Skip to content

Commit

Permalink
Add a zoomer and panner to the UI
Browse files Browse the repository at this point in the history
Zooming not working properly yet, cannot zoom using mouse wheel with pan

Refs #10802
  • Loading branch information
DanNixon committed Jan 15, 2015
1 parent b0e6119 commit fa711bd
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 4 deletions.
Expand Up @@ -12,6 +12,8 @@

#include <qwt_plot.h>
#include <qwt_plot_curve.h>
#include <qwt_plot_panner.h>
#include <qwt_plot_zoomer.h>


namespace MantidQt
Expand Down Expand Up @@ -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
Expand All @@ -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<QString, boost::shared_ptr<QwtPlotCurve>> m_curves;

Expand Down
Expand Up @@ -94,14 +94,49 @@
</property>
</widget>
</item>
<item row="2" column="0">
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="gbView">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>View</string>
</property>
<layout class="QGridLayout" name="loView">
<item row="0" column="0">
<widget class="QPushButton" name="pbPan">
<property name="text">
<string>Pan</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="pbZoom">
<property name="text">
<string>Zoom</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="lbSpectrum">
<property name="text">
<string>Spectrum:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<item row="1" column="1">
<widget class="QSpinBox" name="sbSpectrum">
<property name="suffix">
<string> / 0</string>
Expand All @@ -125,7 +160,7 @@
<property name="title">
<string>Diff</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<layout class="QGridLayout" name="loDiff">
<item row="0" column="0">
<widget class="QPushButton" name="pbDiffSelected">
<property name="text">
Expand Down
46 changes: 45 additions & 1 deletion Code/Mantid/MantidQt/CustomInterfaces/src/DataComparison.cpp
Expand Up @@ -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);
Expand All @@ -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()));

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}

0 comments on commit fa711bd

Please sign in to comment.