Skip to content
Snippets Groups Projects
Commit 49acde57 authored by Owen Arnold's avatar Owen Arnold
Browse files

refs #5167. Refactor to simplify.

Remove PeakOverlayFactoryBase class. Most of the logic had already been stripped out of this type. Also added a test for the NullPeaksPresenter since object of this type should be neutral in existance, yielding no noticable affect on the system whatsoever.
parent a7866b45
No related branches found
No related tags found
No related merge requests found
...@@ -7,7 +7,6 @@ set ( SRC_FILES ...@@ -7,7 +7,6 @@ set ( SRC_FILES
src/LineViewer.cpp src/LineViewer.cpp
src/PeakOverlay.cpp src/PeakOverlay.cpp
src/PeakOverlayFactory.cpp src/PeakOverlayFactory.cpp
src/PeakOverlayFactoryBase.cpp
src/PeakTransform.cpp src/PeakTransform.cpp
src/QScienceSpinBox.cpp src/QScienceSpinBox.cpp
src/QwtRasterDataMD.cpp src/QwtRasterDataMD.cpp
...@@ -33,7 +32,6 @@ set ( INC_FILES ...@@ -33,7 +32,6 @@ set ( INC_FILES
inc/MantidQtSliceViewer/PeakOverlayView.h inc/MantidQtSliceViewer/PeakOverlayView.h
inc/MantidQtSliceViewer/PeakOverlayViewFactory.h inc/MantidQtSliceViewer/PeakOverlayViewFactory.h
inc/MantidQtSliceViewer/PeakOverlayFactory.h inc/MantidQtSliceViewer/PeakOverlayFactory.h
inc/MantidQtSliceViewer/PeakOverlayFactoryBase.h
inc/MantidQtSliceViewer/PeaksPresenter.h inc/MantidQtSliceViewer/PeaksPresenter.h
inc/MantidQtSliceViewer/PeakTransform.h inc/MantidQtSliceViewer/PeakTransform.h
inc/MantidQtSliceViewer/QScienceSpinBox.h inc/MantidQtSliceViewer/QScienceSpinBox.h
...@@ -71,8 +69,8 @@ set ( UI_FILES ...@@ -71,8 +69,8 @@ set ( UI_FILES
set ( TEST_FILES set ( TEST_FILES
test/ConcretePeaksPresenterTest.h test/ConcretePeaksPresenterTest.h
test/PeakOverlayFactoryBaseTest.h
test/PeakTransformTest.h test/PeakTransformTest.h
test/NullPeaksPresenterTest.h
) )
# Python unit tests # Python unit tests
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
#define MANTID_SLICEVIEWER_PEAKOVERLAY_FACTORY_H_ #define MANTID_SLICEVIEWER_PEAKOVERLAY_FACTORY_H_
#include "DllOption.h" #include "DllOption.h"
#include "MantidQtSliceViewer/PeakOverlayFactoryBase.h" #include "MantidQtSliceViewer/PeakOverlayViewFactory.h"
#include <QtGui/qwidget.h> #include <QtGui/qwidget.h>
#include <qwt_plot.h> #include <qwt_plot.h>
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
...@@ -46,18 +46,21 @@ namespace MantidQt ...@@ -46,18 +46,21 @@ namespace MantidQt
File change history is stored at: <https://github.com/mantidproject/mantid> File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org> Code Documentation is available at: <http://doxygen.mantidproject.org>
*/ */
class DLLExport PeakOverlayFactory : public PeakOverlayFactoryBase class DLLExport PeakOverlayFactory : public PeakOverlayViewFactory
{ {
private: private:
QwtPlot * m_plot; QwtPlot * m_plot;
QWidget * m_parent; QWidget * m_parent;
double m_peakRadius;
boost::shared_ptr<PeakOverlayView> createViewAtPoint(const Mantid::Kernel::V3D& position, const double& radius) const;
public: public:
PeakOverlayFactory(QwtPlot * plot, QWidget * parent); PeakOverlayFactory(QwtPlot * plot, QWidget * parent);
virtual ~PeakOverlayFactory(); virtual ~PeakOverlayFactory();
virtual boost::shared_ptr<PeakOverlayView> createViewAtPoint(const Mantid::Kernel::V3D& position, const double& radius) const; boost::shared_ptr<PeakOverlayView> createView(const Mantid::Kernel::V3D& position) const;
virtual std::string getPlotXLabel() const; virtual std::string getPlotXLabel() const;
virtual std::string getPlotYLabel() const; virtual std::string getPlotYLabel() const;
virtual void setRadius(const double& peakRadius);
}; };
} }
} }
......
#ifndef MANTID_SLICEVIEWER_PEAKOVERLAY_FACTORY_BASE_H_
#define MANTID_SLICEVIEWER_PEAKOVERLAY_FACTORY_BASE_H_
#include "MantidKernel/System.h"
#include "MantidQtSliceViewer/PeakOverlayViewFactory.h"
namespace Mantid
{
namespace Kernel
{
class V3D;
}
}
namespace MantidQt
{
namespace SliceViewer
{
class DLLExport PeakOverlayFactoryBase : public PeakOverlayViewFactory
{
public:
PeakOverlayFactoryBase();
~PeakOverlayFactoryBase();
void setRadius(const double& radius);
virtual boost::shared_ptr<PeakOverlayView> createView(const Mantid::Kernel::V3D&) const;
protected:
virtual boost::shared_ptr<PeakOverlayView> createViewAtPoint(const Mantid::Kernel::V3D& position, const double& radius) const = 0;
private:
/// The actual peak radius to use for all peaks created via the factory.
double m_peakRadius;
};
}
}
#endif /* MANTID_SLICEVIEWER_PEAKOVERLAY_FACTORY_BASE_H_ */
\ No newline at end of file
...@@ -14,7 +14,7 @@ namespace MantidQt ...@@ -14,7 +14,7 @@ namespace MantidQt
namespace SliceViewer namespace SliceViewer
{ {
PeakOverlayFactory::PeakOverlayFactory(QwtPlot * plot, QWidget * parent) : PeakOverlayFactoryBase(), m_plot(plot), m_parent(parent) PeakOverlayFactory::PeakOverlayFactory(QwtPlot * plot, QWidget * parent) : PeakOverlayViewFactory(), m_plot(plot), m_parent(parent)
{ {
if(!plot) if(!plot)
throw std::invalid_argument("PeakOverlayFactory plot is null"); throw std::invalid_argument("PeakOverlayFactory plot is null");
...@@ -22,6 +22,11 @@ namespace MantidQt ...@@ -22,6 +22,11 @@ namespace MantidQt
throw std::invalid_argument("PeakOverlayFactory parent widget is null"); throw std::invalid_argument("PeakOverlayFactory parent widget is null");
} }
boost::shared_ptr<PeakOverlayView> PeakOverlayFactory::createView(const Mantid::Kernel::V3D& position) const
{
return this->createViewAtPoint(position, m_peakRadius);
}
boost::shared_ptr<PeakOverlayView> PeakOverlayFactory::createViewAtPoint(const Mantid::Kernel::V3D& position, const double& radius) const boost::shared_ptr<PeakOverlayView> PeakOverlayFactory::createViewAtPoint(const Mantid::Kernel::V3D& position, const double& radius) const
{ {
return boost::make_shared<PeakOverlay>(m_plot, m_parent, position, radius); return boost::make_shared<PeakOverlay>(m_plot, m_parent, position, radius);
...@@ -42,5 +47,14 @@ namespace MantidQt ...@@ -42,5 +47,14 @@ namespace MantidQt
PeakOverlayFactory::~PeakOverlayFactory() PeakOverlayFactory::~PeakOverlayFactory()
{ {
} }
/*
Setter for the actual peak radius. The radius used for drawing will depend on the plane instesection.
@param peakRadius : Global value for the peak radius to apply to all peaks manufactured through this factory.
*/
void PeakOverlayFactory::setRadius(const double& peakRadius)
{
m_peakRadius = peakRadius;
}
} }
} }
\ No newline at end of file
#include "MantidQtSliceViewer/PeakOverlayFactoryBase.h"
#include "MantidAPI/IPeak.h"
#include <boost/regex.hpp>
namespace MantidQt
{
namespace SliceViewer
{
PeakOverlayFactoryBase::PeakOverlayFactoryBase() : m_peakRadius(1)
{
}
PeakOverlayFactoryBase::~PeakOverlayFactoryBase()
{
}
/*
Setter for the actual peak radius. The radius used for drawing will depend on the plane instesection.
@param peakRadius : Global value for the peak radius to apply to all peaks manufactured through this factory.
*/
void PeakOverlayFactoryBase::setRadius(const double& peakRadius)
{
m_peakRadius = peakRadius;
}
boost::shared_ptr<PeakOverlayView> PeakOverlayFactoryBase::createView(const Mantid::Kernel::V3D& position) const
{
return this->createViewAtPoint(position, m_peakRadius);
}
}
}
#ifndef SLICE_VIEWER_NULLPEAKSPRESENTER_TEST_H_
#define SLICE_VIEWER_NULLPEAKSPRESENTER_TEST_H_
#include <cxxtest/TestSuite.h>
#include "MantidQtSliceViewer/NullPeaksPresenter.h"
using namespace MantidQt::SliceViewer;
using namespace Mantid;
class NullPeaksPresenterTest : public CxxTest::TestSuite
{
public:
void test_construction()
{
TS_ASSERT_THROWS_NOTHING(NullPeaksPresenter p());
}
void test_is_peaks_presenter()
{
NullPeaksPresenter presenter;
PeaksPresenter& base = presenter; // compile-time test for the is-a relationship
}
/* Test individual methods on the interface */
void test_update_does_nothing()
{
NullPeaksPresenter presenter;
TS_ASSERT_THROWS_NOTHING(presenter.update());
}
void test_updateWithSlicePoint_does_nothing()
{
NullPeaksPresenter presenter;
TS_ASSERT_THROWS_NOTHING(presenter.updateWithSlicePoint(0));
}
void test_changeShownDim_does_nothing()
{
NullPeaksPresenter presenter;
TS_ASSERT_THROWS_NOTHING(presenter.changeShownDim());
}
void test_isLabelOfFreeAxis_always_returns_false()
{
NullPeaksPresenter presenter;
TS_ASSERT(!presenter.isLabelOfFreeAxis(""));
}
};
#endif
\ No newline at end of file
#ifndef SLICE_VIEWER_PEAKOVERLAYFACTORY_TEST_H_
#define SLICE_VIEWER_PEAKOVERLAYFACTORY_TEST_H_
#include <cxxtest/TestSuite.h>
#include <gmock/gmock.h>
#include "MantidAPI/IPeak.h"
#include "MantidQtSliceViewer/FirstExperimentInfoQuery.h"
#include "MantidQtSliceViewer/PeakOverlayFactoryBase.h"
using namespace MantidQt::SliceViewer;
using namespace Mantid;
using namespace testing;
class PeakOverlayFactoryBaseTest : public CxxTest::TestSuite
{
private:
/**
Testing Type derived from the base type. All tests will use this.
*/
class MockPeakOverlayFactory : public PeakOverlayFactoryBase
{
public:
MockPeakOverlayFactory() : PeakOverlayFactoryBase(){}
MOCK_CONST_METHOD2(createViewAtPoint, boost::shared_ptr<PeakOverlayView>(const Mantid::Kernel::V3D&, const double&));
MOCK_CONST_METHOD0(getPlotXLabel, std::string());
MOCK_CONST_METHOD0(getPlotYLabel, std::string());
~MockPeakOverlayFactory(){}
};
/*------------------------------------------------------------
Mock Query
------------------------------------------------------------*/
class MockFirstExperimentInfoQuery : public FirstExperimentInfoQuery
{
public:
MOCK_CONST_METHOD0(hasOrientedLattice, bool());
MOCK_CONST_METHOD0(hasRotatedGoniometer, bool());
~MockFirstExperimentInfoQuery(){}
};
/*------------------------------------------------------------
Mock Peak Overlay View
------------------------------------------------------------*/
class MockPeakOverlayView : public PeakOverlayView
{
public:
MOCK_METHOD1(setPlaneDistance, void(const double&));
MOCK_METHOD0(updateView, void());
MOCK_METHOD1(setSlicePoint, void(const double&));
MOCK_METHOD0(hideView, void());
MOCK_METHOD1(movePosition, void(const PeakTransform&));
~MockPeakOverlayView(){}
};
/*------------------------------------------------------------
Mock Peak
------------------------------------------------------------*/
class MockIPeak : public Mantid::API::IPeak
{
public:
MOCK_METHOD1(setInstrument,
void(Geometry::Instrument_const_sptr inst));
MOCK_CONST_METHOD0(getDetectorID,
int());
MOCK_METHOD1(setDetectorID,
void(int m_DetectorID));
MOCK_CONST_METHOD0(getDetector,
Geometry::IDetector_const_sptr());
MOCK_CONST_METHOD0(getInstrument,
Geometry::Instrument_const_sptr());
MOCK_CONST_METHOD0(getRunNumber,
int());
MOCK_METHOD1(setRunNumber,
void(int m_RunNumber));
MOCK_CONST_METHOD0(getMonitorCount,
double());
MOCK_METHOD1(setMonitorCount,
void(double m_MonitorCount));
MOCK_CONST_METHOD0(getH,
double());
MOCK_CONST_METHOD0(getK,
double());
MOCK_CONST_METHOD0(getL,
double());
MOCK_CONST_METHOD0(getHKL,
Mantid::Kernel::V3D());
MOCK_METHOD1(setH,
void(double m_H));
MOCK_METHOD1(setK,
void(double m_K));
MOCK_METHOD1(setL,
void(double m_L));
MOCK_METHOD3(setHKL,
void(double H, double K, double L));
MOCK_METHOD1(setHKL,
void(Mantid::Kernel::V3D HKL));
MOCK_CONST_METHOD0(getQLabFrame,
Mantid::Kernel::V3D());
MOCK_CONST_METHOD0(getQSampleFrame,
Mantid::Kernel::V3D());
MOCK_METHOD0(findDetector,
bool());
MOCK_METHOD2(setQSampleFrame,
void(Mantid::Kernel::V3D QSampleFrame, double detectorDistance));
MOCK_METHOD2(setQLabFrame,
void(Mantid::Kernel::V3D QLabFrame, double detectorDistance));
MOCK_METHOD1(setWavelength,
void(double wavelength));
MOCK_CONST_METHOD0(getWavelength,
double());
MOCK_CONST_METHOD0(getScattering,
double());
MOCK_CONST_METHOD0(getDSpacing,
double());
MOCK_CONST_METHOD0(getTOF,
double());
MOCK_CONST_METHOD0(getInitialEnergy,
double());
MOCK_CONST_METHOD0(getFinalEnergy,
double());
MOCK_METHOD1(setInitialEnergy,
void(double m_InitialEnergy));
MOCK_METHOD1(setFinalEnergy,
void(double m_FinalEnergy));
MOCK_CONST_METHOD0(getIntensity,
double());
MOCK_CONST_METHOD0(getSigmaIntensity,
double());
MOCK_METHOD1(setIntensity,
void(double m_Intensity));
MOCK_METHOD1(setSigmaIntensity,
void(double m_SigmaIntensity));
MOCK_CONST_METHOD0(getBinCount,
double());
MOCK_METHOD1(setBinCount,
void(double m_BinCount));
MOCK_CONST_METHOD0(getGoniometerMatrix,
Mantid::Kernel::Matrix<double>());
MOCK_METHOD1(setGoniometerMatrix,
void(Mantid::Kernel::Matrix<double> m_GoniometerMatrix));
MOCK_CONST_METHOD0(getBankName,
std::string());
MOCK_CONST_METHOD0(getRow,
int());
MOCK_CONST_METHOD0(getCol,
int());
MOCK_CONST_METHOD0(getDetPos,
Mantid::Kernel::V3D());
MOCK_CONST_METHOD0(getL1,
double());
MOCK_CONST_METHOD0(getL2,
double());
};
public:
void test_throws_if_no_oriented_lattice()
{
//MockFirstExperimentInfoQuery mockQuery;
//EXPECT_CALL(mockQuery, hasOrientedLattice()).Times(1).WillOnce(Return(false)); // opps, no oriented lattice.
//TS_ASSERT_THROWS(MockPeakOverlayFactory f(mockQuery), std::invalid_argument);
//TS_ASSERT( Mock::VerifyAndClearExpectations(&mockQuery));
}
};
#endif /*SLICE_VIEWER_PEAKOVERLAYFACTORY_TEST_H_*/
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