Skip to content

Commit

Permalink
refs #6271. Better handling for default functionality.
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenArnold committed Jan 7, 2013
1 parent 0236792 commit 8d0e40f
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 5 deletions.
25 changes: 20 additions & 5 deletions Code/Mantid/MantidQt/SliceViewer/src/CompositePeaksPresenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,10 @@ namespace MantidQt
*/
QColor CompositePeaksPresenter::getForegroundColour(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws) const
{
/// TODO Default?
if(useDefault())
{
throw std::runtime_error("Foreground colours from palette cannot be fetched until nested presenters are added.");
}
SubjectContainer::const_iterator iterator = getPresenterIteratorFromWorkspace(ws);
const int pos = std::distance(m_subjects.begin(), iterator);
return m_palette.foregroundIndexToColour(pos);
Expand All @@ -250,29 +253,41 @@ namespace MantidQt
*/
QColor CompositePeaksPresenter::getBackgroundColour(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws) const
{
/// TODO Default?
if(useDefault())
{
throw std::runtime_error("Background colours from palette cannot be fetched until nested presenters are added.");
}
SubjectContainer::const_iterator iterator = getPresenterIteratorFromWorkspace(ws);
const int pos = std::distance(m_subjects.begin(), iterator);
return m_palette.backgroundIndexToColour(pos);
}

void CompositePeaksPresenter::setBackgroundRadiusShown(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws, const bool shown)
{
/// TODO Default?
if(useDefault())
{
return m_default->showBackgroundRadius(shown);
}
auto iterator = getPresenterIteratorFromWorkspace(ws);
(*iterator)->showBackgroundRadius(shown);
}

void CompositePeaksPresenter::remove(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> peaksWS)
{
/// TODO Default?
if(useDefault())
{
return;
}
auto iterator = getPresenterIteratorFromWorkspace(peaksWS);
m_subjects.erase(iterator);
}

void CompositePeaksPresenter::setShown(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> peaksWS, const bool shown)
{
/// TODO Default?
if(useDefault())
{
return m_default->setShown(shown);
}
auto iterator = getPresenterIteratorFromWorkspace(peaksWS);
(*iterator)->setShown(shown);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,15 @@ class CompositePeaksPresenterTest : public CxxTest::TestSuite
TS_ASSERT(Mock::VerifyAndClearExpectations(B));
}

void test_remove_default()
{
CompositePeaksPresenter composite;
auto peaksWorkspace = boost::make_shared<Mantid::DataObjects::PeaksWorkspace>();

//Try to remove a peaks workspace & associated presenter that doesn't exist from a default constructed composite.
TS_ASSERT_THROWS_NOTHING(composite.remove(peaksWorkspace));
}

void do_test_setShown(bool expectedToShow)
{
// Prepare subject objects.
Expand Down Expand Up @@ -445,8 +454,51 @@ class CompositePeaksPresenterTest : public CxxTest::TestSuite
do_test_setShown(HIDE);
}

void test_setShown_default()
{
const bool expectedFlag = true;

// Create a default.
MockPeaksPresenter* mockDefault = new MockPeaksPresenter;
PeaksPresenter_sptr defaultPresenter(mockDefault);
EXPECT_CALL(*mockDefault, setShown(expectedFlag)).Times(1); // Expect the method on the default to be called.

// Create the composite.
CompositePeaksPresenter composite(defaultPresenter);
// Call the method on the composite.
composite.setShown(boost::make_shared<Mantid::DataObjects::PeaksWorkspace>(), expectedFlag);

TS_ASSERT(Mock::VerifyAndClearExpectations(mockDefault));
}

void test_setBackgroundRadiusShown_default()
{
const bool expectedFlag = true;

// Create a default.
MockPeaksPresenter* mockDefault = new MockPeaksPresenter;
PeaksPresenter_sptr defaultPresenter(mockDefault);
EXPECT_CALL(*mockDefault, showBackgroundRadius(expectedFlag)).Times(1); // Expect the method on the default to be called.

// Create the composite.
CompositePeaksPresenter composite(defaultPresenter);
// Call the method on the composite.
composite.setBackgroundRadiusShown(boost::make_shared<Mantid::DataObjects::PeaksWorkspace>(), expectedFlag);

TS_ASSERT(Mock::VerifyAndClearExpectations(mockDefault));
}

void test_getBackroundColour_default()
{
CompositePeaksPresenter composite;
TSM_ASSERT_THROWS("Cannot fetch background colours until nested presenters have been added.", composite.getBackgroundColour(boost::make_shared<Mantid::DataObjects::PeaksWorkspace>()), std::runtime_error);
}

void test_getForegroundColour_default()
{
CompositePeaksPresenter composite;
TSM_ASSERT_THROWS("Cannot fetch foreground colours until nested presenters have been added.", composite.getForegroundColour(boost::make_shared<Mantid::DataObjects::PeaksWorkspace>()), std::runtime_error);
}

};

Expand Down

0 comments on commit 8d0e40f

Please sign in to comment.