Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refs #11036
- Loading branch information
Showing
4 changed files
with
280 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
Code/Mantid/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/PreviewPlot.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
#ifndef MANTIDQTMANTIDWIDGETS_PREVIEWPLOT_H_ | ||
#define MANTIDQTMANTIDWIDGETS_PREVIEWPLOT_H_ | ||
|
||
#include "WidgetDllOption.h" | ||
#include "MantidQtAPI/MantidWidget.h" | ||
|
||
#include "MantidAPI/MatrixWorkspace.h" | ||
|
||
#include <qwt_plot.h> | ||
#include <qwt_plot_curve.h> | ||
#include <qwt_plot_magnifier.h> | ||
#include <qwt_plot_panner.h> | ||
#include <qwt_plot_zoomer.h> | ||
|
||
|
||
namespace MantidQt | ||
{ | ||
namespace MantidWidgets | ||
{ | ||
/** | ||
A widget to display several workspaces on a plot on a custom interface. | ||
Gives option to use pan and zoom options to navigate plot. | ||
@author Dan Nixon | ||
Copyright © 2011 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge National Laboratory & European Spallation Source | ||
This file is part of Mantid. | ||
Mantid is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 3 of the License, or | ||
(at your option) any later version. | ||
Mantid is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
File change history is stored at: <https://github.com/mantidproject/mantid> | ||
Code Documentation is available at: <http://doxygen.mantidproject.org> | ||
*/ | ||
|
||
class EXPORT_OPT_MANTIDQT_MANTIDWIDGETS PreviewPlot : public API::MantidWidget | ||
{ | ||
Q_OBJECT | ||
|
||
Q_PROPERTY(QColor canvasColour READ canvasColour WRITE setCanvasColour) | ||
Q_PROPERTY(bool allowPan READ allowPan WRITE setAllowPan) | ||
Q_PROPERTY(bool allowZoom READ allowZoom WRITE setAllowZoom) | ||
|
||
public: | ||
PreviewPlot(QWidget *parent = NULL, bool init = true); | ||
virtual ~PreviewPlot(); | ||
|
||
QColor canvasColour(); | ||
void setCanvasColour(const QColor & colour); | ||
|
||
bool allowPan(); | ||
void setAllowPan(bool allow); | ||
|
||
bool allowZoom(); | ||
void setAllowZoom(bool allow); | ||
|
||
void addSpectra(Mantid::API::MatrixWorkspace_sptr ws, int specIndex = 0); | ||
void addSpectra(const QString & wsName, int specIndex = 0); | ||
|
||
void removeSpectra(Mantid::API::MatrixWorkspace_sptr ws); | ||
void removeSpectra(const QString & wsName); | ||
|
||
void replot(); | ||
|
||
private: | ||
void handleRemoveEvent(Mantid::API::WorkspacePreDeleteNotification_ptr pNf); | ||
void handleReplaceEvent(Mantid::API::WorkspaceAfterReplaceNotification_ptr pNf); | ||
|
||
private: | ||
/// Poco Observers for ADS Notifications | ||
Poco::NObserver<PreviewPlot, Mantid::API::WorkspacePreDeleteNotification> m_removeObserver; | ||
Poco::NObserver<PreviewPlot, Mantid::API::WorkspaceAfterReplaceNotification> m_replaceObserver; | ||
|
||
/// If the widget was initialised | ||
bool m_init; | ||
|
||
/// If the plot manipulation tools are allowed | ||
bool m_allowPan; | ||
bool m_allowZoom; | ||
|
||
/// The plot its self | ||
QwtPlot *m_plot; | ||
|
||
/// Map of workspaces to plot curves | ||
QMap<Mantid::API::MatrixWorkspace_sptr, QwtPlotCurve> m_curves; | ||
|
||
/// Plot manipulation tools | ||
QwtPlotMagnifier *m_magnifyTool; | ||
QwtPlotPanner *m_panTool; | ||
QwtPlotZoomer *m_zoomTool; | ||
|
||
}; | ||
|
||
} | ||
} | ||
|
||
#endif //MANTIDQTMANTIDWIDGETS_PREVIEWPLOT_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
//------------------------------------------------------ | ||
// Includes | ||
//------------------------------------------------------ | ||
#include "MantidQtMantidWidgets/PreviewPlot.h" | ||
|
||
#include <Poco/Notification.h> | ||
#include <Poco/NotificationCenter.h> | ||
#include <Poco/AutoPtr.h> | ||
#include <Poco/NObserver.h> | ||
|
||
#include <QBrush> | ||
#include <QHBoxLayout> | ||
|
||
using namespace MantidQt::MantidWidgets; | ||
|
||
|
||
PreviewPlot::PreviewPlot(QWidget *parent, bool init) : API::MantidWidget(parent), | ||
m_removeObserver(*this, &PreviewPlot::handleRemoveEvent), | ||
m_replaceObserver(*this, &PreviewPlot::handleReplaceEvent), | ||
m_init(init), m_allowPan(false), m_allowZoom(false), | ||
m_plot(NULL), m_curves(), | ||
m_magnifyTool(NULL), m_panTool(NULL), m_zoomTool(NULL) | ||
{ | ||
if(init) | ||
{ | ||
Mantid::API::AnalysisDataServiceImpl& ads = Mantid::API::AnalysisDataService::Instance(); | ||
ads.notificationCenter.addObserver(m_removeObserver); | ||
ads.notificationCenter.addObserver(m_replaceObserver); | ||
|
||
QHBoxLayout *mainLayout = new QHBoxLayout(this); | ||
mainLayout->setSizeConstraint(QLayout::SetNoConstraint); | ||
|
||
m_plot = new QwtPlot(this); | ||
m_plot->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | ||
mainLayout->addWidget(m_plot); | ||
|
||
this->setLayout(mainLayout); | ||
} | ||
} | ||
|
||
|
||
/** | ||
* Destructor | ||
* | ||
* Removes observers on the ADS. | ||
*/ | ||
PreviewPlot::~PreviewPlot() | ||
{ | ||
if(m_init) | ||
{ | ||
Mantid::API::AnalysisDataService::Instance().notificationCenter.removeObserver(m_removeObserver); | ||
Mantid::API::AnalysisDataService::Instance().notificationCenter.removeObserver(m_replaceObserver); | ||
} | ||
} | ||
|
||
|
||
/** | ||
* Gets the background colour of the plot window. | ||
* | ||
* @return Plot canvas colour | ||
*/ | ||
QColor PreviewPlot::canvasColour() | ||
{ | ||
if(m_plot) | ||
return m_plot->canvasBackground(); | ||
|
||
return QColor(); | ||
} | ||
|
||
|
||
/** | ||
* Sets the background colour of the plot window. | ||
* | ||
* @param colour Plot canvas colour | ||
*/ | ||
void PreviewPlot::setCanvasColour(const QColor & colour) | ||
{ | ||
if(m_plot) | ||
m_plot->setCanvasBackground(QBrush(colour)); | ||
} | ||
|
||
|
||
/** | ||
* Enables or disables the option to use the pan tool on the plot. | ||
* | ||
* @param allow If tool should be allowed | ||
*/ | ||
void PreviewPlot::setAllowPan(bool allow) | ||
{ | ||
m_allowPan = allow; | ||
} | ||
|
||
|
||
/** | ||
* Checks to see if the option to use the pan tool is enabled. | ||
* | ||
* @return True if tool is allowed | ||
*/ | ||
bool PreviewPlot::allowPan() | ||
{ | ||
return m_allowPan; | ||
} | ||
|
||
|
||
/** | ||
* Enables or disables the option to use the zoom tool on the plot. | ||
* | ||
* @param allow If tool should be allowed | ||
*/ | ||
void PreviewPlot::setAllowZoom(bool allow) | ||
{ | ||
m_allowZoom = allow; | ||
} | ||
|
||
|
||
/** | ||
* Checks to see if the option to use the zoom tool is enabled. | ||
* | ||
* @return True if tool is allowed | ||
*/ | ||
bool PreviewPlot::allowZoom() | ||
{ | ||
return m_allowZoom; | ||
} | ||
|
||
|
||
void PreviewPlot::addSpectra(Mantid::API::MatrixWorkspace_sptr ws, int specIndex) | ||
{ | ||
} | ||
|
||
|
||
void PreviewPlot::addSpectra(const QString & wsName, int specIndex) | ||
{ | ||
} | ||
|
||
|
||
void PreviewPlot::removeSpectra(Mantid::API::MatrixWorkspace_sptr ws) | ||
{ | ||
} | ||
|
||
|
||
void PreviewPlot::removeSpectra(const QString & wsName) | ||
{ | ||
} | ||
|
||
|
||
void PreviewPlot::replot() | ||
{ | ||
} | ||
|
||
|
||
void PreviewPlot::handleRemoveEvent(Mantid::API::WorkspacePreDeleteNotification_ptr pNf) | ||
{ | ||
} | ||
|
||
|
||
void PreviewPlot::handleReplaceEvent(Mantid::API::WorkspaceAfterReplaceNotification_ptr pNf) | ||
{ | ||
} |