Skip to content

Commit

Permalink
Re #10474. Added fitting range selector tool.
Browse files Browse the repository at this point in the history
  • Loading branch information
mantid-roman committed Jan 23, 2015
1 parent fd9f3be commit 8ed05a2
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 13 deletions.
Expand Up @@ -2,5 +2,6 @@
<qresource prefix="/MultiDatasetFit/icons">
<file>zoom.png</file>
<file>panning.png</file>
<file>range.png</file>
</qresource>
</RCC>
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Expand Up @@ -37,6 +37,7 @@ namespace MantidQt
namespace MantidWidgets
{
class FunctionBrowser;
class RangeSelector;
}

namespace API
Expand Down Expand Up @@ -164,26 +165,41 @@ class PlotController: public QObject
int getCurrentIndex() const {return m_currentIndex;}
bool isZoomEnabled() const;
bool isPanEnabled() const;
bool isRangeSelectorEnabled() const;
signals:
void currentIndexChanged(int);
public slots:
void enableZoom();
void enablePan();
void enableRange();
private slots:
void tableUpdated();
void prevPlot();
void nextPlot();
void plotDataSet(int);
private:
MultiDatasetFit *owner() const {return static_cast<MultiDatasetFit*>(parent());}
void disableAllTools();
template<class Tool>
void enableTool(Tool* tool, int cursor);
bool eventFilter(QObject *widget, QEvent *evn);
void resetRange();
void zoomToRange();

/// The plot widget
QwtPlot *m_plot;

///@name Plot tools
///@{
/// The zoomer
QwtPlotZoomer *m_zoomer;
/// The panner
QwtPlotPanner *m_panner;
/// The magnifier
QwtPlotMagnifier *m_magnifier;
/// The fitting range selector
MantidWidgets::RangeSelector* m_rangeSelector;
///@}

/// The workspace table
QTableWidget *m_table;
Expand Down
116 changes: 103 additions & 13 deletions Code/Mantid/MantidQt/CustomInterfaces/src/MultiDatasetFit.cpp
Expand Up @@ -24,6 +24,7 @@
#include <qwt_plot_zoomer.h>
#include <qwt_plot_panner.h>
#include <qwt_plot_magnifier.h>
#include <qwt_scale_div.h>
#include <Poco/ActiveResult.h>

#include <vector>
Expand All @@ -32,6 +33,8 @@
namespace{
const int wsColumn = 0;
const int wsIndexColumn = 1;
QColor rangeSelectorDisabledColor(Qt::lightGray);
QColor rangeSelectorEnabledColor(Qt::blue);
}

namespace MantidQt
Expand Down Expand Up @@ -333,16 +336,17 @@ PlotController::PlotController(MultiDatasetFit *parent,
QwtPicker::DragSelection | QwtPicker::CornerToCorner, QwtPicker::AlwaysOff, plot->canvas());

m_panner = new QwtPlotPanner( plot->canvas() );
m_panner->setEnabled(false);

m_magnifier = new QwtPlotMagnifier( plot->canvas() );
m_magnifier->setEnabled( false );

auto rangeSelector = new MantidWidgets::RangeSelector(m_plot);
rangeSelector->setRange( -1e30, 1e30 );
m_rangeSelector = new MantidWidgets::RangeSelector(m_plot);
m_rangeSelector->setRange( -1e30, 1e30 );
m_rangeSelector->setMinimum(10);
m_rangeSelector->setMaximum(990);

disableAllTools();

rangeSelector->setMinimum(10);
rangeSelector->setMaximum(990);
m_plot->canvas()->installEventFilter(this);

}

Expand All @@ -351,6 +355,22 @@ PlotController::~PlotController()
m_plotData.clear();
}

bool PlotController::eventFilter(QObject *widget, QEvent *evn)
{
if ( evn->type() == QEvent::MouseButtonDblClick )
{
if ( isRangeSelectorEnabled() )
{
resetRange();
}
else if ( isZoomEnabled() )
{
zoomToRange();
}
}
return false;
}

