From fa711bd27cbebc77c649a36fcd319dc9d393e1a7 Mon Sep 17 00:00:00 2001 From: Dan Nixon Date: Thu, 15 Jan 2015 17:03:32 +0000 Subject: [PATCH] Add a zoomer and panner to the UI Zooming not working properly yet, cannot zoom using mouse wheel with pan Refs #10802 --- .../MantidQtCustomInterfaces/DataComparison.h | 10 ++++ .../DataComparison.ui | 41 +++++++++++++++-- .../CustomInterfaces/src/DataComparison.cpp | 46 ++++++++++++++++++- 3 files changed, 93 insertions(+), 4 deletions(-) diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/DataComparison.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/DataComparison.h index b3291237f0cd..8baedca5cf49 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/DataComparison.h +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/DataComparison.h @@ -12,6 +12,8 @@ #include #include +#include +#include namespace MantidQt @@ -49,6 +51,10 @@ namespace CustomInterfaces void updatePlot(); /// Handles creating and plotting a diff worksapce void plotDiffWorkspace(); + /// Toggle the pan plot tool + void togglePan(bool enabled); + /// Toggle the zoom plot tool + void toggleZoom(bool enabled); private: /// Enumeration for column index @@ -73,6 +79,10 @@ namespace CustomInterfaces // The plot object QwtPlot *m_plot; + // Plot zoom tool + QwtPlotZoomer *m_zoomTool; + // Plot pan tool + QwtPlotPanner *m_panTool; // Curves shown on plot, indexed by workspace name QMap> m_curves; diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/DataComparison.ui b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/DataComparison.ui index 7a9af7382e2a..474f8cddef26 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/DataComparison.ui +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/DataComparison.ui @@ -94,14 +94,49 @@ - + + + + + + + + 0 + 0 + + + + View + + + + + + Pan + + + true + + + + + + + Zoom + + + true + + + + Spectrum: - + / 0 @@ -125,7 +160,7 @@ Diff - + diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/DataComparison.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/DataComparison.cpp index 3dead66967ba..3d23cb829e2d 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/DataComparison.cpp +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/DataComparison.cpp @@ -43,6 +43,13 @@ void DataComparison::initLayout() { m_uiForm.setupUi(this); + m_zoomTool = new QwtPlotZoomer(QwtPlot::xBottom, QwtPlot::yLeft, + QwtPicker::DragSelection | QwtPicker::CornerToCorner, QwtPicker::AlwaysOff, m_plot->canvas()); + m_zoomTool->setEnabled(false); + + m_panTool = new QwtPlotPanner(m_plot->canvas()); + m_panTool->setEnabled(false); + // Add the plot to the UI m_plot->setCanvasBackground(Qt::white); m_uiForm.loPlot->addWidget(m_plot); @@ -56,6 +63,9 @@ void DataComparison::initLayout() connect(m_uiForm.pbDiffSelected, SIGNAL(clicked()), this, SLOT(diffSelected())); connect(m_uiForm.pbClearDiff, SIGNAL(clicked()), this, SLOT(clearDiff())); + connect(m_uiForm.pbPan, SIGNAL(toggled(bool)), this, SLOT(togglePan(bool))); + connect(m_uiForm.pbZoom, SIGNAL(toggled(bool)), this, SLOT(toggleZoom(bool))); + // Replot spectra when the spectrum index is changed connect(m_uiForm.sbSpectrum, SIGNAL(valueChanged(int)), this, SLOT(plotWorkspaces())); @@ -468,7 +478,7 @@ void DataComparison::diffSelected() // Check there is the correct number of selected items if(selectedRows.size() != 2) { - g_log.error() << "Need to have only two workspaces selected for diff (have " + g_log.error() << "Need to have exactly 2 workspaces selected for diff (have " << selectedRows.size() << ")" << std::endl; return; } @@ -496,3 +506,37 @@ void DataComparison::clearDiff() // Update the plot plotWorkspaces(); } + + +/** + * Toggles the pan plot tool. + * + * @param enabled If the tool should be enabled + */ +void DataComparison::togglePan(bool enabled) +{ + // First disbale the zoom tool + if(enabled && m_uiForm.pbZoom->isChecked()) + { + m_uiForm.pbZoom->setChecked(false); + } + + m_panTool->setEnabled(enabled); +} + + +/** + * Toggles the zoom plot tool. + * + * @param enabled If the tool should be enabled + */ +void DataComparison::toggleZoom(bool enabled) +{ + // First disbale the pan tool + if(enabled && m_uiForm.pbPan->isChecked()) + { + m_uiForm.pbPan->setChecked(false); + } + + m_zoomTool->setEnabled(enabled); +}