Skip to content

Commit

Permalink
refs #6271. Hook into PeakPalette when changing colours.
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenArnold committed Jan 7, 2013
1 parent de0c84d commit fc18f64
Show file tree
Hide file tree
Showing 23 changed files with 380 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

#include "MantidQtSliceViewer/PeaksPresenter.h"
#include "MantidQtSliceViewer/NullPeaksPresenter.h"
#include <set>
#include "MantidQtSliceViewer/PeakPalette.h"
#include <vector>
#include <boost/shared_ptr.hpp>

namespace MantidQt
Expand All @@ -26,8 +27,8 @@ namespace MantidQt
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*/}
void setForegroundColour(const QColor){/*Do nothing*/}
void setBackgroundColour(const QColor){/*Do nothing*/}
virtual std::string getTransformName() const;

/// Constructor
Expand All @@ -41,20 +42,30 @@ namespace MantidQt
/// Clear the owned presenters.
void clear();
/// Change the foreground representation for the peaks of this workspace
void setForegroundColour(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws, Qt::GlobalColor);
void setForegroundColour(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws, const QColor);
/// Change the background representation for the peaks of this workspace
void setBackgroundColour(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws, Qt::GlobalColor);
void setBackgroundColour(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws, const QColor);
/// Get the foreground colour corresponding to the workspace
QColor getForegroundColour(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws) const;
/// Get the background colour corresponding to the workspace
QColor getBackgroundColour(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws) const;
/// Get a copy of the palette in its current state.
PeakPalette getPalette() const;
private:
/// Alias for container of subjects type.
typedef std::vector<PeaksPresenter_sptr> SubjectContainer;
/// Default behaviour
PeaksPresenter_sptr m_default;
/// Subject presenters.
std::set<PeaksPresenter_sptr> m_subjects;
SubjectContainer m_subjects;
/// Use default
bool useDefault() const { return m_subjects.size() == 0; }
/// Get the presenter for a given workspace.
PeaksPresenter_sptr getPresenterFromWorkspace(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws);


SubjectContainer::iterator getPresenterIteratorFromWorkspace(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws);
/// Get the presenter for a given workspace.
SubjectContainer::const_iterator getPresenterIteratorFromWorkspace(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws) const;
/// Colour pallette.
PeakPalette m_palette;
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ namespace MantidQt
virtual bool changeShownDim();
virtual bool isLabelOfFreeAxis(const std::string& label) const;
SetPeaksWorkspaces presentedWorkspaces() const;
void setForegroundColour(const Qt::GlobalColor);
void setBackgroundColour(const Qt::GlobalColor);
void setForegroundColour(const QColor);
void setBackgroundColour(const QColor);
std::string getTransformName() const;
private:
/// Peak overlay views.
VecPeakOverlayView m_viewPeaks;
/// View factory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ namespace MantidQt
virtual bool changeShownDim(){return false;}
virtual bool isLabelOfFreeAxis(const std::string&) const {return false;}
SetPeaksWorkspaces presentedWorkspaces() const{SetPeaksWorkspaces empty; return empty;}
void setForegroundColour(const Qt::GlobalColor){/*Do nothing*/}
void setBackgroundColour(const Qt::GlobalColor){/*Do nothing*/}
void setForegroundColour(const QColor){/*Do nothing*/}
void setBackgroundColour(const QColor){/*Do nothing*/}
std::string getTransformName() const {return "";}
/*virtual QColor getForegroundColour() const{ throw std::logic_error("NullPeaksPresenter::getForegroundColour not possible.");};
virtual QColor getBackgroundColour() const{ throw std::logic_error("NullPeaksPresenter::getBackgroundColour not possible");};*/
};

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ namespace SliceViewer
/// Move the position of the peak, by using a different configuration of the existing origin indexes.
void movePosition(PeakTransform_sptr peakTransform);
/// Change foreground colour
virtual void changeForegroundColour(const Qt::GlobalColor);
virtual void changeForegroundColour(const QColor);
/// Change background colour
virtual void changeBackgroundColour(const Qt::GlobalColor);
virtual void changeBackgroundColour(const QColor);

private:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ namespace SliceViewer
/// Move the position of the peak, by using a different configuration of the existing origin indexes.
void movePosition(PeakTransform_sptr peakTransform);
/// Change foreground colour
virtual void changeForegroundColour(const Qt::GlobalColor);
virtual void changeForegroundColour(const QColor);
/// Change background colour
virtual void changeBackgroundColour(const Qt::GlobalColor);
virtual void changeBackgroundColour(const QColor);

private:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ namespace MantidQt
/// Move the peak overlay to a new position.
virtual void movePosition(PeakTransform_sptr peakTransform) = 0;
/// Change foreground colour
virtual void changeForegroundColour(const Qt::GlobalColor) = 0;
virtual void changeForegroundColour(const QColor) = 0;
/// Change background colour
virtual void changeBackgroundColour(const Qt::GlobalColor) = 0;
virtual void changeBackgroundColour(const QColor) = 0;
/// Destructor
virtual ~PeakOverlayView()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class DLLExport PeakPalette
{
private:

typedef std::map<int, Qt::GlobalColor> ColourMapType;
typedef std::map<int, QColor> ColourMapType;
ColourMapType m_backgroundMap;
ColourMapType m_foregroundMap;
ColourMapType::iterator safeFetchPair(ColourMapType& map, const int index);
Expand All @@ -24,11 +24,12 @@ class DLLExport PeakPalette
PeakPalette();
PeakPalette(const PeakPalette& other);
PeakPalette& operator=(const PeakPalette& other);
Qt::GlobalColor foregroundIndexToColour(const int index) const;
Qt::GlobalColor backgroundIndexToColour(const int index) const;
void setForegroundColour(const int index, const Qt::GlobalColor);
void setBackgroundColour(const int index, const Qt::GlobalColor);
QColor foregroundIndexToColour(const int index) const;
QColor backgroundIndexToColour(const int index) const;
void setForegroundColour(const int index, const QColor);
void setBackgroundColour(const int index, const QColor);
int paletteSize() const;
bool operator==(const PeakPalette& other) const;
~PeakPalette();
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ namespace SliceViewer
virtual bool changeShownDim() = 0;
virtual bool isLabelOfFreeAxis(const std::string& label) const = 0;
virtual SetPeaksWorkspaces presentedWorkspaces() const = 0;
virtual void setForegroundColour(const Qt::GlobalColor) = 0;
virtual void setBackgroundColour(const Qt::GlobalColor) = 0;
virtual void setForegroundColour(const QColor) = 0;
virtual void setBackgroundColour(const QColor) = 0;
virtual std::string getTransformName() const = 0;
/*virtual QColor getForegroundColour() const = 0;
virtual QColor getBackgroundColour() const = 0;*/
};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "DllOption.h"
#include <boost/shared_ptr.hpp>
#include "MantidQtSliceViewer/PeaksPresenter.h"
#include "MantidAPI/IPeaksWorkspace.h"

namespace MantidQt
{
Expand All @@ -13,6 +14,9 @@ namespace SliceViewer
/// Forward dec.
class ProxyCompositePeaksPresenter;

/**
*/
class EXPORT_OPT_MANTIDQT_SLICEVIEWER PeaksViewer : public QWidget
{
Q_OBJECT
Expand All @@ -22,6 +26,9 @@ class EXPORT_OPT_MANTIDQT_SLICEVIEWER PeaksViewer : public QWidget
void setPresenter(boost::shared_ptr<ProxyCompositePeaksPresenter> presenter);
void hide();
~PeaksViewer();
public slots:
void onPeakColourChanged(Mantid::API::IPeaksWorkspace_const_sptr, QColor);
void onBackgroundColourChanged(Mantid::API::IPeaksWorkspace_const_sptr, QColor);
private:
boost::shared_ptr<ProxyCompositePeaksPresenter> m_presenter;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ namespace SliceViewer
public:
PeaksWorkspaceWidget(Mantid::API::IPeaksWorkspace_const_sptr ws, const std::string& coordinateSystem, QWidget *parent = 0);
~PeaksWorkspaceWidget();
signals:
void peakColourChanged(Mantid::API::IPeaksWorkspace_const_sptr, QColor);
void backgroundColourChanged(Mantid::API::IPeaksWorkspace_const_sptr, QColor);
private:
/// Populate the widget with model data.
void populate();
Expand All @@ -27,7 +30,9 @@ namespace SliceViewer
/// Coordinate system.
const std::string m_coordinateSystem;
private slots:
void expandChanged(bool);
void onExpandChanged(bool);
void onBackgroundColourClicked();
void onForegroundColourClicked();
};

} //namespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ namespace MantidQt
size_t size() const;
void update();

