Skip to content

Commit

Permalink
refs #6271. Add hide and show features.
Browse files Browse the repository at this point in the history
Toggle between hiding and showing the peaks workspaces.
  • Loading branch information
OwenArnold committed Jan 11, 2013
1 parent 623f343 commit b588903
Show file tree
Hide file tree
Showing 19 changed files with 141 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ namespace MantidQt
void setForegroundColour(const QColor){/*Do nothing*/}
void setBackgroundColour(const QColor){/*Do nothing*/}
void showBackgroundRadius(const bool show){/*Do nothing*/}
void setShown(const bool show){/*Do nothing*/}
virtual std::string getTransformName() const;

/// Constructor
Expand All @@ -57,6 +58,8 @@ namespace MantidQt
void setBackgroundRadiusShown(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws, const bool shown);
/// Remove the workspace and corresponding presenter.
void remove(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> peaksWS);
/// Hide these peaks in the plot.
void CompositePeaksPresenter::setShown(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> peaksWS, const bool shown);
private:
/// Alias for container of subjects type.
typedef std::vector<PeaksPresenter_sptr> SubjectContainer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ namespace MantidQt
void setForegroundColour(const QColor);
void setBackgroundColour(const QColor);
std::string getTransformName() const;
void setShown(const bool shown);
private:
/// Peak overlay views.
VecPeakOverlayView m_viewPeaks;
/// View factory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace MantidQt
void setBackgroundColour(const QColor){/*Do nothing*/}
std::string getTransformName() const {return "";}
void showBackgroundRadius(const bool){/*Do nothing*/}
void setShown(const bool){/*Do nothing*/}
};

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ namespace SliceViewer
virtual void setBackgroundColour(const QColor) = 0;
virtual std::string getTransformName() const = 0;
virtual void showBackgroundRadius(const bool shown) = 0;
virtual void setShown(const bool shown) = 0;
};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public slots:
void onBackgroundColourChanged(Mantid::API::IPeaksWorkspace_const_sptr, QColor);
void onBackgroundRadiusShown(Mantid::API::IPeaksWorkspace_const_sptr, bool);
void onRemoveWorkspace(Mantid::API::IPeaksWorkspace_const_sptr);
void onHideInPlot(Mantid::API::IPeaksWorkspace_const_sptr peaksWS, bool);
private:
boost::shared_ptr<ProxyCompositePeaksPresenter> m_presenter;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace SliceViewer
void backgroundColourChanged(Mantid::API::IPeaksWorkspace_const_sptr, QColor);
void backgroundRadiusShown(Mantid::API::IPeaksWorkspace_const_sptr, bool);
void removeWorkspace(Mantid::API::IPeaksWorkspace_const_sptr);
void hideInPlot(Mantid::API::IPeaksWorkspace_const_sptr, bool);
private:
/// Populate the widget with model data.
void populate();
Expand All @@ -42,6 +43,7 @@ namespace SliceViewer
void onForegroundColourClicked();
void onShowBackgroundChanged(bool);
void onRemoveWorkspaceClicked();
void onToggleHideInPlot(bool);
};

} //namespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,16 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnHide">
<property name="text">
<string>Hide in Plot</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ namespace MantidQt
void setBackgroundRadiusShown(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws, const bool shown);
/// Remove the workspace and corresponding presenter.
void remove(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> peaksWS);
/// Hide these peaks in the plot.
void hideInPlot(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> peaksWS, const bool hide);

private:
/// Wrapped composite to delegate to.
Expand Down
11 changes: 11 additions & 0 deletions Code/Mantid/MantidQt/SliceViewer/src/CompositePeaksPresenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ namespace MantidQt
*/
QColor CompositePeaksPresenter::getForegroundColour(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws) const
{
/// TODO Default?
SubjectContainer::const_iterator iterator = getPresenterIteratorFromWorkspace(ws);
const int pos = std::distance(m_subjects.begin(), iterator);
return m_palette.foregroundIndexToColour(pos);
Expand All @@ -249,21 +250,31 @@ namespace MantidQt
*/
QColor CompositePeaksPresenter::getBackgroundColour(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws) const
{
/// TODO Default?
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?
auto iterator = getPresenterIteratorFromWorkspace(ws);
(*iterator)->showBackgroundRadius(shown);
}

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

void CompositePeaksPresenter::setShown(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> peaksWS, const bool shown)
{
/// TODO Default?
auto iterator = getPresenterIteratorFromWorkspace(peaksWS);
(*iterator)->setShown(shown);
}
}
}
21 changes: 21 additions & 0 deletions Code/Mantid/MantidQt/SliceViewer/src/ConcretePeaksPresenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,5 +272,26 @@ namespace SliceViewer
}
}