/**
* Slot. Respond to changes in the data table.
*/
Expand Down Expand Up @@ -479,22 +499,75 @@ void PlotController::update()
plotDataSet( m_currentIndex );
}

void PlotController::enableZoom()
/**
* Reset the fitting range to the current limits on the x axis.
*/
void PlotController::resetRange()
{
m_rangeSelector->setMinimum( m_plot->axisScaleDiv(QwtPlot::xBottom)->lowerBound() );
m_rangeSelector->setMaximum( m_plot->axisScaleDiv(QwtPlot::xBottom)->upperBound() );
}

/**
* Set zooming to the current fitting range.
*/
void PlotController::zoomToRange()
{
QwtDoubleRect rect = m_zoomer->zoomRect();
rect.setX( m_rangeSelector->getMinimum() );
rect.setRight( m_rangeSelector->getMaximum() );
m_zoomer->zoom( rect );
}

/**
* Disable all plot tools. It is a helper method
* to simplify switchig between tools.
*/
void PlotController::disableAllTools()
{
m_zoomer->setEnabled(true);
m_zoomer->setEnabled(false);
m_panner->setEnabled(false);
m_magnifier->setEnabled(false);
m_plot->canvas()->setCursor(QCursor(Qt::CrossCursor));
m_rangeSelector->setEnabled(false);
m_rangeSelector->setColour(rangeSelectorDisabledColor);
}

template<class Tool>
void PlotController::enableTool(Tool* tool, int cursor)
{
disableAllTools();
tool->setEnabled(true);
m_plot->canvas()->setCursor(QCursor(static_cast<Qt::CursorShape>(cursor)));
m_plot->replot();
owner()->showPlotInfo();
}


/**
* Enable zooming tool.
*/
void PlotController::enableZoom()
{
enableTool(m_zoomer,Qt::CrossCursor);
}

/**
* Enable panning tool.
*/
void PlotController::enablePan()
{
m_zoomer->setEnabled(false);
m_panner->setEnabled(true);
enableTool(m_panner,Qt::pointingHandCursor);
m_magnifier->setEnabled(true);
m_plot->canvas()->setCursor(Qt::pointingHandCursor);
owner()->showPlotInfo();
}

/**
* Enable range selector tool.
*/
void PlotController::enableRange()
{
enableTool(m_rangeSelector,Qt::pointingHandCursor);
m_rangeSelector->setColour(rangeSelectorEnabledColor);
m_plot->replot();
}

bool PlotController::isZoomEnabled() const
Expand All @@ -507,6 +580,11 @@ bool PlotController::isPanEnabled() const
return m_panner->isEnabled();
}

bool PlotController::isRangeSelectorEnabled() const
{
return m_rangeSelector->isEnabled();
}

/*==========================================================================================*/
/* EditLocalParameterDialog */
/*==========================================================================================*/
Expand Down Expand Up @@ -622,6 +700,7 @@ void MultiDatasetFit::initLayout()
m_uiForm.plot->installEventFilter( this );
m_uiForm.dataTable->installEventFilter( this );

m_plotController->enableZoom();
showInfo( "Add some data, define fitting function" );
}

Expand All @@ -645,6 +724,13 @@ void MultiDatasetFit::createPlotToolbar()
connect(action,SIGNAL(triggered()),m_plotController,SLOT(enablePan()));
group->addAction(action);

action = new QAction(this);
action->setIcon(QIcon(":/MultiDatasetFit/icons/range.png"));
action->setCheckable(true);
action->setToolTip("Set fitting range");
connect(action,SIGNAL(triggered()),m_plotController,SLOT(enableRange()));
group->addAction(action);

toolBar->addActions(group->actions());

m_uiForm.horizontalLayout->insertWidget(3,toolBar);
Expand Down Expand Up @@ -1003,6 +1089,10 @@ void MultiDatasetFit::showPlotInfo()
{
text += "Click and drag to move. Use mouse wheel to zoom in and out.";
}
else if ( m_plotController->isRangeSelectorEnabled() )
{
text += "Drag the vertical dashed lines to adjust the fitting range.";
}

showInfo( text );
}
Expand Down

0 comments on commit 8ed05a2

Please sign in to comment.