diff --git a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Muon/MuonAnalysis.ui b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Muon/MuonAnalysis.ui index d0adda3a343ba1e86c26100545b9c3428d959ffe..2ebeec548893b4a616ad28fb8e0847366fe2eaf7 100644 --- a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Muon/MuonAnalysis.ui +++ b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Muon/MuonAnalysis.ui @@ -2411,22 +2411,6 @@ p, li { white-space: pre-wrap; } <layout class="QGridLayout" name="gridLayout_20"> <item row="3" column="0"> <layout class="QGridLayout" name="gridLayout_21"> - <item row="0" column="2"> - <spacer name="horizontalSpacer_23"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeType"> - <enum>QSizePolicy::Fixed</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>200</width> - <height>20</height> - </size> - </property> - </spacer> - </item> <item row="0" column="1"> <widget class="QComboBox" name="plotCreation"> <property name="sizePolicy"> @@ -2457,6 +2441,22 @@ p, li { white-space: pre-wrap; } </item> </widget> </item> + <item row="0" column="2"> + <spacer name="horizontalSpacer_23"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeType"> + <enum>QSizePolicy::Fixed</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>200</width> + <height>20</height> + </size> + </property> + </spacer> + </item> <item row="0" column="0"> <widget class="QLabel" name="label_7"> <property name="toolTip"> @@ -2518,11 +2518,39 @@ p, li { white-space: pre-wrap; } </layout> </widget> <widget class="QWidget" name="page_2"> - <layout class="QHBoxLayout" name="horizontalLayout_15"> - <property name="margin"> - <number>0</number> - </property> - </layout> + <widget class="QWidget" name=""> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>131</width> + <height>22</height> + </rect> + </property> + <layout class="QHBoxLayout" name="horizontalLayout_KeepNPlots"> + <item> + <widget class="QLabel" name="lblKeepLast"> + <property name="text"> + <string>Keep last</string> + </property> + </widget> + </item> + <item> + <widget class="QSpinBox" name="spinBoxNPlotsToKeep"> + <property name="value"> + <number>1</number> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="lblPlots"> + <property name="text"> + <string>plot(s)</string> + </property> + </widget> + </item> + </layout> + </widget> </widget> </widget> </item> diff --git a/MantidQt/CustomInterfaces/src/Muon/MuonAnalysis.cpp b/MantidQt/CustomInterfaces/src/Muon/MuonAnalysis.cpp index d8f935d5165c7c53bbd8bc7c92df7b5281c829fa..3f3344825a9cd59dd80c96fa67527855cc8730ac 100644 --- a/MantidQt/CustomInterfaces/src/Muon/MuonAnalysis.cpp +++ b/MantidQt/CustomInterfaces/src/Muon/MuonAnalysis.cpp @@ -1844,16 +1844,23 @@ void MuonAnalysis::plotSpectrum(const QString &wsName, bool logScale) { s << ""; // Remove data and difference from given plot (keep fit and guess) - s << "def remove_data(window):"; + // num_to_keep: number of previous fits to keep + s << "def remove_data(window, num_to_keep):"; s << " if window is None:"; s << " raise ValueError('No plot to remove data from')"; - s << " to_keep = ['Workspace-Calc', 'CompositeFunction']"; + // Need to keep the last "num_to_keep" curves with + // "Workspace-Calc" in their name, plus guesses s << " layer = window.activeLayer()"; s << " if layer is not None:"; - s << " for i in range(0, layer.numCurves()):"; - s << " if not any (x in layer.curveTitle(i) for x in to_keep):"; - s << " layer.removeCurve(i)"; - s << ""; + s << " kept_fits = 0"; + s << " for i in range(layer.numCurves() - 1, -1, -1):"; // reversed + s << " title = layer.curveTitle(i)"; + s << " if title == \"CompositeFunction\":"; + s << " continue"; // keep all guesses + s << " if \"Workspace-Calc\" in title and kept_fits < num_to_keep:"; + s << " kept_fits = kept_fits + 1"; + s << " continue"; // keep last n fits + s << " layer.removeCurve(i)"; // remove everything else // Plot data in the given window with given options s << "def plot_data(ws_name, errors, connect, window_to_use):"; @@ -1889,7 +1896,8 @@ void MuonAnalysis::plotSpectrum(const QString &wsName, bool logScale) { // Plot the data! s << "win = get_window('%WSNAME%', '%PREV%', %USEPREV%)"; - s << "remove_data(win)"; + s << "if %FITSTOKEEP% != -1:"; + s << " remove_data(win, %FITSTOKEEP%)"; s << "g = plot_data('%WSNAME%', %ERRORS%, %CONNECT%, win)"; s << "format_graph(g, '%WSNAME%', %LOGSCALE%, %YAUTO%, '%YMIN%', '%YMAX%')"; @@ -1915,6 +1923,11 @@ void MuonAnalysis::plotSpectrum(const QString &wsName, bool logScale) { pyS.replace("%YAUTO%", params["YAxisAuto"]); pyS.replace("%YMIN%", params["YAxisMin"]); pyS.replace("%YMAX%", params["YAxisMax"]); + if (policy == MuonAnalysisOptionTab::PreviousWindow) { + pyS.replace("%FITSTOKEEP%", m_uiForm.spinBoxNPlotsToKeep->text()); + } else { + pyS.replace("%FITSTOKEEP%", "-1"); + } runPythonCode(pyS); } diff --git a/MantidQt/CustomInterfaces/src/Muon/MuonAnalysisHelper.cpp b/MantidQt/CustomInterfaces/src/Muon/MuonAnalysisHelper.cpp index 46ae6407a2178e4e2e6b7200f5a0e618988f7c8f..1e739a6ebb3ed4a2417b1a9b5099326fd5d8e23e 100644 --- a/MantidQt/CustomInterfaces/src/Muon/MuonAnalysisHelper.cpp +++ b/MantidQt/CustomInterfaces/src/Muon/MuonAnalysisHelper.cpp @@ -14,6 +14,7 @@ #include <QLineEdit> #include <QCheckBox> #include <QComboBox> +#include <QSpinBox> #include <boost/scope_exit.hpp> #include <stdexcept> @@ -190,7 +191,7 @@ void WidgetAutoSaver::registerWidget(QWidget *widget, const QString &name, } /** - * Return a signal (which can be used instead of SIGNAL()) which is emmited when + * Return a signal (which can be used instead of SIGNAL()) which is emitted when * given widget is * changed. * @param widget @@ -204,8 +205,10 @@ const char *WidgetAutoSaver::changedSignal(QWidget *widget) { return SIGNAL(stateChanged(int)); } else if (qobject_cast<QComboBox *>(widget)) { return SIGNAL(currentIndexChanged(int)); + } else if (qobject_cast<QSpinBox *>(widget)) { + return SIGNAL(valueChanged(int)); } - // ... add more as neccessary + // ... add more as necessary else { throw std::runtime_error("Unsupported widget type"); } diff --git a/MantidQt/CustomInterfaces/src/Muon/MuonAnalysisOptionTab.cpp b/MantidQt/CustomInterfaces/src/Muon/MuonAnalysisOptionTab.cpp index 8fa4b7d20ad468657f3294a6cd816aac3ab63107..8b5e166e8bc5d9ee8ff01aac27356a3b9fec97e2 100644 --- a/MantidQt/CustomInterfaces/src/Muon/MuonAnalysisOptionTab.cpp +++ b/MantidQt/CustomInterfaces/src/Muon/MuonAnalysisOptionTab.cpp @@ -71,6 +71,7 @@ void MuonAnalysisOptionTab::initLayout() { m_autoSaver.registerWidget(m_uiForm.newPlotPolicy, "newPlotPolicy", 0); m_autoSaver.registerWidget(m_uiForm.hideToolbars, "toolbars", true); m_autoSaver.registerWidget(m_uiForm.hideGraphs, "hiddenGraphs", true); + m_autoSaver.registerWidget(m_uiForm.spinBoxNPlotsToKeep, "fitsToKeep", 1); m_autoSaver.endGroup(); // Set validators for double fields diff --git a/docs/source/release/v3.8.0/muon.rst b/docs/source/release/v3.8.0/muon.rst index 31f50d54c280692a4c46d34437b64c25db53c8f3..a2f9fd97d5e0783ce45a87be48ab2824d6f02932 100644 --- a/docs/source/release/v3.8.0/muon.rst +++ b/docs/source/release/v3.8.0/muon.rst @@ -11,6 +11,8 @@ Interfaces Muon Analysis ############# +- When reusing the same plot window, an option has been added on the Settings tab to control how many previous fits are kept. It can be adjusted to 0 (remove all previous fits; default pre-Mantid 3.7), 1 (keep just one previous fit plus this one; new default) or higher. + Algorithms ----------