void ConcretePeaksPresenter::setShown(const bool shown)
{
// Change background colours
for(VecPeakOverlayView::iterator it = m_viewPeaks.begin(); it != m_viewPeaks.end(); ++it)
{
PeakOverlayView_sptr view = (*it);
if((*it) != NULL)
{
if(shown)
{
view->showView();
}
else
{
view->hideView();
}
view->updateView();
}
}
}

}
}
1 change: 0 additions & 1 deletion Code/Mantid/MantidQt/SliceViewer/src/PeakOverlaySphere.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ namespace SliceViewer
{
}


void PeakOverlaySphere::setSlicePoint(const double& z)
{
m_physicalPeak.setSlicePoint(z);
Expand Down
6 changes: 6 additions & 0 deletions Code/Mantid/MantidQt/SliceViewer/src/PeaksViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ namespace MantidQt
connect(widget, SIGNAL(backgroundColourChanged(Mantid::API::IPeaksWorkspace_const_sptr, QColor)), this, SLOT(onBackgroundColourChanged(Mantid::API::IPeaksWorkspace_const_sptr, QColor)));
connect(widget, SIGNAL(backgroundRadiusShown(Mantid::API::IPeaksWorkspace_const_sptr, bool)), this, SLOT(onBackgroundRadiusShown(Mantid::API::IPeaksWorkspace_const_sptr, bool)));
connect(widget, SIGNAL(removeWorkspace(Mantid::API::IPeaksWorkspace_const_sptr)), this, SLOT(onRemoveWorkspace(Mantid::API::IPeaksWorkspace_const_sptr)));
connect(widget, SIGNAL(hideInPlot(Mantid::API::IPeaksWorkspace_const_sptr, bool)), this, SLOT(onHideInPlot(Mantid::API::IPeaksWorkspace_const_sptr, bool)));

layout()->addWidget(widget);
++it;
Expand Down Expand Up @@ -103,5 +104,10 @@ namespace MantidQt
m_presenter->remove(peaksWS);
}

void PeaksViewer::onHideInPlot(Mantid::API::IPeaksWorkspace_const_sptr peaksWS, bool hide)
{
m_presenter->hideInPlot(peaksWS, hide);
}

} // namespace
}
6 changes: 6 additions & 0 deletions Code/Mantid/MantidQt/SliceViewer/src/PeaksWorkspaceWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace MantidQt
connect(ui.btnBackgroundColor, SIGNAL(clicked()), this, SLOT(onBackgroundColourClicked()));
connect(ui.btnPeakColor, SIGNAL(clicked()), this, SLOT(onForegroundColourClicked()));
connect(ui.btnRemove, SIGNAL(clicked()), this, SLOT(onRemoveWorkspaceClicked()));
connect(ui.btnHide, SIGNAL(toggled(bool)), this, SLOT(onToggleHideInPlot(bool)));

populate();
}
Expand Down Expand Up @@ -78,5 +79,10 @@ namespace MantidQt
this->hide();
}

void PeaksWorkspaceWidget::onToggleHideInPlot(bool hidden)
{
emit hideInPlot(this->m_ws, hidden);
}

} // namespace
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,10 @@ namespace MantidQt
{
m_compositePresenter->remove(peaksWS);
}

void ProxyCompositePeaksPresenter::hideInPlot(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> peaksWS, const bool hide)
{
m_compositePresenter->setShown(peaksWS, !hide);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,38 @@ class CompositePeaksPresenterTest : public CxxTest::TestSuite
TS_ASSERT(Mock::VerifyAndClearExpectations(B));
}

