Skip to content

Commit

Permalink
refs #6271. Expose transform type.
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenArnold committed Jan 11, 2013
1 parent 91da0bb commit 3145bbc
Show file tree
Hide file tree
Showing 18 changed files with 132 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ namespace MantidQt
virtual void updateWithSlicePoint(const double&);
virtual bool changeShownDim();
virtual bool isLabelOfFreeAxis(const std::string& label) const;
SetPeaksWorkspaces presentedWorkspaces() const;
void setForegroundColour(const Qt::GlobalColor){/*Do nothing*/}
void setBackgroundColour(const Qt::GlobalColor){/*Do nothing*/}
virtual std::string getTransformName() const;

/// Constructor
CompositePeaksPresenter(PeaksPresenter_sptr defaultPresenter = PeaksPresenter_sptr(new NullPeaksPresenter));
Expand All @@ -36,8 +40,6 @@ namespace MantidQt
size_t size() const;
/// Clear the owned presenters.
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, Qt::GlobalColor);
/// Change the background representation for the peaks of this workspace
Expand All @@ -49,8 +51,10 @@ namespace MantidQt
std::set<PeaksPresenter_sptr> m_subjects;
/// Use default
bool useDefault() const { return m_subjects.size() == 0; }
void setForegroundColour(const Qt::GlobalColor){/*Do nothing*/}
void setBackgroundColour(const Qt::GlobalColor){/*Do nothing*/}
/// Get the presenter for a given workspace.
PeaksPresenter_sptr getPresenterFromWorkspace(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws);


};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ namespace MantidQt
SetPeaksWorkspaces presentedWorkspaces() const;
void setForegroundColour(const Qt::GlobalColor);
void setBackgroundColour(const Qt::GlobalColor);
std::string getTransformName() const;
private:
/// Peak overlay views.
VecPeakOverlayView m_viewPeaks;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace MantidQt
SetPeaksWorkspaces presentedWorkspaces() const{SetPeaksWorkspaces empty; return empty;}
void setForegroundColour(const Qt::GlobalColor){/*Do nothing*/}
void setBackgroundColour(const Qt::GlobalColor){/*Do nothing*/}
std::string getTransformName() const {return "";}
};

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ namespace MantidQt
boost::regex getFreePeakAxisRegex() const;
/// Virtual constructor.
virtual boost::shared_ptr<PeakTransform> clone() const = 0;
/// Getter for a friendly name to describe the transform type.
virtual std::string getFriendlyName() const = 0;
protected:
PeakTransform(const PeakTransform& other);
std::string m_xPlotLabel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,26 @@ namespace MantidQt
class DLLExport PeakTransformHKL : public PeakTransform
{
public:
static std::string name(){return "HKL";}
/// Constructor
PeakTransformHKL();
/// Constructor
PeakTransformHKL(const std::string& xPlotLabel, const std::string& yPlotLabel);
/// Destructor
virtual ~PeakTransformHKL();
/// Copy Constructor
PeakTransformHKL(const PeakTransformHKL& other);
/// Assigmentent
PeakTransformHKL & operator=(const PeakTransformHKL & other);
/// Virtual constructor
PeakTransform_sptr clone() const;
/// Transform peak.
Mantid::Kernel::V3D transformPeak(const Mantid::API::IPeak& peak) const;
/// Getter for a friendly name to describe the transform type.
virtual std::string getFriendlyName() const
{
return name();
}
};

/// Typedef a factory for type of PeaksTransform.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,26 @@ namespace MantidQt
class DLLExport PeakTransformQLab : public PeakTransform
{
public:
static std::string name(){ return "QLab"; }
/// Constructor
PeakTransformQLab();
/// Constructor
PeakTransformQLab(const std::string& xPlotLabel, const std::string& yPlotLabel);
/// Destructor
virtual ~PeakTransformQLab();
/// Copy constructor
PeakTransformQLab(const PeakTransformQLab& other);
/// Assigment
PeakTransformQLab & operator=(const PeakTransformQLab & other);
/// Virtual constructor
PeakTransform_sptr clone() const;
/// Transform peak.
Mantid::Kernel::V3D transformPeak(const Mantid::API::IPeak& peak) const;
/// Get the transform friendly name.
virtual std::string getFriendlyName() const
{
return name();
}
};