void setForegroundColour(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws, Qt::GlobalColor);
void setForegroundColour(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws, QColor);
/// Change the background representation for the peaks of this workspace
void setBackgroundColour(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws, Qt::GlobalColor);
void setBackgroundColour(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws, QColor);
/// Get the foreground colour corresponding to the workspace
QColor getForegroundColour(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws) const;
/// Get the background colour corresponding to the workspace
QColor getBackgroundColour(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws) const;
/// Get references to all presented workspaces.
SetPeaksWorkspaces presentedWorkspaces() const;
/// Gets the transform name.
Expand Down
89 changes: 81 additions & 8 deletions Code/Mantid/MantidQt/SliceViewer/src/CompositePeaksPresenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,12 @@ namespace MantidQt
{
throw std::invalid_argument("Maximum number of PeaksWorkspaces that can be simultaneously displayed is 10.");
}
m_subjects.insert(presenter);

auto result_it = std::find(m_subjects.begin(), m_subjects.end(), presenter);
if(result_it == m_subjects.end())
{
m_subjects.push_back(presenter);
}
}

/**
Expand Down Expand Up @@ -134,16 +139,36 @@ namespace MantidQt
@param ws : Peaks Workspace to look for on sub-presenters.
@return the identified sub-presenter for the workspace, or a NullPeaksPresenter.
*/
PeaksPresenter_sptr CompositePeaksPresenter::getPresenterFromWorkspace(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws)
CompositePeaksPresenter::SubjectContainer::iterator CompositePeaksPresenter::getPresenterIteratorFromWorkspace(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws)
{
SubjectContainer::iterator presenterFound = m_subjects.end();
for(auto presenterIterator = m_subjects.begin(); presenterIterator != m_subjects.end(); ++presenterIterator)
{
auto workspacesOfSubject = (*presenterIterator)->presentedWorkspaces();
SetPeaksWorkspaces::iterator iteratorFound = workspacesOfSubject.find(ws);
if(iteratorFound != workspacesOfSubject.end())
{
presenterFound = presenterIterator;
break;
}
}
return presenterFound;
}

/**
@param ws : Peaks Workspace to look for on sub-presenters.
@return the identified sub-presenter for the workspace, or a NullPeaksPresenter.
*/
CompositePeaksPresenter::SubjectContainer::const_iterator CompositePeaksPresenter::getPresenterIteratorFromWorkspace(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws) const
{
PeaksPresenter_sptr presenterFound = PeaksPresenter_sptr(new NullPeaksPresenter);
SubjectContainer::const_iterator presenterFound = m_subjects.end();
for(auto presenterIterator = m_subjects.begin(); presenterIterator != m_subjects.end(); ++presenterIterator)
{
auto workspacesOfSubject = (*presenterIterator)->presentedWorkspaces();
SetPeaksWorkspaces::iterator iteratorFound = workspacesOfSubject.find(ws);
if(iteratorFound != workspacesOfSubject.end())
{
presenterFound = *presenterIterator;
presenterFound = presenterIterator;
break;
}
}
Expand All @@ -155,21 +180,39 @@ namespace MantidQt
@ 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)
void CompositePeaksPresenter::setForegroundColour(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws, const QColor colour)
{
getPresenterFromWorkspace(ws)->setForegroundColour(colour);
SubjectContainer::iterator iterator = getPresenterIteratorFromWorkspace(ws);

// Update the palette the foreground colour
const int pos = std::distance(m_subjects.begin(), iterator);
m_palette.setForegroundColour(pos, colour);

// Apply the foreground colour
(*iterator)->setForegroundColour(colour);
}

