diff --git a/qt/scientific_interfaces/Indirect/IndirectSqw.cpp b/qt/scientific_interfaces/Indirect/IndirectSqw.cpp index 1c4c0fdd54181bc4f3dd6793dbc25de7d7c94c31..2bdd834593ff452155babd15fe0bdc4188ba56aa 100644 --- a/qt/scientific_interfaces/Indirect/IndirectSqw.cpp +++ b/qt/scientific_interfaces/Indirect/IndirectSqw.cpp @@ -15,6 +15,26 @@ using namespace Mantid::API; using MantidQt::API::BatchAlgorithmRunner; +namespace { + +MatrixWorkspace_sptr getADSMatrixWorkspace(std::string const &workspaceName) { + return AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>( + workspaceName); +} + +void convertToSpectrumAxis(std::string const &inputName, + std::string const &outputName) { + auto converter = AlgorithmManager::Instance().create("ConvertSpectrumAxis"); + converter->initialize(); + converter->setProperty("InputWorkspace", inputName); + converter->setProperty("OutputWorkspace", outputName); + converter->setProperty("Target", "ElasticQ"); + converter->setProperty("EMode", "Indirect"); + converter->execute(); +} + +} // namespace + namespace MantidQt { namespace CustomInterfaces { //---------------------------------------------------------------------------------------------- @@ -24,8 +44,8 @@ IndirectSqw::IndirectSqw(IndirectDataReduction *idrUI, QWidget *parent) : IndirectDataReductionTab(idrUI, parent) { m_uiForm.setupUi(parent); - connect(m_uiForm.dsSampleInput, SIGNAL(loadClicked()), this, - SLOT(plotContour())); + connect(m_uiForm.dsSampleInput, SIGNAL(dataReady(const QString &)), this, + SLOT(plotRqwContour())); connect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, SLOT(sqwAlgDone(bool))); @@ -42,17 +62,18 @@ IndirectSqw::IndirectSqw(IndirectDataReduction *idrUI, QWidget *parent) this, SLOT(updateRunButton(bool, std::string const &, QString const &, QString const &))); + + m_uiForm.rqwPlot2D->setColourBarVisible(false); + m_uiForm.rqwPlot2D->setXAxisLabel("Energy (meV)"); + m_uiForm.rqwPlot2D->setYAxisLabel("Q (A-1)"); } -//---------------------------------------------------------------------------------------------- -/** Destructor - */ IndirectSqw::~IndirectSqw() {} void IndirectSqw::setup() {} bool IndirectSqw::validate() { - double tolerance = 1e-10; + double const tolerance = 1e-10; UserInputValidator uiv; // Validate the data selector @@ -67,7 +88,7 @@ bool IndirectSqw::validate() { uiv.checkBins(m_uiForm.spELow->value(), m_uiForm.spEWidth->value(), m_uiForm.spEHigh->value(), tolerance); - QString errorMessage = uiv.generateErrorMessage(); + auto const errorMessage = uiv.generateErrorMessage(); // Show an error message if needed if (!errorMessage.isEmpty()) @@ -77,25 +98,23 @@ bool IndirectSqw::validate() { } void IndirectSqw::run() { - QString sampleWsName = m_uiForm.dsSampleInput->getCurrentDataName(); - QString sqwWsName = sampleWsName.left(sampleWsName.length() - 4) + "_sqw"; - QString eRebinWsName = sampleWsName.left(sampleWsName.length() - 4) + "_r"; + auto const sampleWsName = m_uiForm.dsSampleInput->getCurrentDataName(); + auto const sqwWsName = sampleWsName.left(sampleWsName.length() - 4) + "_sqw"; + auto const eRebinWsName = sampleWsName.left(sampleWsName.length() - 4) + "_r"; - QString rebinString = m_uiForm.spQLow->text() + "," + - m_uiForm.spQWidth->text() + "," + - m_uiForm.spQHigh->text(); + auto const rebinString = m_uiForm.spQLow->text() + "," + + m_uiForm.spQWidth->text() + "," + + m_uiForm.spQHigh->text(); // Rebin in energy - bool rebinInEnergy = m_uiForm.ckRebinInEnergy->isChecked(); + bool const rebinInEnergy = m_uiForm.ckRebinInEnergy->isChecked(); if (rebinInEnergy) { - QString eRebinString = m_uiForm.spELow->text() + "," + - m_uiForm.spEWidth->text() + "," + - m_uiForm.spEHigh->text(); + auto const eRebinString = m_uiForm.spELow->text() + "," + + m_uiForm.spEWidth->text() + "," + + m_uiForm.spEHigh->text(); - IAlgorithm_sptr energyRebinAlg = - AlgorithmManager::Instance().create("Rebin"); + auto energyRebinAlg = AlgorithmManager::Instance().create("Rebin"); energyRebinAlg->initialize(); - energyRebinAlg->setProperty("InputWorkspace", sampleWsName.toStdString()); energyRebinAlg->setProperty("OutputWorkspace", eRebinWsName.toStdString()); energyRebinAlg->setProperty("Params", eRebinString.toStdString()); @@ -103,9 +122,9 @@ void IndirectSqw::run() { m_batchAlgoRunner->addAlgorithm(energyRebinAlg); } - QString eFixed = getInstrumentDetails()["Efixed"]; + auto const eFixed = getInstrumentDetails()["Efixed"]; - IAlgorithm_sptr sqwAlg = AlgorithmManager::Instance().create("SofQW"); + auto sqwAlg = AlgorithmManager::Instance().create("SofQW"); sqwAlg->initialize(); BatchAlgorithmRunner::AlgorithmRuntimeProps sqwInputProps; @@ -124,10 +143,8 @@ void IndirectSqw::run() { m_batchAlgoRunner->addAlgorithm(sqwAlg, sqwInputProps); // Add sample log for S(Q, w) algorithm used - IAlgorithm_sptr sampleLogAlg = - AlgorithmManager::Instance().create("AddSampleLog"); + auto sampleLogAlg = AlgorithmManager::Instance().create("AddSampleLog"); sampleLogAlg->initialize(); - sampleLogAlg->setProperty("LogName", "rebin_type"); sampleLogAlg->setProperty("LogType", "String"); sampleLogAlg->setProperty("LogText", "NormalisedPolygon"); @@ -143,13 +160,8 @@ void IndirectSqw::run() { m_batchAlgoRunner->executeBatch(); } -MatrixWorkspace_const_sptr -IndirectSqw::getADSWorkspace(std::string const &name) const { - return AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(name); -} - std::size_t IndirectSqw::getOutWsNumberOfSpectra() const { - return getADSWorkspace(m_pythonExportWsName)->getNumberHistograms(); + return getADSMatrixWorkspace(m_pythonExportWsName)->getNumberHistograms(); } /** @@ -177,27 +189,18 @@ void IndirectSqw::setPlotSpectrumIndexMax(int maximum) { * * Creates a colour 2D plot of the data */ -void IndirectSqw::plotContour() { +void IndirectSqw::plotRqwContour() { if (m_uiForm.dsSampleInput->isValid()) { - QString sampleWsName = m_uiForm.dsSampleInput->getCurrentDataName(); + auto const sampleName = + m_uiForm.dsSampleInput->getCurrentDataName().toStdString(); + auto const outputName = + sampleName.substr(0, sampleName.size() - 4) + "_rqw"; - QString convertedWsName = - sampleWsName.left(sampleWsName.length() - 4) + "_rqw"; + convertToSpectrumAxis(sampleName, outputName); - IAlgorithm_sptr convertSpecAlg = - AlgorithmManager::Instance().create("ConvertSpectrumAxis"); - convertSpecAlg->initialize(); - - convertSpecAlg->setProperty("InputWorkspace", sampleWsName.toStdString()); - convertSpecAlg->setProperty("OutputWorkspace", - convertedWsName.toStdString()); - convertSpecAlg->setProperty("Target", "ElasticQ"); - convertSpecAlg->setProperty("EMode", "Indirect"); - - convertSpecAlg->execute(); - - QString pyInput = "plot2D('" + convertedWsName + "')\n"; - m_pythonRunner.runPythonCode(pyInput); + auto const rqwWorkspace = getADSMatrixWorkspace(outputName); + if (rqwWorkspace) + m_uiForm.rqwPlot2D->setWorkspace(rqwWorkspace); } else { emit showMessageBox("Invalid filename."); } diff --git a/qt/scientific_interfaces/Indirect/IndirectSqw.h b/qt/scientific_interfaces/Indirect/IndirectSqw.h index 14a5126f3e80ac8f2458d7e19da94061a2fdee4c..6e7decdd617390cf5dec85eab1dc7f58d224a9e5 100644 --- a/qt/scientific_interfaces/Indirect/IndirectSqw.h +++ b/qt/scientific_interfaces/Indirect/IndirectSqw.h @@ -31,7 +31,7 @@ public: bool validate() override; private slots: - void plotContour(); + void plotRqwContour(); void sqwAlgDone(bool error); void runClicked(); diff --git a/qt/scientific_interfaces/Indirect/IndirectSqw.ui b/qt/scientific_interfaces/Indirect/IndirectSqw.ui index 64fdd7dc5efffb5a1ce49d3d329edc23f6c75ce7..a95068485584d1262129a90f13f2c45fed5e9307 100644 --- a/qt/scientific_interfaces/Indirect/IndirectSqw.ui +++ b/qt/scientific_interfaces/Indirect/IndirectSqw.ui @@ -6,8 +6,8 @@ <rect> <x>0</x> <y>0</y> - <width>601</width> - <height>303</height> + <width>602</width> + <height>475</height> </rect> </property> <property name="minimumSize"> @@ -43,9 +43,6 @@ <property name="autoLoad" stdset="0"> <bool>true</bool> </property> - <property name="loadLabelText" stdset="0"> - <string>Plot Input</string> - </property> <property name="workspaceSuffixes" stdset="0"> <stringlist> <string>_red</string> @@ -57,7 +54,7 @@ </stringlist> </property> <property name="showLoad" stdset="0"> - <bool>true</bool> + <bool>false</bool> </property> </widget> </item> @@ -69,283 +66,336 @@ <property name="title"> <string>Options</string> </property> - <layout class="QVBoxLayout" name="verticalLayout_7"> + <layout class="QHBoxLayout" name="horizontalLayout_3"> + <property name="topMargin"> + <number>0</number> + </property> + <property name="bottomMargin"> + <number>0</number> + </property> <item> - <layout class="QGridLayout" name="loOptions" columnstretch="0,0,0,0,0,0"> - <item row="1" column="4"> - <widget class="QDoubleSpinBox" name="spELow"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="maximumSize"> - <size> - <width>200</width> - <height>16777215</height> - </size> - </property> - <property name="decimals"> - <number>5</number> - </property> - <property name="minimum"> - <double>-1000.000000000000000</double> - </property> - <property name="maximum"> - <double>1000.000000000000000</double> - </property> - <property name="singleStep"> - <double>0.100000000000000</double> - </property> - </widget> - </item> - <item row="2" column="3"> - <widget class="QLabel" name="lbEWidth"> - <property name="enabled"> - <bool>true</bool> - </property> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="minimumSize"> - <size> - <width>43</width> - <height>0</height> - </size> - </property> - <property name="text"> - <string>E Width:</string> - </property> - </widget> - </item> - <item row="2" column="0"> - <widget class="QLabel" name="lbQWidth"> - <property name="minimumSize"> - <size> - <width>43</width> - <height>0</height> - </size> - </property> - <property name="text"> - <string>Q Width:</string> - </property> - </widget> - </item> - <item row="3" column="4"> - <widget class="QDoubleSpinBox" name="spEHigh"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="maximumSize"> - <size> - <width>200</width> - <height>16777215</height> - </size> - </property> - <property name="decimals"> - <number>5</number> - </property> - <property name="minimum"> - <double>-1000.000000000000000</double> - </property> - <property name="maximum"> - <double>1000.000000000000000</double> - </property> - <property name="singleStep"> - <double>0.100000000000000</double> - </property> - </widget> - </item> - <item row="3" column="3"> - <widget class="QLabel" name="lbEHigh"> - <property name="enabled"> - <bool>true</bool> - </property> - <property name="minimumSize"> - <size> - <width>43</width> - <height>0</height> - </size> - </property> - <property name="text"> - <string>E High:</string> - </property> - </widget> - </item> - <item row="1" column="0"> - <widget class="QLabel" name="lbQLow"> - <property name="minimumSize"> - <size> - <width>43</width> - <height>0</height> - </size> - </property> - <property name="text"> - <string>Q Low:</string> - </property> - </widget> - </item> - <item row="3" column="0"> - <widget class="QLabel" name="lbQHigh"> - <property name="minimumSize"> - <size> - <width>43</width> - <height>0</height> - </size> - </property> - <property name="text"> - <string>Q High:</string> - </property> + <layout class="QGridLayout" name="loOptions" columnstretch="0"> + <property name="spacing"> + <number>6</number> + </property> + <item row="5" column="0"> + <widget class="QFrame" name="fEValues"> + <layout class="QGridLayout" name="gridLayout_2"> + <item row="0" column="0" rowspan="2" colspan="2"> + <widget class="QCheckBox" name="ckRebinInEnergy"> + <property name="text"> + <string>Rebin in Energy</string> + </property> + </widget> + </item> + <item row="3" column="1"> + <widget class="QDoubleSpinBox" name="spEWidth"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="maximumSize"> + <size> + <width>200</width> + <height>16777215</height> + </size> + </property> + <property name="decimals"> + <number>5</number> + </property> + <property name="minimum"> + <double>0.000000000000000</double> + </property> + <property name="maximum"> + <double>1000.000000000000000</double> + </property> + <property name="singleStep"> + <double>0.010000000000000</double> + </property> + </widget> + </item> + <item row="3" column="0"> + <widget class="QLabel" name="lbEWidth"> + <property name="enabled"> + <bool>true</bool> + </property> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>43</width> + <height>0</height> + </size> + </property> + <property name="text"> + <string>E Width:</string> + </property> + </widget> + </item> + <item row="2" column="1"> + <widget class="QDoubleSpinBox" name="spELow"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="maximumSize"> + <size> + <width>200</width> + <height>16777215</height> + </size> + </property> + <property name="decimals"> + <number>5</number> + </property> + <property name="minimum"> + <double>-1000.000000000000000</double> + </property> + <property name="maximum"> + <double>1000.000000000000000</double> + </property> + <property name="singleStep"> + <double>0.100000000000000</double> + </property> + </widget> + </item> + <item row="2" column="0"> + <widget class="QLabel" name="lbELow"> + <property name="enabled"> + <bool>true</bool> + </property> + <property name="minimumSize"> + <size> + <width>43</width> + <height>0</height> + </size> + </property> + <property name="text"> + <string>E Low:</string> + </property> + </widget> + </item> + <item row="4" column="0"> + <widget class="QLabel" name="lbEHigh"> + <property name="enabled"> + <bool>true</bool> + </property> + <property name="minimumSize"> + <size> + <width>43</width> + <height>0</height> + </size> + </property> + <property name="text"> + <string>E High:</string> + </property> + </widget> + </item> + <item row="4" column="1"> + <widget class="QDoubleSpinBox" name="spEHigh"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="maximumSize"> + <size> + <width>200</width> + <height>16777215</height> + </size> + </property> + <property name="decimals"> + <number>5</number> + </property> + <property name="minimum"> + <double>-1000.000000000000000</double> + </property> + <property name="maximum"> + <double>1000.000000000000000</double> + </property> + <property name="singleStep"> + <double>0.100000000000000</double> + </property> + </widget> + </item> + </layout> </widget> </item> - <item row="2" column="4"> - <widget class="QDoubleSpinBox" name="spEWidth"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> + <item row="6" column="0"> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> </property> - <property name="maximumSize"> + <property name="sizeHint" stdset="0"> <size> - <width>200</width> - <height>16777215</height> + <width>20</width> + <height>40</height> </size> </property> - <property name="decimals"> - <number>5</number> - </property> - <property name="minimum"> - <double>0.000000000000000</double> - </property> - <property name="maximum"> - <double>1000.000000000000000</double> - </property> - <property name="singleStep"> - <double>0.010000000000000</double> - </property> - </widget> - </item> - <item row="0" column="3" colspan="3"> - <widget class="QCheckBox" name="ckRebinInEnergy"> - <property name="text"> - <string>Rebin in Energy</string> - </property> - </widget> + </spacer> </item> - <item row="1" column="3"> - <widget class="QLabel" name="lbELow"> - <property name="enabled"> - <bool>true</bool> + <item row="0" column="0"> + <spacer name="verticalSpacer_3"> + <property name="orientation"> + <enum>Qt::Vertical</enum> </property> - <property name="minimumSize"> + <property name="sizeHint" stdset="0"> <size> - <width>43</width> - <height>0</height> + <width>20</width> + <height>40</height> </size> </property> - <property name="text"> - <string>E Low:</string> - </property> - </widget> - </item> - <item row="1" column="1"> - <widget class="QDoubleSpinBox" name="spQLow"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Minimum" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="decimals"> - <number>5</number> - </property> - <property name="minimum"> - <double>-1000.000000000000000</double> - </property> - <property name="maximum"> - <double>1000.000000000000000</double> - </property> - <property name="singleStep"> - <double>0.100000000000000</double> - </property> - </widget> - </item> - <item row="2" column="1"> - <widget class="QDoubleSpinBox" name="spQWidth"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="decimals"> - <number>5</number> - </property> - <property name="minimum"> - <double>0.000000000000000</double> - </property> - <property name="maximum"> - <double>1000.000000000000000</double> - </property> - <property name="singleStep"> - <double>0.100000000000000</double> - </property> - </widget> - </item> - <item row="3" column="1"> - <widget class="QDoubleSpinBox" name="spQHigh"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="decimals"> - <number>5</number> - </property> - <property name="minimum"> - <double>-1000.000000000000000</double> - </property> - <property name="maximum"> - <double>1000.000000000000000</double> - </property> - <property name="singleStep"> - <double>0.100000000000000</double> - </property> - </widget> + </spacer> </item> - <item row="0" column="2"> - <spacer name="horizontalSpacer"> + <item row="4" column="0"> + <spacer name="verticalSpacer_2"> <property name="orientation"> - <enum>Qt::Horizontal</enum> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeType"> + <enum>QSizePolicy::Fixed</enum> </property> <property name="sizeHint" stdset="0"> <size> - <width>40</width> + <width>20</width> <height>20</height> </size> </property> </spacer> </item> + <item row="1" column="0"> + <widget class="QFrame" name="fQValues"> + <layout class="QGridLayout" name="gridLayout"> + <item row="1" column="0"> + <widget class="QLabel" name="lbQWidth"> + <property name="minimumSize"> + <size> + <width>43</width> + <height>0</height> + </size> + </property> + <property name="text"> + <string>Q Width:</string> + </property> + </widget> + </item> + <item row="0" column="0"> + <widget class="QLabel" name="lbQLow"> + <property name="minimumSize"> + <size> + <width>43</width> + <height>0</height> + </size> + </property> + <property name="text"> + <string>Q Low:</string> + </property> + </widget> + </item> + <item row="2" column="0"> + <widget class="QLabel" name="lbQHigh"> + <property name="minimumSize"> + <size> + <width>43</width> + <height>0</height> + </size> + </property> + <property name="text"> + <string>Q High:</string> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QDoubleSpinBox" name="spQWidth"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="decimals"> + <number>5</number> + </property> + <property name="minimum"> + <double>0.000000000000000</double> + </property> + <property name="maximum"> + <double>1000.000000000000000</double> + </property> + <property name="singleStep"> + <double>0.100000000000000</double> + </property> + </widget> + </item> + <item row="2" column="1"> + <widget class="QDoubleSpinBox" name="spQHigh"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="decimals"> + <number>5</number> + </property> + <property name="minimum"> + <double>-1000.000000000000000</double> + </property> + <property name="maximum"> + <double>1000.000000000000000</double> + </property> + <property name="singleStep"> + <double>0.100000000000000</double> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QDoubleSpinBox" name="spQLow"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Minimum" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="decimals"> + <number>5</number> + </property> + <property name="minimum"> + <double>-1000.000000000000000</double> + </property> + <property name="maximum"> + <double>1000.000000000000000</double> + </property> + <property name="singleStep"> + <double>0.100000000000000</double> + </property> + </widget> + </item> + </layout> + </widget> + </item> </layout> </item> + <item> + <widget class="MantidQt::MantidWidgets::ContourPreviewPlot" name="rqwPlot2D" native="true"/> + </item> </layout> </widget> </item> @@ -507,15 +557,14 @@ <extends>QWidget</extends> <header>MantidQtWidgets/Common/DataSelector.h</header> </customwidget> + <customwidget> + <class>MantidQt::MantidWidgets::ContourPreviewPlot</class> + <extends>QWidget</extends> + <header>MantidQtWidgets/LegacyQwt/ContourPreviewPlot.h</header> + <container>1</container> + </customwidget> </customwidgets> <tabstops> - <tabstop>spQLow</tabstop> - <tabstop>spQWidth</tabstop> - <tabstop>spQHigh</tabstop> - <tabstop>ckRebinInEnergy</tabstop> - <tabstop>spELow</tabstop> - <tabstop>spEWidth</tabstop> - <tabstop>spEHigh</tabstop> <tabstop>pbSave</tabstop> </tabstops> <resources/> diff --git a/qt/widgets/legacyqwt/CMakeLists.txt b/qt/widgets/legacyqwt/CMakeLists.txt index 3cac2c5bac88a1304ebed03158a001878e9b7e92..729764a5edf9f233f7c1c0bb95858e90fe68301b 100644 --- a/qt/widgets/legacyqwt/CMakeLists.txt +++ b/qt/widgets/legacyqwt/CMakeLists.txt @@ -1,4 +1,5 @@ set ( SRC_FILES + src/ContourPreviewPlot.cpp src/DraggableColorBarWidget.cpp src/MantidColorMap.cpp src/MantidQwtIMDWorkspaceData.cpp @@ -22,6 +23,7 @@ ) set ( MOC_FILES + inc/MantidQtWidgets/LegacyQwt/ContourPreviewPlot.h inc/MantidQtWidgets/LegacyQwt/DraggableColorBarWidget.h inc/MantidQtWidgets/LegacyQwt/ColorBarWidget.h inc/MantidQtWidgets/LegacyQwt/MWView.h @@ -34,6 +36,7 @@ set ( MOC_FILES # Include files aren't required, but this makes them appear in Visual Studio set ( INC_FILES + inc/MantidQtWidgets/LegacyQwt/ContourPreviewPlot.h inc/MantidQtWidgets/LegacyQwt/MantidQwtWorkspaceData.h inc/MantidQtWidgets/LegacyQwt/QwtRasterDataMD.h inc/MantidQtWidgets/LegacyQwt/QwtRasterDataMDNonOrthogonal.h @@ -52,6 +55,7 @@ set ( INC_FILES set ( UI_FILES inc/MantidQtWidgets/LegacyQwt/ColorBarWidget.ui + inc/MantidQtWidgets/LegacyQwt/ContourPreviewPlot.ui inc/MantidQtWidgets/LegacyQwt/DisplayCurveFit.ui inc/MantidQtWidgets/LegacyQwt/MWView.ui inc/MantidQtWidgets/LegacyQwt/PreviewPlot.ui @@ -91,6 +95,7 @@ mtd_add_qt_library (TARGET_NAME MantidQtWidgetsLegacyQwt # Testing ########################################################################### set( TEST_FILES + test/ContourPreviewPlotTest.h test/MantidColorMapTest.h test/QwtWorkspaceBinDataTest.h test/QwtWorkspaceSpectrumDataTest.h diff --git a/qt/widgets/legacyqwt/inc/MantidQtWidgets/LegacyQwt/ContourPreviewPlot.h b/qt/widgets/legacyqwt/inc/MantidQtWidgets/LegacyQwt/ContourPreviewPlot.h new file mode 100644 index 0000000000000000000000000000000000000000..bf062458cf3560cc08115d1c10e56aad4ebbc9da --- /dev/null +++ b/qt/widgets/legacyqwt/inc/MantidQtWidgets/LegacyQwt/ContourPreviewPlot.h @@ -0,0 +1,121 @@ +// Mantid Repository : https://github.com/mantidproject/mantid +// +// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI, +// NScD Oak Ridge National Laboratory, European Spallation Source +// & Institut Laue - Langevin +// SPDX - License - Identifier: GPL - 3.0 + +#ifndef MANTID_MANTIDWIDGETS_CONTOURPREVIEWPLOT_H_ +#define MANTID_MANTIDWIDGETS_CONTOURPREVIEWPLOT_H_ + +#include "ui_ContourPreviewPlot.h" + +#include "DllOption.h" +#include "MantidAPI/IMDWorkspace.h" +#include "MantidAPI/MatrixWorkspace_fwd.h" +#include "MantidGeometry/MDGeometry/MDHistoDimension.h" +#include "MantidQtWidgets/Common/MdSettings.h" +#include "MantidQtWidgets/Common/WorkspaceObserver.h" + +#include <qwt_plot_spectrogram.h> + +#include <QSettings> +#include <QWidget> + +namespace Mantid { +namespace API { +class MWDimension; +} +} // namespace Mantid + +namespace MantidQt { +namespace API { +class QwtRasterDataMD; +class MdSettings; +} // namespace API + +namespace MantidWidgets { +class ColorBarWidget; +class SafeQwtPlot; + +using MWDimension_sptr = boost::shared_ptr<Mantid::API::MWDimension>; +using MWDimension_const_sptr = + boost::shared_ptr<Mantid::API::MWDimension const>; +using DimensionRange = std::pair<Mantid::coord_t, Mantid::coord_t>; + +class EXPORT_OPT_MANTIDQT_LEGACYQWT ContourPreviewPlot + : public QWidget, + public MantidQt::API::WorkspaceObserver { + Q_OBJECT + +public: + ContourPreviewPlot(QWidget *parent = nullptr); + ~ContourPreviewPlot() override; + + Mantid::API::MatrixWorkspace_sptr getActiveWorkspace() const; + void setWorkspace(Mantid::API::MatrixWorkspace_sptr const workspace); + SafeQwtPlot *getPlot2D(); + + void setPlotVisible(bool const &visible); + void setColourBarVisible(bool const &visible); + + bool isPlotVisible() const; + bool isColourBarVisible() const; + + void setXAxisLabel(QString const &label); + void setYAxisLabel(QString const &label); + +protected: + void preDeleteHandle( + std::string const &workspaceName, + boost::shared_ptr<Mantid::API::Workspace> const workspace) override; + +private slots: + void handleColourRangeChanged(); + void handleLoadColourMap(); + void handleSetTransparentZeros(bool const &transparent); + +private: + void setupColourBarAndPlot(); + QString colourMapFileName(QString const &filename); + void loadSettings(); + void setCurrentColourMapFile(QSettings const &settings); + void setCurrentColourMapFile(QString const &file); + void saveSettings(); + + void loadColourMap(QString filename = QString()); + void updateDisplay(); + + void checkRangeLimits() const; + void checkForInfiniteLimits(DimensionRange const &range, + std::size_t const &index, + std::ostringstream &message) const; + DimensionRange dimensionRange(std::size_t const &index) const; + Mantid::coord_t dimensionMinimum(std::size_t const &index) const; + Mantid::coord_t dimensionMaximum(std::size_t const &index) const; + void findFullRange(); + + void setVectorDimensions(); + void clearPlot(); + + Ui::ContourPreviewPlot m_uiForm; + /// Spectrogram plot of ContourPreviewPlot + std::unique_ptr<QwtPlotSpectrogram> m_spectrogram; + /// Data presenter + std::unique_ptr<API::QwtRasterDataMD> m_data; + /// File of the last loaded colour map. + QString m_currentColourMapFile; + /// Md Settings for colour maps + boost::shared_ptr<MantidQt::API::MdSettings> m_mdSettings; + /// Workspace being shown + Mantid::API::MatrixWorkspace_sptr m_workspace; + /// The calculated range of values in the full data set + QwtDoubleInterval m_colourRangeFull; + Mantid::API::MDNormalization m_normalization; + /// Vector of the dimensions to show. + std::vector<Mantid::Geometry::MDHistoDimension_sptr> m_dimensions; +}; + +} // namespace MantidWidgets +} // namespace MantidQt + +#endif /* MANTID_MANTIDWIDGETS_CONTOURPREVIEWPLOT_H_ */ diff --git a/qt/widgets/legacyqwt/inc/MantidQtWidgets/LegacyQwt/ContourPreviewPlot.ui b/qt/widgets/legacyqwt/inc/MantidQtWidgets/LegacyQwt/ContourPreviewPlot.ui new file mode 100644 index 0000000000000000000000000000000000000000..cfac215cf6c33d5a7eeaf9309f080f79b675e89a --- /dev/null +++ b/qt/widgets/legacyqwt/inc/MantidQtWidgets/LegacyQwt/ContourPreviewPlot.ui @@ -0,0 +1,128 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>ContourPreviewPlot</class> + <widget class="QWidget" name="ContourPreviewPlot"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>569</width> + <height>470</height> + </rect> + </property> + <property name="windowTitle"> + <string>Form</string> + </property> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="1"> + <layout class="QGridLayout" name="gridLayout_2"> + <item row="0" column="2"> + <widget class="MantidQt::MantidWidgets::ColorBarWidget" name="colourBar" native="true"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Expanding"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="MantidQt::MantidWidgets::SafeQwtPlot" name="plot2D"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Expanding" vsizetype="Expanding"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + </item> + <item row="0" column="0"> + <widget class="QLabel" name="lbYAxis"> + <property name="font"> + <font> + <pointsize>8</pointsize> + </font> + </property> + <property name="text"> + <string/> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QFrame" name="fXAxis"> + <layout class="QHBoxLayout" name="horizontalLayout"> + <property name="spacing"> + <number>0</number> + </property> + <property name="leftMargin"> + <number>0</number> + </property> + <property name="topMargin"> + <number>0</number> + </property> + <property name="rightMargin"> + <number>0</number> + </property> + <property name="bottomMargin"> + <number>0</number> + </property> + <item> + <spacer name="horizontalSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeType"> + <enum>QSizePolicy::Fixed</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>30</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QLabel" name="lbXAxis"> + <property name="font"> + <font> + <pointsize>8</pointsize> + </font> + </property> + <property name="text"> + <string/> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + </widget> + </item> + </layout> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + <customwidgets> + <customwidget> + <class>QwtPlot</class> + <extends>QFrame</extends> + <header>qwt_plot.h</header> + <container>1</container> + </customwidget> + <customwidget> + <class>MantidQt::MantidWidgets::ColorBarWidget</class> + <extends>QWidget</extends> + <header>MantidQtWidgets/LegacyQwt/ColorBarWidget.h</header> + </customwidget> + <customwidget> + <class>MantidQt::MantidWidgets::SafeQwtPlot</class> + <extends>QwtPlot</extends> + <header>MantidQtWidgets/LegacyQwt/SafeQwtPlot.h</header> + <container>1</container> + </customwidget> + </customwidgets> + <resources/> + <connections/> +</ui> diff --git a/qt/widgets/legacyqwt/src/ContourPreviewPlot.cpp b/qt/widgets/legacyqwt/src/ContourPreviewPlot.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5e5d1003676dba643c0e007118c6ebac3f075d3b --- /dev/null +++ b/qt/widgets/legacyqwt/src/ContourPreviewPlot.cpp @@ -0,0 +1,403 @@ +// Mantid Repository : https://github.com/mantidproject/mantid +// +// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI, +// NScD Oak Ridge National Laboratory, European Spallation Source +// & Institut Laue - Langevin +// SPDX - License - Identifier: GPL - 3.0 + +#include "MantidQtWidgets/LegacyQwt/ContourPreviewPlot.h" + +#include "MantidAPI/MatrixWorkspace.h" +#include "MantidGeometry/MDGeometry/IMDDimension.h" +#include "MantidGeometry/MDGeometry/MDHistoDimension.h" +#include "MantidGeometry/MDGeometry/MDTypes.h" +#include "MantidKernel/ReadLock.h" +#include "MantidQtWidgets/LegacyQwt/MantidColorMap.h" +#include "MantidQtWidgets/LegacyQwt/QwtRasterDataMD.h" +#include "MantidQtWidgets/LegacyQwt/SignalRange.h" + +#include <boost/pointer_cast.hpp> +#include <boost/shared_ptr.hpp> +#include <qwt_color_map.h> +#include <qwt_double_rect.h> + +#include <cmath> +#include <sstream> + +using namespace Mantid::API; +using namespace Mantid::Geometry; +using namespace MantidQt::API; + +namespace { +Mantid::Kernel::Logger g_log("ContourPreviewPlot"); + +MatrixWorkspace_sptr +convertToMatrixWorkspace(boost::shared_ptr<Workspace> const workspace) { + return boost::dynamic_pointer_cast<MatrixWorkspace>(workspace); +} + +template <typename T> +auto getValueFromSettings(QSettings const &settings, QString const &key, + T const &defaultValue) { + return settings.value(key, defaultValue); +} + +QString getColourMapFile(QSettings const &settings) { + return getValueFromSettings(settings, "ColourmapFile", "").toString(); +} + +int getScaleType(QSettings const &settings) { + int scaleType = getValueFromSettings(settings, "ColourScale", -1).toInt(); + if (scaleType == -1) + scaleType = getValueFromSettings(settings, "LogColourScale", 0).toInt(); + return scaleType; +} + +double getExponent(QSettings const &settings) { + return getValueFromSettings(settings, "PowerScaleExponent", 2.0).toDouble(); +} + +bool transparentZeros(QSettings const &settings) { + return getValueFromSettings(settings, "TransparentZeros", 1).toInt(); +} + +} // namespace + +namespace MantidQt { +namespace MantidWidgets { + +ContourPreviewPlot::ContourPreviewPlot(QWidget *parent) + : QWidget(parent), WorkspaceObserver(), + m_mdSettings(boost::make_shared<MdSettings>()), m_workspace(), + m_dimensions() { + this->observePreDelete(true); + m_spectrogram = std::make_unique<QwtPlotSpectrogram>(); + m_data = std::make_unique<QwtRasterDataMD>(); + m_normalization = NoNormalization; + m_uiForm.setupUi(this); + + QObject::connect(m_uiForm.colourBar, + SIGNAL(changedColorRange(double, double, bool)), this, + SLOT(handleColourRangeChanged())); + QObject::connect(m_uiForm.colourBar, SIGNAL(colorBarDoubleClicked()), this, + SLOT(handleLoadColourMap())); + + this->setupColourBarAndPlot(); + this->loadSettings(); + this->updateDisplay(); +} + +ContourPreviewPlot::~ContourPreviewPlot() { + this->observePreDelete(false); // Disconnect notifications + saveSettings(); + m_data.reset(); + m_spectrogram.reset(); +} + +MatrixWorkspace_sptr ContourPreviewPlot::getActiveWorkspace() const { + return m_workspace; +} + +/** + * Initialize objects after loading the workspace + */ +void ContourPreviewPlot::setWorkspace(MatrixWorkspace_sptr const workspace) { + m_workspace = workspace; + this->checkRangeLimits(); + m_data->setWorkspace(workspace); + + // Sets how the signal is normalized + m_normalization = workspace->displayNormalization(); + m_data->setNormalization(m_normalization); + + this->setVectorDimensions(); + this->findFullRange(); + + m_uiForm.colourBar->setViewRange(m_colourRangeFull); + m_uiForm.colourBar->updateColorMap(); + m_uiForm.plot2D->setWorkspace(workspace); + m_spectrogram->setColorMap(m_uiForm.colourBar->getColorMap()); + + this->updateDisplay(); + m_uiForm.colourBar->setScale(0); +} + +SafeQwtPlot *ContourPreviewPlot::getPlot2D() { return m_uiForm.plot2D; } + +/** + * Set the plot to be visible or hidden + * @param visible :: false to hide the plot + */ +void ContourPreviewPlot::setPlotVisible(bool const &visible) { + m_uiForm.plot2D->setVisible(visible); +} + +/** + * Set the colour bar to be visible or hidden + * @param visible :: false to hide the colour bar + */ +void ContourPreviewPlot::setColourBarVisible(bool const &visible) { + m_uiForm.colourBar->setVisible(visible); +} + +/** + * Checks if the plot is currently visible + * @returns true if the plot is visible + */ +bool ContourPreviewPlot::isPlotVisible() const { + return m_uiForm.plot2D->isVisible(); +} + +/** + * Checks if the colour bar is currently visible + * @returns true if the colour bar is visible + */ +bool ContourPreviewPlot::isColourBarVisible() const { + return m_uiForm.colourBar->isVisible(); +} + +/** + * Sets the label for the x axis + * @param label :: the label given to the axis + */ +void ContourPreviewPlot::setXAxisLabel(QString const &label) { + m_uiForm.lbXAxis->setText(label); +} + +/** + * Sets the label for the y axis + * @param label :: the label given to the axis + */ +void ContourPreviewPlot::setYAxisLabel(QString const &label) { + m_uiForm.lbYAxis->setText(label); +} + +/** + * Slot called when the ColorBarWidget changes the range of colours + */ +void ContourPreviewPlot::handleColourRangeChanged() { + m_spectrogram->setColorMap(m_uiForm.colourBar->getColorMap()); + this->updateDisplay(); +} + +/** + * Slot called to load a colour map + */ +void ContourPreviewPlot::handleLoadColourMap() { + this->loadColourMap(QString()); +} + +/** + * Set whether to display 0 signal as "transparent" colour. + * @param transparent :: true if you want zeros to be transparent. + */ +void ContourPreviewPlot::handleSetTransparentZeros(bool const &transparent) { + m_data->setZerosAsNan(transparent); + this->updateDisplay(); +} + +/** + * Remove the displayed data when the associated workspace is deleted + */ +void ContourPreviewPlot::preDeleteHandle( + std::string const &workspaceName, + boost::shared_ptr<Workspace> const workspace) { + UNUSED_ARG(workspaceName); + auto const deletedWorkspace = convertToMatrixWorkspace(workspace); + if (deletedWorkspace && deletedWorkspace == m_workspace) + this->clearPlot(); +} + +/** + * Clear the plot + */ +void ContourPreviewPlot::clearPlot() { m_uiForm.plot2D->clear(); } + +/** + * Setup the ColourBar and Plot. Attach the spectrogram to the plot + */ +void ContourPreviewPlot::setupColourBarAndPlot() { + m_uiForm.colourBar->setViewRange(1, 10); + m_spectrogram->attach(m_uiForm.plot2D); + m_spectrogram->setColorMap(m_uiForm.colourBar->getColorMap()); + m_uiForm.plot2D->autoRefresh(); +} + +/** + * Load QSettings from .ini-type files + */ +void ContourPreviewPlot::loadSettings() { + QSettings settings; + settings.beginGroup("Mantid/ContourPreviewPlot"); + + setCurrentColourMapFile(settings); + if (!m_currentColourMapFile.isEmpty()) + loadColourMap(m_currentColourMapFile); + + m_uiForm.colourBar->setScale(getScaleType(settings)); + m_uiForm.colourBar->setExponent(getExponent(settings)); + this->handleSetTransparentZeros(transparentZeros(settings)); + + settings.endGroup(); +} + +/** + * Set the current colour map file + * @param settings :: stores the value of the colour map file + */ +void ContourPreviewPlot::setCurrentColourMapFile(QSettings const &settings) { + if (m_mdSettings != nullptr && m_mdSettings->getUsageGeneralMdColorMap()) + setCurrentColourMapFile(m_mdSettings->getGeneralMdColorMapFile()); + else + setCurrentColourMapFile(getColourMapFile(settings)); +} + +/** + * Set the current colour map file + * @param file :: the filename as a QString + */ +void ContourPreviewPlot::setCurrentColourMapFile(QString const &file) { + m_currentColourMapFile = file; +} + +void ContourPreviewPlot::saveSettings() { + QSettings settings; + settings.beginGroup("Mantid/ContourPreviewPlot"); + settings.setValue("ColourmapFile", m_currentColourMapFile); + settings.setValue("ColourScale", m_uiForm.colourBar->getScale()); + settings.setValue("PowerScaleExponent", m_uiForm.colourBar->getExponent()); + settings.setValue("TransparentZeros", (m_data->isZerosAsNan() ? 1 : 0)); +} + +/** + * Load a colour map from a file + * @param file :: file to open; empty to ask via a dialog box. + */ +void ContourPreviewPlot::loadColourMap(QString file) { + auto const filename = colourMapFileName(file); + if (!filename.isEmpty()) { + setCurrentColourMapFile(filename); + m_uiForm.colourBar->getColorMap().loadMap(filename); + m_spectrogram->setColorMap(m_uiForm.colourBar->getColorMap()); + m_uiForm.colourBar->updateColorMap(); + + this->updateDisplay(); + } +} + +QString ContourPreviewPlot::colourMapFileName(QString const &filename) { + if (filename.isEmpty()) + return MantidColorMap::chooseColorMap(m_currentColourMapFile, this); + return filename; +} + +/** + * Updates the contour plot + */ +void ContourPreviewPlot::updateDisplay() { + if (m_workspace) { + m_data->setRange(m_uiForm.colourBar->getViewRange()); + + std::vector<Mantid::coord_t> slicePoint{0, 0}; + constexpr std::size_t dimX(0); + constexpr std::size_t dimY(1); + IMDDimension_const_sptr X = m_dimensions[dimX]; + IMDDimension_const_sptr Y = m_dimensions[dimY]; + m_data->setSliceParams(dimX, dimY, X, Y, slicePoint); + + double const left{X->getMinimum()}; + double const top{Y->getMinimum()}; + double const width{X->getMaximum() - X->getMinimum()}; + double const height{Y->getMaximum() - Y->getMinimum()}; + QwtDoubleRect const bounds{left, top, width, height}; + m_data->setBoundingRect(bounds.normalized()); + + m_spectrogram->setColorMap(m_uiForm.colourBar->getColorMap()); + m_spectrogram->setData(*m_data); + m_spectrogram->itemChanged(); + m_uiForm.plot2D->replot(); + } +} + +/** + * Verify the limits of the stored workspace + */ +void ContourPreviewPlot::checkRangeLimits() const { + std::ostringstream message; + for (auto i = 0u; i < m_workspace->getNumDims(); ++i) + checkForInfiniteLimits(dimensionRange(i), i, message); + + if (!message.str().empty()) { + message << "Bad ranges could cause memory allocation errors. Please fix " + "the workspace."; + throw std::out_of_range(message.str()); + } +} + +/** + * Produces an error message if either of the limits are infinite + */ +void ContourPreviewPlot::checkForInfiniteLimits( + DimensionRange const &range, std::size_t const &index, + std::ostringstream &message) const { + if (!std::isfinite(range.first) || !std::isfinite(range.second)) + message << "Dimension " << m_workspace->getDimension(index)->getName() + << " has a bad range: (" << range.first << ", " << range.second + << ")\n"; +} + +DimensionRange +ContourPreviewPlot::dimensionRange(std::size_t const &index) const { + DimensionRange range = + std::make_pair(dimensionMinimum(index), dimensionMaximum(index)); + if (range.second < range.first) + range.swap(range); + return range; +} + +Mantid::coord_t +ContourPreviewPlot::dimensionMinimum(std::size_t const &index) const { + return m_workspace->getDimension(index)->getMinimum(); +} + +Mantid::coord_t +ContourPreviewPlot::dimensionMaximum(std::size_t const &index) const { + return m_workspace->getDimension(index)->getMaximum(); +} + +/** + * Finds the full range of values in the workspace + */ +void ContourPreviewPlot::findFullRange() { + if (m_workspace) { + auto const workspace = m_workspace; + Mantid::Kernel::ReadLock lock(*workspace); + + m_colourRangeFull = + API::SignalRange(*workspace, m_normalization).interval(); + double minimum = m_colourRangeFull.minValue(); + + if (minimum <= 0 && m_uiForm.colourBar->getScale() == 1) { + double const maximum = m_colourRangeFull.maxValue(); + minimum = pow(10., log10(maximum) - 10.); + m_colourRangeFull = QwtDoubleInterval(minimum, maximum); + } + } +} + +/** + * Update m_dimensions using the loaded workspace + */ +void ContourPreviewPlot::setVectorDimensions() { + if (m_workspace) { + m_dimensions.clear(); + + for (auto i = 0u; i < m_workspace->getNumDims(); ++i) { + MDHistoDimension_sptr dimension(std::make_unique<MDHistoDimension>( + m_workspace->getDimension(i).get())); + m_dimensions.push_back(dimension); + } + } +} + +} // namespace MantidWidgets +} // namespace MantidQt diff --git a/qt/widgets/legacyqwt/test/ContourPreviewPlotTest.h b/qt/widgets/legacyqwt/test/ContourPreviewPlotTest.h new file mode 100644 index 0000000000000000000000000000000000000000..146ecb2b8a19e8fa40c6e377a35030fe3bd951db --- /dev/null +++ b/qt/widgets/legacyqwt/test/ContourPreviewPlotTest.h @@ -0,0 +1,99 @@ +// Mantid Repository : https://github.com/mantidproject/mantid +// +// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI, +// NScD Oak Ridge National Laboratory, European Spallation Source +// & Institut Laue - Langevin +// SPDX - License - Identifier: GPL - 3.0 + +#ifndef MANTIDQT_API_MANTIDCONTOURPREVIEWPLOTTEST_H_ +#define MANTIDQT_API_MANTIDCONTOURPREVIEWPLOTTEST_H_ + +#include <cxxtest/TestSuite.h> + +#include "MantidAPI/MatrixWorkspace.h" +#include "MantidQtWidgets/LegacyQwt/ContourPreviewPlot.h" +#include "MantidTestHelpers/WorkspaceCreationHelper.h" + +using namespace Mantid::API; +using namespace MantidQt::MantidWidgets; + +namespace { + +MatrixWorkspace_sptr createMatrixWorkspace(int numberOfHistograms, + int numberOfBoundaries = 4) { + return WorkspaceCreationHelper::create2DWorkspace(numberOfHistograms, + numberOfBoundaries); +} + +} // namespace + +/// This QApplication object is required in order to construct the widget +class QApplicationHolder : CxxTest::GlobalFixture { +public: + bool setUpWorld() override { + int argc(0); + char **argv = {}; + m_app = new QApplication(argc, argv); + return true; + } + + bool tearDownWorld() override { + delete m_app; + return true; + } + +private: + QApplication *m_app; +}; + +static QApplicationHolder MAIN_QAPPLICATION; + +/// Unit tests for ContourPreviewPlot +class ContourPreviewPlotTest : public CxxTest::TestSuite { +public: + static ContourPreviewPlotTest *createSuite() { + return new ContourPreviewPlotTest(); + } + + static void destroySuite(ContourPreviewPlotTest *suite) { delete suite; } + + void setUp() override { + m_contourPlot = std::make_unique<ContourPreviewPlot>(); + } + + void tearDown() override { m_contourPlot.reset(); } + + void + test_that_a_ContourPreviewPlot_is_instantiated_without_an_active_workspace() { + TS_ASSERT(!m_contourPlot->getActiveWorkspace()); + } + + void test_that_getPlot2D_will_get_the_contour_plot() { + TS_ASSERT(m_contourPlot->getPlot2D()); + } + + void + test_that_setWorkspace_will_set_the_active_workspace_for_the_contour_plot() { + auto const workspace = createMatrixWorkspace(3); + + m_contourPlot->setWorkspace(workspace); + + TS_ASSERT(m_contourPlot->getActiveWorkspace()); + TS_ASSERT_EQUALS(m_contourPlot->getActiveWorkspace(), workspace); + } + + void test_that_setPlotVisible_will_hide_the_plot_when_it_is_passed_false() { + m_contourPlot->setPlotVisible(false); + TS_ASSERT(!m_contourPlot->isPlotVisible()); + } + + void + test_that_setColourBarVisible_will_hide_the_colour_bar_when_it_is_passed_false() { + m_contourPlot->setColourBarVisible(false); + TS_ASSERT(!m_contourPlot->isColourBarVisible()); + } + +private: + std::unique_ptr<ContourPreviewPlot> m_contourPlot; +}; + +#endif /* MANTIDQT_API_MANTIDCONTOURPREVIEWPLOTTEST_H_ */