From 10439c2a06c4172c23c2425fbab1707b8599b7b7 Mon Sep 17 00:00:00 2001 From: Shahroz Ahmed <shahroz.ahmed@stfc.ac.uk> Date: Thu, 7 Apr 2016 12:15:34 +0100 Subject: [PATCH] handling of adding peaks to list and signal & slots refs #15765 --- .../EnggDiffractionQtTabFitting.ui | 6 +++ .../EnggDiffractionViewQtGUI.cpp | 49 ++++++++++--------- 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionQtTabFitting.ui b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionQtTabFitting.ui index 37790a92d1a..fe234039b3c 100644 --- a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionQtTabFitting.ui +++ b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionQtTabFitting.ui @@ -370,6 +370,9 @@ </item> <item> <widget class="QPushButton" name="pushButton_add_peak"> + <property name="enabled"> + <bool>false</bool> + </property> <property name="text"> <string>Add Peak</string> </property> @@ -377,6 +380,9 @@ </item> <item> <widget class="QPushButton" name="pushButton_save_peak_list"> + <property name="enabled"> + <bool>true</bool> + </property> <property name="text"> <string>Save Peaks List</string> </property> diff --git a/MantidQt/CustomInterfaces/src/EnggDiffraction/EnggDiffractionViewQtGUI.cpp b/MantidQt/CustomInterfaces/src/EnggDiffraction/EnggDiffractionViewQtGUI.cpp index 02c02e43bde..2cc4aa93614 100644 --- a/MantidQt/CustomInterfaces/src/EnggDiffraction/EnggDiffractionViewQtGUI.cpp +++ b/MantidQt/CustomInterfaces/src/EnggDiffraction/EnggDiffractionViewQtGUI.cpp @@ -784,6 +784,8 @@ void EnggDiffractionViewQtGUI::setPeakPickerEnabled(bool enabled) { m_peakPicker->setEnabled(enabled); m_peakPicker->setVisible(enabled); m_uiTabFitting.dataPlot->replot(); // PeakPicker might get hidden/shown + m_uiTabFitting.pushButton_add_peak->setEnabled(enabled); + m_uiTabFitting.pushButton_select_peak->setEnabled(!enabled); } void EnggDiffractionViewQtGUI::setPeakPicker( @@ -1325,29 +1327,30 @@ void MantidQt::CustomInterfaces::EnggDiffractionViewQtGUI::setPeakPick() { void MantidQt::CustomInterfaces::EnggDiffractionViewQtGUI::addPeakToList() { - if (m_peakPicker->isEnabled()) { - auto peakCentre = getPeakCentre(); - - std::stringstream stream; - stream << std::fixed << std::setprecision(4) << peakCentre; - auto strPeakCentre = stream.str(); - - auto curExpPeaksList = m_uiTabFitting.lineEdit_fitting_peaks->text(); - - if (!curExpPeaksList.isEmpty()) { - - std::string expPeakStr = curExpPeaksList.toStdString(); - std::size_t found = (expPeakStr.find_last_of(", ") || expPeakStr.find_last_of(",")); - if (found) { - QString comma = ", "; - curExpPeaksList.append(comma + QString::fromStdString(strPeakCentre)); - } - else { - curExpPeaksList.append(QString::fromStdString(strPeakCentre)); - } - m_uiTabFitting.lineEdit_fitting_peaks->setText(curExpPeaksList); - } - } + if (m_peakPicker->isEnabled()) { + auto peakCentre = getPeakCentre(); + + std::stringstream stream; + stream << std::fixed << std::setprecision(4) << peakCentre; + auto strPeakCentre = stream.str(); + + auto curExpPeaksList = m_uiTabFitting.lineEdit_fitting_peaks->text(); + + if (!curExpPeaksList.isEmpty()) { + + std::string expPeakStr = curExpPeaksList.toStdString(); + std::string lastTwoChr = expPeakStr.substr(expPeakStr.size() - 2); + auto lastChr = expPeakStr.back(); + char comma = ','; + if (lastChr == comma || lastTwoChr == ", ") { + curExpPeaksList.append(QString::fromStdString(" " + strPeakCentre)); + } else { + QString comma = ", "; + curExpPeaksList.append(comma + QString::fromStdString(strPeakCentre)); + } + m_uiTabFitting.lineEdit_fitting_peaks->setText(curExpPeaksList); + } + } } void MantidQt::CustomInterfaces::EnggDiffractionViewQtGUI::savePeakList() { -- GitLab