Skip to content

Commit

Permalink
refs #6271. Fix warnings and add proxy.
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenArnold committed Jan 11, 2013
1 parent b257093 commit 91da0bb
Show file tree
Hide file tree
Showing 26 changed files with 228 additions and 122 deletions.
2 changes: 2 additions & 0 deletions Code/Mantid/MantidQt/SliceViewer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ set ( SRC_FILES
src/PeaksWorkspaceWidget.cpp
src/PhysicalCrossPeak.cpp
src/PhysicalSphericalPeak.cpp
src/ProxyCompositePeaksPresenter.cpp
src/QScienceSpinBox.cpp
src/QwtRasterDataMD.cpp
src/SliceViewer.cpp
Expand Down Expand Up @@ -62,6 +63,7 @@ set ( INC_FILES
inc/MantidQtSliceViewer/PeaksWorkspaceWidget.h
inc/MantidQtSliceViewer/PhysicalCrossPeak.h
inc/MantidQtSliceViewer/PhysicalSphericalPeak.h
inc/MantidQtSliceViewer/ProxyCompositePeaksPresenter.h
inc/MantidQtSliceViewer/QScienceSpinBox.h
inc/MantidQtSliceViewer/QwtRasterDataMD.h
inc/MantidQtSliceViewer/SliceViewer.h
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@ namespace MantidQt
/// 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, Colour);
void setForegroundColour(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws, Qt::GlobalColor);
/// Change the background representation for the peaks of this workspace
void setBackgroundColour(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws, Colour);
void setBackgroundColour(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws, Qt::GlobalColor);
private:
/// Default behaviour
PeaksPresenter_sptr m_default;
/// Subject presenters.
std::set<PeaksPresenter_sptr> m_subjects;
/// Use default
bool useDefault() const { return m_subjects.size() == 0; }
void setForegroundColour(const Colour){/*Do nothing*/}
void setBackgroundColour(const Colour){/*Do nothing*/}
void setForegroundColour(const Qt::GlobalColor){/*Do nothing*/}
void setBackgroundColour(const Qt::GlobalColor){/*Do nothing*/}
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ namespace MantidQt
virtual bool changeShownDim();
virtual bool isLabelOfFreeAxis(const std::string& label) const;
SetPeaksWorkspaces presentedWorkspaces() const;
void setForegroundColour(const Colour);
void setBackgroundColour(const Colour);
void setForegroundColour(const Qt::GlobalColor);
void setBackgroundColour(const Qt::GlobalColor);
private:
/// Peak overlay views.
VecPeakOverlayView m_viewPeaks;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ 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 Colour){/*Do nothing*/}
void setBackgroundColour(const Colour){/*Do nothing*/}
void setForegroundColour(const Qt::GlobalColor){/*Do nothing*/}
void setBackgroundColour(const Qt::GlobalColor){/*Do nothing*/}
};

}
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 Colour);
virtual void changeForegroundColour(const Qt::GlobalColor);
/// Change background colour
virtual void changeBackgroundColour(const Colour);
virtual void changeBackgroundColour(const Qt::GlobalColor);

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 Colour);
virtual void changeForegroundColour(const Qt::GlobalColor);
/// Change background colour
virtual void changeBackgroundColour(const Colour);
virtual void changeBackgroundColour(const Qt::GlobalColor);

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 Colour) = 0;
virtual void changeForegroundColour(const Qt::GlobalColor) = 0;
/// Change background colour
virtual void changeBackgroundColour(const Colour) = 0;
virtual void changeBackgroundColour(const Qt::GlobalColor) = 0;
/// Destructor
virtual ~PeakOverlayView()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,18 @@

#include "MantidKernel/System.h"
#include <map>
#include <QColor>

