Skip to content

Commit

Permalink
Refs #10237 Store options as QVariants
Browse files Browse the repository at this point in the history
This way we don't need to handle type conversion ourselves. We can let
QVariant take care of that for us.
  • Loading branch information
Harry Jeffery committed Oct 29, 2014
1 parent 3af0c90 commit f75a370
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
Expand Up @@ -5,6 +5,9 @@
#include <string>

#include "MantidKernel/System.h"

class QVariant;

namespace MantidQt
{
namespace CustomInterfaces
Expand Down Expand Up @@ -39,8 +42,8 @@ namespace MantidQt
virtual ~IReflPresenter() {};
//Tell the presenter something happened
virtual void notify(int flag) = 0;
virtual const std::map<std::string,std::string>& options() const = 0;
virtual void setOptions(const std::map<std::string,std::string>& options) = 0;
virtual const std::map<std::string,QVariant>& options() const = 0;
virtual void setOptions(const std::map<std::string,QVariant>& options) = 0;
private:

};
Expand Down
Expand Up @@ -45,8 +45,8 @@ namespace MantidQt
ReflMainViewPresenter(ReflMainView* view);
virtual ~ReflMainViewPresenter();
virtual void notify(int flag);
virtual const std::map<std::string,std::string>& options() const;
virtual void setOptions(const std::map<std::string,std::string>& options);
virtual const std::map<std::string,QVariant>& options() const;
virtual void setOptions(const std::map<std::string,QVariant>& options);
//Public for the purposes of unit testing
static std::map<std::string,std::string> parseKeyValueString(const std::string& str);
protected:
Expand All @@ -59,7 +59,7 @@ namespace MantidQt
//stores whether or not the table has changed since it was last saved
bool m_tableDirty;
//stores the user options for the presenter
std::map<std::string,std::string> m_options;
std::map<std::string,QVariant> m_options;

//process selected rows
virtual void process();
Expand Down
Expand Up @@ -30,10 +30,10 @@ namespace MantidQt
/** This slot saves the currently configured options to the presenter */
void QtReflOptionsDialog::saveOptions()
{
std::map<std::string,std::string> options = m_presenter->options();
std::map<std::string,QVariant> options = m_presenter->options();

//Set the options map to match the UI
options["WarnProcessAll"] = ui.checkWarnProcessAll->isChecked() ? "true" : "false";
options["WarnProcessAll"] = ui.checkWarnProcessAll->isChecked();

//Update the presenter's options
m_presenter->setOptions(options);
Expand All @@ -42,10 +42,10 @@ namespace MantidQt
/** This slot sets the ui to match the presenter's options */
void QtReflOptionsDialog::loadOptions()
{
std::map<std::string,std::string> options = m_presenter->options();
std::map<std::string,QVariant> options = m_presenter->options();

//Set the values from the options
ui.checkWarnProcessAll->setChecked(options["WarnProcessAll"] == "true");
ui.checkWarnProcessAll->setChecked(options["WarnProcessAll"].toBool());
}

} //CustomInterfaces
Expand Down
Expand Up @@ -250,7 +250,7 @@ namespace MantidQt
std::set<size_t> rows = m_view->getSelectedRows();
if(rows.empty())
{
if(m_options["WarnProcessAll"] == "true")
if(m_options["WarnProcessAll"].toBool())
{
//Does the user want to abort?
if(!m_view->askUserYesNo("This will process all rows in the table. Continue?","Process all rows?"))
Expand Down Expand Up @@ -1055,15 +1055,15 @@ namespace MantidQt
/** Gets the options used by the presenter
@returns The options used by the presenter
*/
const std::map<std::string,std::string>& ReflMainViewPresenter::options() const
const std::map<std::string,QVariant>& ReflMainViewPresenter::options() const
{
return m_options;
}

/** Sets the options used by the presenter
@param options : The new options for the presenter to use
*/
void ReflMainViewPresenter::setOptions(const std::map<std::string,std::string>& options)
void ReflMainViewPresenter::setOptions(const std::map<std::string,QVariant>& options)
{
//Optionally check the validity of the new options
m_options = options;
Expand All @@ -1075,7 +1075,7 @@ namespace MantidQt
m_options.clear();

//Set defaults
m_options["WarnProcessAll"] = "true";
m_options["WarnProcessAll"] = true;

//Load from disk
//TODO
Expand Down

0 comments on commit f75a370

Please sign in to comment.