/// Typedef a factory for type of PeaksTransform.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,27 @@ namespace MantidQt
class DLLExport PeakTransformQSample : public PeakTransform
{
public:
/// Transform name.
static std::string name(){ return "QLab"; }
/// Constructor
PeakTransformQSample();
/// Constructor
PeakTransformQSample(const std::string& xPlotLabel, const std::string& yPlotLabel);
/// Destructor
virtual ~PeakTransformQSample();
/// Copy constructor
PeakTransformQSample(const PeakTransformQSample& other);
/// Assigment
PeakTransformQSample & operator=(const PeakTransformQSample & other);
/// Virtual constructor
PeakTransform_sptr clone() const;
/// Transform peak.
Mantid::Kernel::V3D transformPeak(const Mantid::API::IPeak& peak) const;
/// Getter for the transform name.
virtual std::string getFriendlyName() const
{
return name();
}
};

/// Typedef a factory for type of PeaksTransform.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace SliceViewer
// Forward dec.
class PeakOverlayViewFactory;
class PeakOverlayView;
class PeakTransform;

// Alias
typedef std::set<boost::shared_ptr<const Mantid::API::IPeaksWorkspace> > SetPeaksWorkspaces;
Expand All @@ -44,6 +45,7 @@ namespace SliceViewer
virtual SetPeaksWorkspaces presentedWorkspaces() const = 0;
virtual void setForegroundColour(const Qt::GlobalColor) = 0;
virtual void setBackgroundColour(const Qt::GlobalColor) = 0;
virtual std::string getTransformName() const = 0;
};


Expand Down
43 changes: 27 additions & 16 deletions Code/Mantid/MantidQt/SliceViewer/src/CompositePeaksPresenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,22 +131,33 @@ namespace MantidQt
}

/**
Set the foreground colour of the peaks.
@ workspace containing the peaks to re-colour
@ colour to use for re-colouring
@param ws : Peaks Workspace to look for on sub-presenters.
@return the identified sub-presenter for the workspace, or a NullPeaksPresenter.
*/
void CompositePeaksPresenter::setForegroundColour(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws, Qt::GlobalColor colour)
PeaksPresenter_sptr CompositePeaksPresenter::getPresenterFromWorkspace(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws)
{
for(auto it = m_subjects.begin(); it != m_subjects.end(); ++it)
PeaksPresenter_sptr presenterFound = PeaksPresenter_sptr(new NullPeaksPresenter);
for(auto presenterIterator = m_subjects.begin(); presenterIterator != m_subjects.end(); ++presenterIterator)
{
auto workspacesOfSubject = (*it)->presentedWorkspaces();
auto iteratorFound = workspacesOfSubject.find(ws);
auto workspacesOfSubject = (*presenterIterator)->presentedWorkspaces();
SetPeaksWorkspaces::iterator iteratorFound = workspacesOfSubject.find(ws);
if(iteratorFound != workspacesOfSubject.end())
{
(*it)->setForegroundColour(colour);
presenterFound = *presenterIterator;
break;
}
}
return presenterFound;
}

/**
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, Qt::GlobalColor colour)
{
getPresenterFromWorkspace(ws)->setForegroundColour(colour);
}

/**
Expand All @@ -156,16 +167,16 @@ namespace MantidQt
*/
void CompositePeaksPresenter::setBackgroundColour(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws, Qt::GlobalColor colour)
{
for(auto it = m_subjects.begin(); it != m_subjects.end(); ++it)
getPresenterFromWorkspace(ws)->setBackgroundColour(colour);
}

std::string CompositePeaksPresenter::getTransformName() const
{
if(useDefault())
{
auto workspacesOfSubject = (*it)->presentedWorkspaces();
auto iteratorFound = workspacesOfSubject.find(ws);
if(iteratorFound != workspacesOfSubject.end())
{
(*it)->setBackgroundColour(colour);
break;
}
return m_default->getTransformName();
}
return (*m_subjects.begin())->getTransformName();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ namespace SliceViewer
{
std::string xLabel = m_viewFactory->getPlotXLabel();
std::string yLabel = m_viewFactory->getPlotYLabel();
m_transform = m_transformFactory->createTransform(xLabel, yLabel);
auto temp = m_transformFactory->createTransform(xLabel, yLabel);
m_transform = temp;
showAll();
transformSucceeded = true;
}
Expand Down Expand Up @@ -249,5 +250,10 @@ namespace SliceViewer
}
}