namespace MantidQt
{
namespace SliceViewer
{

enum Colour
{
White=3,
Black=2,
Red=7,
DarkRed=13,
Green=8,
DarkGreen=14,
Blue=9,
DarkBlue=15,
Cyan=10,
DarkCyan=16,
Magenta=11,
DarkMagenta=17,
Yellow=12,
DarkYellow=18,
Gray=5,
DarkGray=4,
LightGray=6,
Transparent=19,
Color0=0,
Color1=1
};

class DLLExport PeakPalette
{
private:

typedef std::map<int, Colour> ColourMapType;
typedef std::map<int, Qt::GlobalColor> ColourMapType;
ColourMapType m_backgroundMap;
ColourMapType m_foregroundMap;
ColourMapType::iterator safeFetchPair(ColourMapType& map, const int index);
Expand All @@ -47,10 +24,10 @@ class DLLExport PeakPalette
PeakPalette();
PeakPalette(const PeakPalette& other);
PeakPalette& operator=(const PeakPalette& other);
Colour foregroundIndexToColour(const int index) const;
Colour backgroundIndexToColour(const int index) const;
void setForegroundColour(const int index, const Colour);
void setBackgroundColour(const int index, const Colour);
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);
int paletteSize() const;
~PeakPalette();
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ namespace SliceViewer
virtual bool changeShownDim() = 0;
virtual bool isLabelOfFreeAxis(const std::string& label) const = 0;
virtual SetPeaksWorkspaces presentedWorkspaces() const = 0;
virtual void setForegroundColour(const Colour) = 0;
virtual void setBackgroundColour(const Colour) = 0;
virtual void setForegroundColour(const Qt::GlobalColor) = 0;
virtual void setBackgroundColour(const Qt::GlobalColor) = 0;
};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,26 @@

#include <QtGui/QWidget>
#include "DllOption.h"
#include <boost/shared_ptr.hpp>
#include "MantidQtSliceViewer/PeaksPresenter.h"

namespace MantidQt
{
namespace SliceViewer
{
/// Forward dec.
class ProxyCompositePeaksPresenter;

class EXPORT_OPT_MANTIDQT_SLICEVIEWER PeaksViewer : public QWidget
{
Q_OBJECT
public:
PeaksViewer(QWidget *parent = 0);
void setPeaksWorkspaces(const SetPeaksWorkspaces& workspaces);
void setPresenter(boost::shared_ptr<ProxyCompositePeaksPresenter> presenter);
~PeaksViewer();
private:
boost::shared_ptr<ProxyCompositePeaksPresenter> m_presenter;
};

} //namespace
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#ifndef MANTID_SLICEVIEWER_PROXYCOMPOSITEPEAKSPRESENTER_H_
#define MANTID_SLICEVIEWER_PROXYCOMPOSITEPEAKSPRESENTER_H_


#include "MantidKernel/System.h"
#include "MantidQtSliceViewer/CompositePeaksPresenter.h"
#include <boost/shared_ptr.hpp>

namespace MantidQt
{
namespace SliceViewer
{
/*---------------------------------------------------------
ProxyCompositePeaksPresenter
Proxy wrapper of the CompositePeaksPresenter. Allows the CompositePeaksPresenter to
be used in suituations where diluted power, via a restricted API is required.
----------------------------------------------------------*/
class DLLExport ProxyCompositePeaksPresenter
{
public:

ProxyCompositePeaksPresenter(boost::shared_ptr<CompositePeaksPresenter> compositePresenter);
~ProxyCompositePeaksPresenter();
size_t size() const;
void update();

void setForegroundColour(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws, Qt::GlobalColor);
/// Change the background representation for the peaks of this workspace
void setBackgroundColour(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws, Qt::GlobalColor);
/// Get references to all presented workspaces.
SetPeaksWorkspaces presentedWorkspaces() const;

private:
/// Wrapped composite to delegate to.
boost::shared_ptr<CompositePeaksPresenter> m_compositePresenter;
};
}
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ namespace SliceViewer

// Forward dec
class CompositePeaksPresenter;
class ProxyCompositePeaksPresenter;

/** GUI for viewing a 2D slice out of a multi-dimensional workspace.
* You can select which dimension to plot as X,Y, and the cut point
Expand Down Expand Up @@ -96,7 +97,7 @@ class EXPORT_OPT_MANTIDQT_SLICEVIEWER SliceViewer : public QWidget
void refreshRebin();

/// Methods relating to peaks overlays.
SetPeaksWorkspaces getPeaksWorkspaces() const;
boost::shared_ptr<ProxyCompositePeaksPresenter> getPeaksPresenter() const;

signals:
/// Signal emitted when the X/Y index of the shown dimensions is changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ 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, Colour colour)
void CompositePeaksPresenter::setForegroundColour(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws, Qt::GlobalColor colour)
{
for(auto it = m_subjects.begin(); it != m_subjects.end(); ++it)
{
Expand All @@ -154,7 +154,7 @@ namespace MantidQt
@ workspace containing the peaks to re-colour
@ colour to use for re-colouring
*/
void CompositePeaksPresenter::setBackgroundColour(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws, Colour colour)
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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ namespace SliceViewer
return workspaces;
}

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

void ConcretePeaksPresenter::setBackgroundColour(const Colour colour)
void ConcretePeaksPresenter::setBackgroundColour(const Qt::GlobalColor 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 Colour colour)
void PeakOverlayCross::changeForegroundColour(const Qt::GlobalColor colour)
{
this->m_peakColour = QColor(colour);
}

void PeakOverlayCross::changeBackgroundColour(const Colour)
void PeakOverlayCross::changeBackgroundColour(const Qt::GlobalColor)
{
// Do nothing with the background colour for a peak widget of this type.
}
Expand Down
4 changes: 2 additions & 2 deletions Code/Mantid/MantidQt/SliceViewer/src/PeakOverlaySphere.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,12 @@ namespace SliceViewer
m_physicalPeak.movePosition(transform);
}

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

void PeakOverlaySphere::changeBackgroundColour(const Colour)
void PeakOverlaySphere::changeBackgroundColour(const Qt::GlobalColor)
{
// Not being drawn at the moment, TODO.
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace MantidQt

PeakPalette defaultPalette;
auto colourEnum = defaultPalette.foregroundIndexToColour(static_cast<int>(workspaceNumber));

//Qt::GlobalColor qtColourEnum = colourEnum;
m_peakColour = QColor(colourEnum);
}

Expand Down
28 changes: 14 additions & 14 deletions Code/Mantid/MantidQt/SliceViewer/src/PeakPalette.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ namespace MantidQt
PeakPalette::PeakPalette()
{
int index = 0;
m_foregroundMap.insert(std::make_pair(index++, Colour::Green));
m_foregroundMap.insert(std::make_pair(index++, Colour::DarkMagenta));
m_foregroundMap.insert(std::make_pair(index++, Colour::Cyan));
m_foregroundMap.insert(std::make_pair(index++, Colour::DarkGreen));
m_foregroundMap.insert(std::make_pair(index++, Colour::DarkCyan));
m_foregroundMap.insert(std::make_pair(index++, Colour::DarkYellow));
m_foregroundMap.insert(std::make_pair(index++, Colour::DarkRed));
m_foregroundMap.insert(std::make_pair(index++, Colour::Black));
m_foregroundMap.insert(std::make_pair(index++, Colour::White));
m_foregroundMap.insert(std::make_pair(index++, Colour::DarkGray));
m_foregroundMap.insert(std::make_pair(index++, Qt::green));
m_foregroundMap.insert(std::make_pair(index++, Qt::darkMagenta));
m_foregroundMap.insert(std::make_pair(index++, Qt::cyan));
m_foregroundMap.insert(std::make_pair(index++, Qt::darkGreen));
m_foregroundMap.insert(std::make_pair(index++, Qt::darkCyan));
m_foregroundMap.insert(std::make_pair(index++, Qt::darkYellow));
m_foregroundMap.insert(std::make_pair(index++, Qt::darkRed));
m_foregroundMap.insert(std::make_pair(index++, Qt::black));
m_foregroundMap.insert(std::make_pair(index++, Qt::white));
m_foregroundMap.insert(std::make_pair(index++, Qt::darkGray));
m_backgroundMap = m_foregroundMap;
}

Expand Down Expand Up @@ -70,26 +70,26 @@ namespace MantidQt
return it;
}

Colour PeakPalette::foregroundIndexToColour(const int index) const
Qt::GlobalColor PeakPalette::foregroundIndexToColour(const int index) const
{
auto it = safeFetchPair(m_foregroundMap, index);
return it->second;
}

Colour PeakPalette::backgroundIndexToColour(const int index) const
Qt::GlobalColor PeakPalette::backgroundIndexToColour(const int index) const
{
auto it = safeFetchPair(m_backgroundMap, index);
return it->second;
}

void PeakPalette::setForegroundColour(const int index, const Colour colour)
void PeakPalette::setForegroundColour(const int index, const Qt::GlobalColor colour)
{
auto it = safeFetchPair(m_foregroundMap, index);
// overwrite
it->second = colour;
}

void PeakPalette::setBackgroundColour(const int index, const Colour colour)
void PeakPalette::setBackgroundColour(const int index, const Qt::GlobalColor colour)
{
auto it = safeFetchPair(m_backgroundMap, index);
// owverwirte
Expand Down

0 comments on commit 91da0bb

Please sign in to comment.