Skip to content

Commit

Permalink
refs #6271. Must get access to PeaksWorkspaces.
Browse files Browse the repository at this point in the history
For future work we need to get access to the peaks workspaces (const).
  • Loading branch information
OwenArnold committed Jan 7, 2013
1 parent d112d85 commit 61b26bf
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "MantidQtSliceViewer/PeaksPresenter.h"
#include "MantidQtSliceViewer/NullPeaksPresenter.h"
#include <set>
#include <boost/shared_ptr.hpp>

namespace MantidQt
{
Expand Down Expand Up @@ -35,7 +36,8 @@ namespace MantidQt
size_t size() const;
/// Clear the owned presenters.
void clear();

/// Get references to all presented workspaces.
SetPeaksWorkspaces presentedWorkspaces() const;
private:
/// Default behaviour
PeaksPresenter_sptr m_default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@ namespace MantidQt
virtual void updateWithSlicePoint(const double& slicePoint);
virtual bool changeShownDim();
virtual bool isLabelOfFreeAxis(const std::string& label) const;
SetPeaksWorkspaces presentedWorkspaces() const;
private:
/// Peak overlay views.
VecPeakOverlayView m_viewPeaks;
/// View factory
boost::shared_ptr<PeakOverlayViewFactory> m_viewFactory;
/// Peaks workspace.
boost::shared_ptr<const Mantid::API::IPeaksWorkspace> m_peaksWS;
/// Transform factory
boost::shared_ptr<PeakTransformFactory> m_transformFactory;
/// Peak transformer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace MantidQt
virtual void updateWithSlicePoint(const double&){}
virtual bool changeShownDim(){return false;}
virtual bool isLabelOfFreeAxis(const std::string&) const {return false;}
SetPeaksWorkspaces presentedWorkspaces() const{SetPeaksWorkspaces empty; return empty;}
};

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@
#include "MantidKernel/System.h"
#include <boost/shared_ptr.hpp>
#include "MantidKernel/System.h"
#include <set>

namespace Mantid
{
namespace API
{
// Forward dec.
class IPeaksWorkspace;
}
}

namespace MantidQt
{
Expand All @@ -13,6 +23,9 @@ namespace SliceViewer
class PeakOverlayViewFactory;
class PeakOverlayView;

// Alias
typedef std::set<boost::shared_ptr<const Mantid::API::IPeaksWorkspace> > SetPeaksWorkspaces;

/*---------------------------------------------------------
Abstract PeaksPresenter.
Expand All @@ -27,6 +40,7 @@ namespace SliceViewer
virtual void updateWithSlicePoint(const double&) = 0;
virtual bool changeShownDim() = 0;
virtual bool isLabelOfFreeAxis(const std::string& label) const = 0;
virtual SetPeaksWorkspaces presentedWorkspaces() const = 0;
};


Expand Down
16 changes: 15 additions & 1 deletion Code/Mantid/MantidQt/SliceViewer/src/CompositePeaksPresenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,19 @@ namespace MantidQt
{
return m_subjects.size();
}
}

/**
Return a collection of all referenced workspaces on demand.
*/
SetPeaksWorkspaces CompositePeaksPresenter::presentedWorkspaces() const
{
SetPeaksWorkspaces allWorkspaces;
for(auto it = m_subjects.begin(); it != m_subjects.end(); ++it)
{
auto workspacesToAppend = (*it)->presentedWorkspaces();
allWorkspaces.insert(workspacesToAppend.begin(), workspacesToAppend.end());
}
return allWorkspaces;
}
}
}
13 changes: 12 additions & 1 deletion Code/Mantid/MantidQt/SliceViewer/src/ConcretePeaksPresenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace SliceViewer
@param peaksTransform : Peak Transformation Factory. This is about interpreting the MODEL.
*/
ConcretePeaksPresenter::ConcretePeaksPresenter(PeakOverlayViewFactory_sptr nonIntegratedViewFactory, PeakOverlayViewFactory_sptr integratedViewFactory, IPeaksWorkspace_sptr peaksWS, boost::shared_ptr<MDGeometry> mdWS, PeakTransformFactory_sptr transformFactory) : m_viewPeaks(peaksWS->getNumberPeaks())
, m_viewFactory(integratedViewFactory), m_transformFactory(transformFactory), m_transform(transformFactory->createDefaultTransform()), m_slicePoint(0)
, m_viewFactory(integratedViewFactory), m_peaksWS(peaksWS), m_transformFactory(transformFactory), m_transform(transformFactory->createDefaultTransform()), m_slicePoint(0)
{
if(integratedViewFactory == NULL)
{
Expand Down Expand Up @@ -212,5 +212,16 @@ namespace SliceViewer
}
}

/**
@return a reference to the held peaks workspace.
*/
SetPeaksWorkspaces ConcretePeaksPresenter::presentedWorkspaces() const
{
// There is only one workspace to return.
SetPeaksWorkspaces workspaces;
workspaces.insert(m_peaksWS);
return workspaces;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,30 @@ class CompositePeaksPresenterTest : public CxxTest::TestSuite
TS_ASSERT(Mock::VerifyAndClearExpectations(mockPresenter));
}

void test_presentedWorkspaces()
{
SetPeaksWorkspaces setA;
MockPeaksPresenter* pA = new MockPeaksPresenter;
PeaksPresenter_sptr A(pA);
EXPECT_CALL(*pA, presentedWorkspaces()).WillOnce(Return(setA));

SetPeaksWorkspaces setB;
MockPeaksPresenter* pB = new MockPeaksPresenter;
PeaksPresenter_sptr B(pB);
EXPECT_CALL(*pB, presentedWorkspaces()).WillOnce(Return(setB));

// Create the composite.
CompositePeaksPresenter composite;
// add the subject presenter.
composite.addPeaksPresenter(A);
composite.addPeaksPresenter(B);
// Call the method on the composite.
composite.presentedWorkspaces();

TS_ASSERT(Mock::VerifyAndClearExpectations(pA));
TS_ASSERT(Mock::VerifyAndClearExpectations(pB));
}

void test_changeShownDimension()
{
const bool PASS = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ class ConcretePeaksPresenterTest : public CxxTest::TestSuite
TSM_ASSERT("MockView not used as expected.", Mock::VerifyAndClearExpectations(pMockView));
TSM_ASSERT("MockTransformFactory not used as expected", Mock::VerifyAndClearExpectations(pMockTransformFactory));
TSM_ASSERT("MockTransform not used as expected", Mock::VerifyAndClearExpectations(pMockTransform));

auto ownedPeaksWorkspace = presenter.presentedWorkspaces();
TS_ASSERT_EQUALS(1, ownedPeaksWorkspace.size());
}

void test_constructor_swaps_view_factory_if_peaks_workspace_not_integrated()
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 @@ -29,6 +29,7 @@ namespace
MOCK_METHOD1(updateWithSlicePoint, void(const double&));
MOCK_METHOD0(changeShownDim, bool());
MOCK_CONST_METHOD1(isLabelOfFreeAxis, bool(const std::string&));
MOCK_CONST_METHOD0(presentedWorkspaces, SetPeaksWorkspaces());
~MockPeaksPresenter(){}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ class NullPeaksPresenterTest : public CxxTest::TestSuite
TS_ASSERT(!presenter.isLabelOfFreeAxis(""));
}

void test_presentedWorkspaces_is_empty()
{
NullPeaksPresenter presenter;
SetPeaksWorkspaces workspaces = presenter.presentedWorkspaces();
TS_ASSERT_EQUALS(0, workspaces.size());
}

};

#endif

0 comments on commit 61b26bf

Please sign in to comment.