Skip to content

Commit

Permalink
Initial work on prevew plot widget
Browse files Browse the repository at this point in the history
Refs #11036
  • Loading branch information
DanNixon committed Feb 9, 2015
1 parent 6640342 commit 370128b
Show file tree
Hide file tree
Showing 4 changed files with 280 additions and 2 deletions.
Expand Up @@ -2,6 +2,8 @@

#include <QFileInfo>

#include "MantidQtMantidWidgets/PreviewPlot.h"

using namespace Mantid::API;

namespace MantidQt
Expand All @@ -18,11 +20,17 @@ namespace CustomInterfaces
m_uiForm.setupUi(parent);

// Preview plot
m_plots["PreviewPlot"] = new QwtPlot(m_parentWidget);
m_plots["PreviewPlot"] = new QwtPlot(0); //m_parentWidget);
m_plots["PreviewPlot"]->setAxisFont(QwtPlot::xBottom, parent->font());
m_plots["PreviewPlot"]->setAxisFont(QwtPlot::yLeft, parent->font());
m_plots["PreviewPlot"]->setCanvasBackground(Qt::white);
m_uiForm.plotPreview->addWidget(m_plots["PreviewPlot"]);
/* m_uiForm.plotPreview->addWidget(m_plots["PreviewPlot"]); */

//TODO
MantidWidgets::PreviewPlot *plot = new MantidWidgets::PreviewPlot(m_parentWidget);
plot->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
plot->setCanvasColour(Qt::white);
m_uiForm.plotPreview->addWidget(plot);

// Update the preview plot when the algorithm is complete
connect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, SLOT(transAlgDone(bool)));
Expand Down
2 changes: 2 additions & 0 deletions Code/Mantid/MantidQt/MantidWidgets/CMakeLists.txt
Expand Up @@ -40,6 +40,7 @@ set ( SRC_FILES
src/UserFunctionDialog.cpp
src/WorkspaceEditorFactory.cpp
src/WorkspaceSelector.cpp
src/PreviewPlot.cpp
src/pqHelpWindow.cxx
src/pythonCalc.cpp
src/LineEditWithClear.cpp
Expand Down Expand Up @@ -72,6 +73,7 @@ set ( MOC_FILES
inc/MantidQtMantidWidgets/MWRunFiles.h
inc/MantidQtMantidWidgets/PeakPicker.h
inc/MantidQtMantidWidgets/pqHelpWindow.h
inc/MantidQtMantidWidgets/PreviewPlot.h
inc/MantidQtMantidWidgets/PropertyHandler.h
inc/MantidQtMantidWidgets/ProcessingAlgoWidget.h
inc/MantidQtMantidWidgets/pythonCalc.h
Expand Down
@@ -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 &copy; 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_
159 changes: 159 additions & 0 deletions Code/Mantid/MantidQt/MantidWidgets/src/PreviewPlot.cpp
@@ -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)
{
}

0 comments on commit 370128b

Please sign in to comment.