Skip to content

Commit

Permalink
Add RangeSelector integration to PreviewPlot
Browse files Browse the repository at this point in the history
Refs #11365
  • Loading branch information
DanNixon committed Mar 17, 2015
1 parent 5994f7c commit 0dd22fa
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
#include "ui_PreviewPlot.h"

#include "WidgetDllOption.h"
#include "MantidQtMantidWidgets/RangeSelector.h"
#include "MantidQtAPI/MantidWidget.h"

#include "MantidAPI/MatrixWorkspace.h"

#include <QActionGroup>
#include <QHBoxLayout>
#include <QLabel>
#include <QMap>
#include <QMenu>

#include <qwt_plot.h>
Expand Down Expand Up @@ -81,6 +83,12 @@ namespace MantidWidgets

bool hasCurve(const QString & curveName);

RangeSelector * addRangeSelector(const QString & rsName);
RangeSelector * getRangeSelector(const QString & rsName);
void removeRangeSelector(const QString & rsName, bool del);

bool hasRangeSelector(const QString & rsName);

QString getAxisType(int axisID);

signals:
Expand Down Expand Up @@ -132,6 +140,9 @@ namespace MantidWidgets
private:
Ui::PreviewPlot m_uiForm;

/// Range selector widget for mini plot
QMap<QString, MantidQt::MantidWidgets::RangeSelector *> m_rangeSelectors;

/// Poco Observers for ADS Notifications
Poco::NObserver<PreviewPlot, Mantid::API::WorkspacePreDeleteNotification> m_removeObserver;
Poco::NObserver<PreviewPlot, Mantid::API::WorkspaceAfterReplaceNotification> m_replaceObserver;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#define MANTIDQT_MANTIDWIDGET_POSHPLOTTING_H

#include "WidgetDllOption.h"
#include "PreviewPlot.h"

#include <qwt_plot_picker.h>
#include <qwt_plot.h>
Expand All @@ -14,6 +13,8 @@ namespace MantidQt
{
namespace MantidWidgets
{
class PreviewPlot;

/**
* Allows for simpler (in a way) selection of a range on a QwtPlot in MantidQt.
* @author Michael Whitty, RAL ISIS
Expand All @@ -35,6 +36,8 @@ namespace MantidWidgets
double getMinimum() { return m_min; } ///< Returns current min value
double getMaximum() { return m_max; } ///< Reutnrs current max value

SelectType getType() { return m_type; }

signals:
void minValueChanged(double);
void maxValueChanged(double);
Expand Down
73 changes: 73 additions & 0 deletions Code/Mantid/MantidQt/MantidWidgets/src/PreviewPlot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,68 @@ bool PreviewPlot::hasCurve(const QString & curveName)
}


/**
* Attaches a RangeSelector to the plot and stores it.
*
* @param rsName Name of range selector
* @return RangeSelector object
*/
RangeSelector * PreviewPlot::addRangeSelector(const QString & rsName)
{
if(hasRangeSelector(rsName))
return NULL;

m_rangeSelectors[rsName] = new MantidWidgets::RangeSelector(m_uiForm.plot);

return m_rangeSelectors[rsName];
}


/**
* Gets a RangeSelector.
*
* @param rsName Name of range selector
* @return RangeSelector object
*/
RangeSelector * PreviewPlot::getRangeSelector(const QString & rsName)
{
if(!hasRangeSelector(rsName))
return NULL;

return m_rangeSelectors[rsName];
}


/**
* Removes a RangeSelector from the plot.
*
* @param rsName Name of range selector
* @param del If the object should be deleted
*/
void PreviewPlot::removeRangeSelector(const QString & rsName, bool del = true)
{
if(!hasRangeSelector(rsName))
return;

if(del)
delete m_rangeSelectors[rsName];

m_rangeSelectors.remove(rsName);
}


/**
* Checks to see if a range selector with a given name is on the plot.
*
* @param rsName Name of range selector
* @return True if the plot has a range selector with the given name
*/
bool PreviewPlot::hasRangeSelector(const QString & rsName)
{
return m_rangeSelectors.contains(rsName);
}


/**
* Shows or hides the plot legend.
*
Expand Down Expand Up @@ -725,6 +787,17 @@ void PreviewPlot::handleAxisTypeSelect()

emit axisScaleChanged();

// Hide range selectors on X axis when X axis scale is X^2
bool xIsSquared = xAxisType == "Squared";
for(auto it = m_rangeSelectors.begin(); it != m_rangeSelectors.end(); ++it)
{
RangeSelector * rs = it.value();
RangeSelector::SelectType type = rs->getType();

if(type == RangeSelector:: XMINMAX || type == RangeSelector::XSINGLE)
rs->setVisible(!xIsSquared);
}

// Update the plot
emit needToHardReplot();
}
2 changes: 2 additions & 0 deletions Code/Mantid/MantidQt/MantidWidgets/src/RangeSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <QEvent>
#include <QMouseEvent>

#include "MantidQtMantidWidgets/PreviewPlot.h"

using namespace MantidQt::MantidWidgets;

RangeSelector::RangeSelector(QwtPlot* plot, SelectType type, bool visible, bool infoOnly)
Expand Down

0 comments on commit 0dd22fa

Please sign in to comment.