void do_test_setShown(bool expectedToShow)
{
// Prepare subject objects.
Mantid::API::IPeaksWorkspace_sptr peaksWS = boost::make_shared<Mantid::DataObjects::PeaksWorkspace>();
SetPeaksWorkspaces set;
set.insert(peaksWS);
MockPeaksPresenter* pSubject = new MockPeaksPresenter;
PeaksPresenter_sptr subject(pSubject);
EXPECT_CALL(*pSubject, setShown(expectedToShow)).Times(1);
EXPECT_CALL(*pSubject, presentedWorkspaces()).WillOnce(Return(set));

// Create the composite and add the test presenter.
CompositePeaksPresenter composite;
composite.addPeaksPresenter(subject);

// execute setshown(...)
composite.setShown(peaksWS, expectedToShow);

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

void test_setShown()
{
const bool SHOW = true;
const bool HIDE = false;
// Test that calling method on composite causes subject presenters to show.
do_test_setShown(SHOW);
// Test that calling method on composite causes subject presenters to hide.
do_test_setShown(HIDE);
}




};
Expand Down
30 changes: 30 additions & 0 deletions Code/Mantid/MantidQt/SliceViewer/test/ConcretePeaksPresenterTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,36 @@ class ConcretePeaksPresenterTest : public CxxTest::TestSuite
TS_ASSERT(Mock::VerifyAndClearExpectations(pMockView));
}


void test_setShown()
{
const int expectedNumberOfPeaks = 5;
auto concreteBuilder = createStandardBuild(expectedNumberOfPeaks);

// Create a mock view object/product that will be returned by the mock factory.
auto pMockView = new NiceMock<MockPeakOverlayView>;
auto mockView = boost::shared_ptr<NiceMock<MockPeakOverlayView> >(pMockView);
EXPECT_CALL(*pMockView, showView()).Times(expectedNumberOfPeaks); // Expect that the view will be forced to SHOW.
EXPECT_CALL(*pMockView, hideView()).Times(expectedNumberOfPeaks); // Expect that the view will be forced to HIDE.
EXPECT_CALL(*pMockView, updateView()).Times(2*expectedNumberOfPeaks); // Expect that each widget will be updated.
// Create a widget factory mock
auto pMockViewFactory = new MockPeakOverlayFactory;
PeakOverlayViewFactory_sptr mockViewFactory = PeakOverlayViewFactory_sptr(pMockViewFactory);
EXPECT_CALL(*pMockViewFactory, createView(_)).WillRepeatedly(Return(mockView));
EXPECT_CALL(*pMockViewFactory, getPlotXLabel()).WillRepeatedly(Return("H"));
EXPECT_CALL(*pMockViewFactory, getPlotYLabel()).WillRepeatedly(Return("K"));
EXPECT_CALL(*pMockViewFactory, setPeakRadius(_,_,_)).Times(AtLeast(1));
EXPECT_CALL(*pMockViewFactory, setZRange(_,_)).Times(AtLeast(1));

concreteBuilder.withIntegratedViewFactory(mockViewFactory);

auto presenter = concreteBuilder.create();
presenter->setShown(true);
presenter->setShown(false);

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

};


Expand Down
1 change: 1 addition & 0 deletions Code/Mantid/MantidQt/SliceViewer/test/MockObjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace
MOCK_METHOD1(setBackgroundColour, void(const QColor));
MOCK_CONST_METHOD0(getTransformName, std::string());
MOCK_METHOD1(showBackgroundRadius, void(const bool));
MOCK_METHOD1(setShown, void(const bool));
virtual ~MockPeaksPresenter(){}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ class NullPeaksPresenterTest : public CxxTest::TestSuite
TS_ASSERT_THROWS_NOTHING(presenter.setBackgroundColour(Qt::black));
}

void test_setShown_does_nothing()
{
NullPeaksPresenter presenter;
TS_ASSERT_THROWS_NOTHING(presenter.setShown(true));
TS_ASSERT_THROWS_NOTHING(presenter.setShown(false));
}

};

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ class PhysicalSphericalPeakTest : public CxxTest::TestSuite
const double slicePoint = radius + delta;
physicalPeak.setSlicePoint(slicePoint);

int i;
std::cin >> i;

TSM_ASSERT("Should NOT be viewable if a slice point > r is set.", !physicalPeak.isViewablePeak());
}

Expand Down

0 comments on commit b588903

Please sign in to comment.