/**
Set the background colour of the peaks.
@ workspace containing the peaks to re-colour
@ colour to use for re-colouring
*/
void CompositePeaksPresenter::setBackgroundColour(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws, Qt::GlobalColor colour)
void CompositePeaksPresenter::setBackgroundColour(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws,const QColor colour)
{
getPresenterFromWorkspace(ws)->setBackgroundColour(colour);
SubjectContainer::iterator iterator = getPresenterIteratorFromWorkspace(ws);

// Update the palette background colour.
const int pos = std::distance(m_subjects.begin(), iterator);
m_palette.setBackgroundColour(pos, colour);

// Apply the background colour
(*iterator)->setBackgroundColour(colour);
}

/**
Getter for the name of the transform.
@return transform name.
*/
std::string CompositePeaksPresenter::getTransformName() const
{
if(useDefault())
Expand All @@ -178,5 +221,35 @@ namespace MantidQt
}
return (*m_subjects.begin())->getTransformName();
}

/**
@return a copy of the peaks palette.
*/
PeakPalette CompositePeaksPresenter::getPalette() const
{
return this->m_palette;
}

/**
@param ws: PeakWorkspace to get the colour for.
@return the foreground colour corresponding to the peaks workspace.
*/
QColor CompositePeaksPresenter::getForegroundColour(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws) const
{
SubjectContainer::const_iterator iterator = getPresenterIteratorFromWorkspace(ws);
const int pos = std::distance(m_subjects.begin(), iterator);
return m_palette.foregroundIndexToColour(pos);
}

/**
@param ws: PeakWorkspace to get the colour for.
@return the background colour corresponding to the peaks workspace.
*/
QColor CompositePeaksPresenter::getBackgroundColour(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws) const
{
SubjectContainer::const_iterator iterator = getPresenterIteratorFromWorkspace(ws);
const int pos = std::distance(m_subjects.begin(), iterator);
return m_palette.backgroundIndexToColour(pos);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ namespace SliceViewer
return workspaces;
}

void ConcretePeaksPresenter::setForegroundColour(const Qt::GlobalColor colour)
void ConcretePeaksPresenter::setForegroundColour(const QColor colour)
{
// Change foreground colours
for(VecPeakOverlayView::iterator it = m_viewPeaks.begin(); it != m_viewPeaks.end(); ++it)
Expand All @@ -237,7 +237,7 @@ namespace SliceViewer
}
}

void ConcretePeaksPresenter::setBackgroundColour(const Qt::GlobalColor colour)
void ConcretePeaksPresenter::setBackgroundColour(const QColor colour)
{
// Change background colours
for(VecPeakOverlayView::iterator it = m_viewPeaks.begin(); it != m_viewPeaks.end(); ++it)
Expand Down
4 changes: 2 additions & 2 deletions Code/Mantid/MantidQt/SliceViewer/src/PeakOverlayCross.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,12 @@ namespace SliceViewer
m_physicalPeak.movePosition(transform);
}

void PeakOverlayCross::changeForegroundColour(const Qt::GlobalColor colour)
void PeakOverlayCross::changeForegroundColour(const QColor colour)
{
this->m_peakColour = QColor(colour);
}

void PeakOverlayCross::changeBackgroundColour(const Qt::GlobalColor)
void PeakOverlayCross::changeBackgroundColour(const QColor)
{
// Do nothing with the background colour for a peak widget of this type.
}
Expand Down

0 comments on commit fc18f64

Please sign in to comment.