std::string ConcretePeaksPresenter::getTransformName() const
{
return m_transform->getFriendlyName();
}

}
}
3 changes: 3 additions & 0 deletions Code/Mantid/MantidQt/SliceViewer/src/PeaksViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ namespace MantidQt

// Configure the entire control using the managed workspaces.
auto workspaces = m_presenter->presentedWorkspaces();



auto _layout = layout();
if(_layout)
{
Expand Down
4 changes: 0 additions & 4 deletions Code/Mantid/MantidQt/SliceViewer/src/PeaksWorkspaceWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ namespace MantidQt
const QString integratedMsg = "integrated";

ui.lblWorkspaceName->setText(m_ws->hasIntegratedPeaks() ? integratedMsg : unintegratedMsg );

// Viewing coordinate system.... ? SliceViewer::peakCoordinateSystem() -> PeakTransformSelector -> PeakTransformFactory::productName(instancemethod) -> PeakTransform::name(static)
// Default Background colour .... ? -- PeakPallette ?
// Default Foreground colour .... ? -- PeakPallette ?
}

PeaksWorkspaceWidget::~PeaksWorkspaceWidget()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,33 @@ class CompositePeaksPresenterTest : public CxxTest::TestSuite
TS_ASSERT(Mock::VerifyAndClearExpectations(mockPresenter));
}

void test_getTransformName_default()
{
MockPeaksPresenter* mockDefault = new MockPeaksPresenter;
PeaksPresenter_sptr defaultPresenter(mockDefault);
EXPECT_CALL(*mockDefault, getTransformName()).Times(1).WillOnce(Return(""));// Expect the method on the default to be called.

defaultPresenter->getTransformName();

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

void test_getTransformName()
{
MockPeaksPresenter* mockPresenter = new MockPeaksPresenter;
PeaksPresenter_sptr presenter(mockPresenter);
EXPECT_CALL(*mockPresenter, getTransformName()).Times(1).WillOnce(Return(""));

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

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

/**
Check that when no subject presenters have been added, that the composite uses the 'default' for the update method.
*/
Expand Down
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 @@ -33,6 +33,7 @@ namespace
MOCK_CONST_METHOD0(presentedWorkspaces, SetPeaksWorkspaces());
MOCK_METHOD1(setForegroundColour, void(const Qt::GlobalColor));
MOCK_METHOD1(setBackgroundColour, void(const Qt::GlobalColor));
MOCK_CONST_METHOD0(getTransformName, std::string());
~MockPeaksPresenter(){}
};

Expand All @@ -52,6 +53,7 @@ namespace
MOCK_CONST_METHOD0(clone, PeakTransform_sptr());
MOCK_CONST_METHOD1(transform, Mantid::Kernel::V3D(const Mantid::Kernel::V3D&));
MOCK_CONST_METHOD1(transformPeak, Mantid::Kernel::V3D(const Mantid::API::IPeak&));
MOCK_CONST_METHOD0(getFriendlyName, std::string());
};

/*------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class NullPeaksPresenterTest : public CxxTest::TestSuite

void test_construction()
{
TS_ASSERT_THROWS_NOTHING(NullPeaksPresenter p());
TS_ASSERT_THROWS_NOTHING(NullPeaksPresenter p);
}

void test_is_peaks_presenter()
Expand Down
7 changes: 6 additions & 1 deletion Code/Mantid/MantidQt/SliceViewer/test/PeakTransformHKLTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,12 @@ void test_factory()
TS_ASSERT_EQUALS(regexA, regexB);
}

private:
void test_getFriendlyName()
{
PeakTransformHKL transform;
TS_ASSERT_EQUALS(PeakTransformHKL::name(), transform.getFriendlyName());
}

};
#endif

Expand Down
5 changes: 5 additions & 0 deletions Code/Mantid/MantidQt/SliceViewer/test/PeakTransformQLabTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ void test_factory()
TS_ASSERT_EQUALS(regexA, regexB);
}

void test_getFriendlyName()
{
PeakTransformQLab transform;
TS_ASSERT_EQUALS(PeakTransformQLab::name(), transform.getFriendlyName());
}

};
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,12 @@ void test_factory()
TS_ASSERT_EQUALS(regexA, regexB);
}

void test_getFriendlyName()
{
PeakTransformQSample transform;
TS_ASSERT_EQUALS(PeakTransformQSample::name(), transform.getFriendlyName());
}


};
#endif
Expand Down

0 comments on commit 3145bbc

Please sign in to comment.