Skip to content

Commit

Permalink
refs #6271. Enable palette changing on all presenters.
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenArnold committed Jan 11, 2013
1 parent 8e875d2 commit b257093
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,19 @@ namespace MantidQt
void clear();
/// Get references to all presented workspaces.
SetPeaksWorkspaces presentedWorkspaces() const;
/// Change the foreground representation for the peaks of this workspace
void setForegroundColour(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws, Colour);
/// Change the background representation for the peaks of this workspace
void setBackgroundColour(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws, Colour);
private:
/// Default behaviour
PeaksPresenter_sptr m_default;
/// Subject presenters.
std::set<PeaksPresenter_sptr> m_subjects;
/// Use default
bool useDefault() const { return m_subjects.size() == 0; }
void setForegroundColour(const Colour){/*Do nothing*/}
void setBackgroundColour(const Colour){/*Do nothing*/}
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ namespace MantidQt
virtual bool changeShownDim(){return false;}
virtual bool isLabelOfFreeAxis(const std::string&) const {return false;}
SetPeaksWorkspaces presentedWorkspaces() const{SetPeaksWorkspaces empty; return empty;}
void setForegroundColour(const Colour){/*Do nothing*/}
void setBackgroundColour(const Colour){/*Do nothing*/}
};

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ namespace SliceViewer
virtual bool changeShownDim() = 0;
virtual bool isLabelOfFreeAxis(const std::string& label) const = 0;
virtual SetPeaksWorkspaces presentedWorkspaces() const = 0;
virtual void setForegroundColour(const Colour) = 0;
virtual void setBackgroundColour(const Colour) = 0;
};


Expand Down
38 changes: 38 additions & 0 deletions Code/Mantid/MantidQt/SliceViewer/src/CompositePeaksPresenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,43 @@ namespace MantidQt
}
return allWorkspaces;
}

/**
Set the foreground colour of the peaks.
@ workspace containing the peaks to re-colour
@ colour to use for re-colouring
*/
void CompositePeaksPresenter::setForegroundColour(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws, Colour colour)
{
for(auto it = m_subjects.begin(); it != m_subjects.end(); ++it)
{
auto workspacesOfSubject = (*it)->presentedWorkspaces();
auto iteratorFound = workspacesOfSubject.find(ws);
if(iteratorFound != workspacesOfSubject.end())
{
(*it)->setForegroundColour(colour);
break;
}
}
}

/**
Set the background colour of the peaks.
@ workspace containing the peaks to re-colour
@ colour to use for re-colouring
*/
void CompositePeaksPresenter::setBackgroundColour(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws, Colour colour)
{
for(auto it = m_subjects.begin(); it != m_subjects.end(); ++it)
{
auto workspacesOfSubject = (*it)->presentedWorkspaces();
auto iteratorFound = workspacesOfSubject.find(ws);
if(iteratorFound != workspacesOfSubject.end())
{
(*it)->setBackgroundColour(colour);
break;
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ namespace SliceViewer
}

/**
Request that each owned view makes iteself visible.
Request that each owned view makes its self visible.
*/
void ConcretePeaksPresenter::showAll()
{
Expand All @@ -198,7 +198,7 @@ namespace SliceViewer
}

/**
Request that each owned view makes iteself NOT visible.
Request that each owned view makes its self NOT visible.
*/
void ConcretePeaksPresenter::hideAll()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ class CompositePeaksPresenterTest : public CxxTest::TestSuite
TS_ASSERT_THROWS(presenter.addPeaksPresenter( boost::make_shared<MockPeaksPresenter>()), std::invalid_argument);
}



};

#endif
2 changes: 2 additions & 0 deletions Code/Mantid/MantidQt/SliceViewer/test/MockObjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ namespace
MOCK_METHOD0(changeShownDim, bool());
MOCK_CONST_METHOD1(isLabelOfFreeAxis, bool(const std::string&));
MOCK_CONST_METHOD0(presentedWorkspaces, SetPeaksWorkspaces());
MOCK_METHOD1(setForegroundColour, void(const Colour));
MOCK_METHOD1(setBackgroundColour, void(const Colour));
~MockPeaksPresenter(){}
};

Expand Down
12 changes: 12 additions & 0 deletions Code/Mantid/MantidQt/SliceViewer/test/NullPeaksPresenterTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ class NullPeaksPresenterTest : public CxxTest::TestSuite
TS_ASSERT_EQUALS(0, workspaces.size());
}

void test_setForegroundColour_does_nothing()
{
NullPeaksPresenter presenter;
TS_ASSERT_THROWS_NOTHING(presenter.setForegroundColour(Colour::Black));
}

void test_setBackgroundColour_does_nothing()
{
NullPeaksPresenter presenter;
TS_ASSERT_THROWS_NOTHING(presenter.setBackgroundColour(Colour::Black));
}

};

#endif

0 comments on commit b257093

Please sign in to comment.