Skip to content
Snippets Groups Projects
Commit cdcbbc91 authored by Harry Jeffery's avatar Harry Jeffery
Browse files

Refs #10222 Refactor IReflPresenter's notify method

We no longer pass flags separately. By passing them one at a time
directly with notify we bypass a potential race condition and vastly
simplify unit testing logic.
parent 7cb12998
No related branches found
No related tags found
No related merge requests found
......@@ -34,8 +34,8 @@ namespace MantidQt
{
public:
virtual ~IReflPresenter() {};
//Tell the presenter somehting happened
virtual void notify() = 0;
//Tell the presenter something happened
virtual void notify(int flag) = 0;
private:
};
......
......@@ -52,19 +52,13 @@ namespace MantidQt
//Dialog/Prompt methods
virtual std::string askUserString(const std::string& prompt, const std::string& title, const std::string& defaultValue);
virtual bool askUserYesNo(std::string prompt, std::string title);
virtual void giveUserInfo(std::string prompt, std::string title);
virtual void giveUserWarning(std::string prompt, std::string title);
virtual void giveUserCritical(std::string prompt, std::string title);
virtual bool askUserYesNo(std::string prompt, std::string title);
//flag methods
//Accessor methods
virtual std::vector<size_t> getSelectedRowIndexes() const;
virtual Flag getFlag();
virtual bool flagSet() const;
protected:
//notify flags
std::vector<Flag> m_flags;
private:
//initialise the interface
......
......@@ -44,25 +44,20 @@ namespace MantidQt
//Dialog/Prompt methods
virtual std::string askUserString(const std::string& prompt, const std::string& title, const std::string& defaultValue) = 0;
virtual bool askUserYesNo(std::string prompt, std::string title) = 0;
virtual void giveUserInfo(std::string prompt, std::string title) = 0;
virtual void giveUserWarning(std::string prompt, std::string title) = 0;
virtual void giveUserCritical(std::string prompt, std::string title) = 0;
virtual bool askUserYesNo(std::string prompt, std::string title) = 0;
enum Flag
{
NoFlags = 0,
SaveFlag,
SaveAsFlag,
AddRowFlag,
DeleteRowFlag,
ProcessFlag
};
//flag methods
//Accessor methods
virtual std::vector<size_t> getSelectedRowIndexes() const = 0;
virtual Flag getFlag() = 0;
virtual bool flagSet() const = 0;
static const int NoFlags = 0;
static const int SaveFlag = 1;
static const int SaveAsFlag = 2;
static const int AddRowFlag = 3;
static const int DeleteRowFlag = 4;
static const int ProcessFlag = 5;
};
}
}
......
......@@ -40,7 +40,7 @@ namespace MantidQt
ReflMainViewPresenter(Mantid::API::ITableWorkspace_sptr model, ReflMainView* view);
ReflMainViewPresenter(ReflMainView* view);
virtual ~ReflMainViewPresenter() = 0;
virtual void notify();
virtual void notify(int flag);
protected:
//The model and backup copy of the original model
Mantid::API::ITableWorkspace_sptr m_model;
......
......@@ -35,10 +35,10 @@ namespace MantidQt
{
public:
virtual ~ReflNullMainViewPresenter();
virtual void notify();
virtual void notify(int flag);
private:
};
}
}
#endif
\ No newline at end of file
#endif
......@@ -69,7 +69,7 @@ namespace MantidQt
{
boost::scoped_ptr<IReflPresenter> newPtr(new ReflLoadedMainViewPresenter(name.toStdString(), this));
m_presenter.swap(newPtr);
m_presenter->notify();
m_presenter->notify(NoFlags);
}
/**
......@@ -87,8 +87,7 @@ namespace MantidQt
*/
void QtReflMainView::saveButton()
{
m_flags.push_back(SaveFlag);
m_presenter->notify();
m_presenter->notify(SaveFlag);
}
/**
......@@ -96,8 +95,7 @@ namespace MantidQt
*/
void QtReflMainView::saveAsButton()
{
m_flags.push_back(SaveAsFlag);
m_presenter->notify();
m_presenter->notify(SaveAsFlag);
}
/**
......@@ -105,8 +103,7 @@ namespace MantidQt
*/
void QtReflMainView::addRowButton()
{
m_flags.push_back(AddRowFlag);
m_presenter->notify();
m_presenter->notify(AddRowFlag);
}
/**
......@@ -114,8 +111,7 @@ namespace MantidQt
*/
void QtReflMainView::deleteRowButton()
{
m_flags.push_back(DeleteRowFlag);
m_presenter->notify();
m_presenter->notify(DeleteRowFlag);
}
/**
......@@ -123,29 +119,7 @@ namespace MantidQt
*/
void QtReflMainView::processButton()
{
m_flags.push_back(ProcessFlag);
m_presenter->notify();
}
/**
Pops the flag from the front of the queue, returning it to the presenter
*/
ReflMainView::Flag QtReflMainView::getFlag()
{
if(m_flags.size() < 1)
return NoFlags;
auto ret = m_flags.front();
m_flags.erase(m_flags.begin());
return ret;
}
/**
Returns true if there is a flag waiting to be processed. Otherwise returns false.
*/
bool QtReflMainView::flagSet() const
{
return m_flags.size() > 0;
m_presenter->notify(ProcessFlag);
}
/**
......
......@@ -284,24 +284,19 @@ namespace MantidQt
/**
Used by the view to tell the presenter something has changed
*/
void ReflMainViewPresenter::notify()
void ReflMainViewPresenter::notify(int flag)
{
//Fetch all the flags in turn, processing them.
while(m_view->flagSet())
switch(flag)
{
ReflMainView::Flag flag = m_view->getFlag();
switch(flag)
{
case ReflMainView::SaveAsFlag: saveAs(); break;
case ReflMainView::SaveFlag: save(); break;
case ReflMainView::AddRowFlag: addRow(); break;
case ReflMainView::DeleteRowFlag: deleteRow(); break;
case ReflMainView::ProcessFlag: process(); break;
case ReflMainView::SaveAsFlag: saveAs(); break;
case ReflMainView::SaveFlag: save(); break;
case ReflMainView::AddRowFlag: addRow(); break;
case ReflMainView::DeleteRowFlag: deleteRow(); break;
case ReflMainView::ProcessFlag: process(); break;
case ReflMainView::NoFlags: return;
}
//Not having a 'default' case is deliberate. gcc issues a warning if there's a flag we aren't handling.
case ReflMainView::NoFlags: return;
}
//Not having a 'default' case is deliberate. gcc issues a warning if there's a flag we aren't handling.
}
/**
......
......@@ -6,8 +6,9 @@ namespace MantidQt
{
namespace CustomInterfaces
{
void ReflNullMainViewPresenter::notify()
void ReflNullMainViewPresenter::notify(int flag)
{
(void)flag;
throw std::runtime_error("Cannot notify a null presenter");
}
......@@ -15,4 +16,4 @@ namespace MantidQt
{
}
}
}
\ No newline at end of file
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment