Mantid
Loading...
Searching...
No Matches
MuonFitDataSelector.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
9
10#include "MantidQtWidgets/Common/QtPropertyBrowser/qtpropertymanager.h"
11#include "MantidQtWidgets/Common/QtPropertyBrowser/qttreepropertybrowser.h"
12#include <QFileInfo>
13
14namespace {
15Mantid::Kernel::Logger g_log("MuonFitDataSelector");
16}
17
18namespace MantidQt {
19namespace MantidWidgets {
20
26 m_multiFit = false;
27 m_ui.setupUi(this);
28 this->setDefaultValues();
29 this->setUpConnections();
30 // Disable "Browse" button - use case is that first run will always be the one
31 // selected on front tab. User will type in the runs they want rather than
32 // using the Browse button. (If they want to "Browse" they can use front tab).
34}
35
42MuonFitDataSelector::MuonFitDataSelector(QWidget *parent, int runNumber, const QString &instName) /*
43 * numPeriods :: [input] Number of periods from initial workspace
44 * groups :: [input] Group names from initial workspace
45 size_t numPeriods,
46 const QStringList &groups)*/
47 : MuonFitDataSelector(parent) {
48 m_multiFit = false;
49 this->setWorkspaceDetails(QString::number(runNumber), instName, boost::optional<QString>{});
50 // not used in this case
51 // but leave these here as a remainder
52 // for future changes that may need to assign them
53
54 // this->setNumPeriods(numPeriods);
55 // this->setAvailableGroups(groups);
56}
57
63 connect(m_ui.runs, SIGNAL(filesFound()), this, SLOT(userChangedRuns()));
64 connect(m_ui.rbCoAdd, SIGNAL(toggled(bool)), this, SLOT(fitTypeChanged(bool)));
65 connect(m_ui.txtSimFitLabel, SIGNAL(editingFinished()), this, SIGNAL(simulLabelChanged()));
66 connect(this, SIGNAL(workspaceChanged()), this, SLOT(checkForMultiGroupPeriodSelection()));
67 connect(m_ui.cbDataset, SIGNAL(currentIndexChanged(int)), this, SIGNAL(datasetIndexChanged(int)));
68 connect(m_ui.cbDataset, SIGNAL(currentIndexChanged(int)), this, SLOT(updateNormalizationFromDropDown(int)));
69 connect(m_ui.btnNextDataset, SIGNAL(clicked()), this, SLOT(setNextDataset()));
70 connect(m_ui.btnPrevDataset, SIGNAL(clicked()), this, SLOT(setPreviousDataset()));
71}
72
78 (void)state;
79 emit workspaceChanged();
80}
81
88 // check for single run and enable/disable radio buttons
89 const auto runs = getRuns();
90 if (runs.contains(',') || runs.contains('-')) {
91 // record if its multi fit
92 m_multiFit = true;
93 } else {
95 }
96 emit workspaceChanged();
97}
98
104 // Validator ensures cast to double will succeed
105 return m_startX; // start.toDouble();
106}
107
113
119 setStartTimeQuietly(start);
121}
122
127double MuonFitDataSelector::getEndTime() const { return m_endX; }
128
134
142}
143
148QStringList MuonFitDataSelector::getFilenames() const { return m_ui.runs->getFilenames(); }
149
158void MuonFitDataSelector::setWorkspaceDetails(const QString &runNumbers, const QString &instName,
159 const boost::optional<QString> &filePath) {
160 // Set the file finder to the correct instrument (not Mantid's default)
161 m_ui.runs->setInstrumentOverride(instName);
162
163 QString runs(runNumbers);
164 runs.remove(QRegExp("^[0]*")); // remove leading zeros, if any
165 // Set fit type - co-add (as this comes from Home tab) or single
166 if (runs.contains('-') || runs.contains(',')) {
168 } else {
170 }
171
172 // Set initial run to be run number of the workspace loaded in Home tab
173 // and search for filenames. Use busy cursor until search finished.
174 setBusyState();
175
176 if (filePath) { // load current run: use special file path
177 m_ui.runs->setUserInput(filePath.get());
178 m_ui.runs->setText(runs);
179 } else { // default
180 m_ui.runs->setFileTextWithSearch(runs);
181 }
182}
183
189 this->setStartTime(0.0);
190 this->setEndTime(0.0);
191 m_ui.txtSimFitLabel->setText("0");
192 emit simulLabelChanged(); // make sure default "0" is set
193}
199
205
217 QVariant ret(QVariant::Map);
218 auto map = ret.toMap();
219 map.insert("Start", getStartTime());
220 map.insert("End", getEndTime());
221 map.insert("Runs", getRuns());
222 map.insert("Groups", getChosenGroups());
223 map.insert("Periods", getPeriodSelections());
224 return map;
225}
226
240 if (value.canConvert(QVariant::Map)) {
241 const auto map = value.toMap();
242 if (map.contains("Start")) {
243 setStartTime(map.value("Start").toDouble());
244 }
245 if (map.contains("End")) {
246 setEndTime(map.value("End").toDouble());
247 }
248 }
249}
250
260 // If radio buttons disabled, it's a single fit unless multiple groups/periods
261 // chosen
262 if (!m_multiFit) {
263 return m_chosenGroups.size() <= 1 && m_chosenPeriods.size() <= 1 ? FitType::Single : FitType::Simultaneous;
264 } else {
265 // which button is selected
266 if (m_ui.rbCoAdd->isChecked()) {
267 return FitType::CoAdd;
268 } else {
270 }
271 }
272}
273
281 if (type == FitType::Single) {
282 m_multiFit = false;
283 } else {
284 m_multiFit = true;
285
286 m_ui.rbCoAdd->setChecked(type == FitType::CoAdd);
287 m_ui.rbSimultaneous->setChecked(type == FitType::Simultaneous);
288 }
290}
296QString MuonFitDataSelector::getInstrumentName() const { return m_ui.runs->getInstrumentOverride(); }
297
303 if (m_ui.runs->isValid()) {
304 return m_ui.runs->getText();
305 } else {
306 return "";
307 }
308}
309
315 disconnect(m_ui.runs, SIGNAL(fileInspectionFinished()), this, SLOT(unsetBusyState()));
316 this->setCursor(Qt::ArrowCursor);
317}
318
324 connect(m_ui.runs, SIGNAL(fileInspectionFinished()), this, SLOT(unsetBusyState()));
325 this->setCursor(Qt::WaitCursor);
326}
327
332QString MuonFitDataSelector::getSimultaneousFitLabel() const { return m_ui.txtSimFitLabel->text(); }
333
339 // do some checks that it is valid
340 auto safeLabel = label;
341 if (label.indexOf(".") >= 0) {
342 QFileInfo file(label);
343 safeLabel = file.baseName();
344 // trim instrument name
345 auto index = safeLabel.indexOf("0");
346 safeLabel = safeLabel.mid(index);
347 // trim leading zeros
348 safeLabel = safeLabel.remove(QRegExp("^[0]*"));
349 }
350 m_ui.txtSimFitLabel->setText(safeLabel);
351}
352
358 m_ui.txtSimFitLabel->setEnabled(m_chosenGroups.size() > 1 || m_chosenPeriods.size() > 1 ||
360}
361
366int MuonFitDataSelector::getDatasetIndex() const { return m_ui.cbDataset->currentIndex(); }
367
372QString MuonFitDataSelector::getDatasetName() const { return m_ui.cbDataset->currentText(); }
373
378void MuonFitDataSelector::setDatasetNames(const QStringList &datasetNames) {
379 const auto selectedName = m_ui.cbDataset->currentText();
380 // Turn off signals while names are updated
381 m_ui.cbDataset->blockSignals(true);
382 m_ui.cbDataset->clear();
383 m_ui.cbDataset->addItems(datasetNames);
384 m_ui.cbDataset->blockSignals(false);
385
386 // If previously selected name is in new list, set this index again.
387 int i = 0;
388 while (i < m_ui.cbDataset->count()) {
389 if (m_ui.cbDataset->itemText(i) == selectedName) {
390 m_ui.cbDataset->setCurrentIndex(i);
391 break;
392 }
393 i++;
394 }
395 // Otherwise select the first in the list.
396 if (i == m_ui.cbDataset->count()) {
397 m_ui.cbDataset->setCurrentIndex(0);
398 }
399}
401 for (int i = 0; i < m_ui.cbDataset->count(); i++) {
402 if (i == j) {
403 auto name = m_ui.cbDataset->itemText(i);
404 emit nameChanged(name);
405 return;
406 }
407 }
408}
415 const int index = m_ui.cbDataset->currentIndex();
416 if (index > 0) {
417 m_ui.cbDataset->setCurrentIndex(index - 1);
418 }
419}
420
427 const int index = m_ui.cbDataset->currentIndex();
428 const int maxIndex = m_ui.cbDataset->count() - 1;
429 if (index < maxIndex) {
430 m_ui.cbDataset->setCurrentIndex(index + 1);
431 }
432}
433
440 const int choice =
441 QMessageBox::question(this, tr("MantidPlot - Overwrite Warning"),
442 getSimultaneousFitLabel() + tr(" already exists. Do you want to replace it?"),
443 QMessageBox::Yes | QMessageBox::Default, QMessageBox::No | QMessageBox::Escape);
444
445 return choice == QMessageBox::Yes;
446}
447
448} // namespace MantidWidgets
449} // namespace MantidQt
double value
The value of the point.
Definition: FitMW.cpp:51
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
int count
counter
Definition: Matrix.cpp:37
@ None
disable the load file dialog
This is the base class all customised widgets that do not wish to be tied to a specific Mantid algori...
Definition: MantidWidget.h:27
MuonFitDataSelector : Selects runs, groups, periods for fit.
void workspaceChanged()
Changed the workspace.
void setUpConnections()
Set up connections for signals/slots.
void setDatasetNames(const QStringList &datasetNames) override
Set names of datasets for selection.
void setEndTimeQuietly(double end) override
Set end time without sending a signal.
void unsetBusyState()
Set normal cursor and enable input.
void setEndTime(double end) override
Set end time for fit.
double getStartTime() const override
Get selected start time.
QString getDatasetName() const override
Get name of selected dataset.
void setStartTime(double start) override
Set start time for fit.
QString getSimultaneousFitLabel() const override
Get label for simultaneous fit.
Ui::MuonFitDataSelector m_ui
Member - user interface.
void setPreviousDataset()
Change dataset to previous one.
QStringList getFilenames() const override
Get selected filenames.
void checkForMultiGroupPeriodSelection()
Called when group/period box selection changes.
void setBusyState()
Set busy cursor and disable input.
QStringList getChosenGroups() const override
Get names of chosen groups.
void fitTypeChanged(bool state)
Called when fit type changed.
void setFitType(IMuonFitDataSelector::FitType type)
Set type for fit.
void setUserInput(const QVariant &value) override
Set user input through a common interface.
void setNextDataset()
Change dataset to next one.
MuonFitDataSelector(QWidget *parent)
Basic constructor.
void simulLabelChanged()
Simultaneous fit label changed.
QString getRuns() const override
Get selected run numbers.
void datasetIndexChanged(int index)
Dataset index changed.
void setWorkspaceDetails(const QString &runNumbers, const QString &instName, const boost::optional< QString > &filePath) override
Set starting run number, instrument and (optionally) file path.
QStringList getPeriodSelections() const override
Get selected periods.
bool askUserWhetherToOverwrite() override
Ask user whether to overwrite label or not.
void setSimultaneousFitLabel(const QString &label) override
Set label for simultaneous fit.
QString getInstrumentName() const override
Get instrument name.
void setDefaultValues()
Set default values in some input controls.
double getEndTime() const override
Get selected end time.
void setStartTimeQuietly(double start) override
Set start time without sending a signal.
void dataPropertiesChanged()
Edited the start or end fields.
void userChangedRuns()
Called when user changes runs.
int getDatasetIndex() const override
Get index of selected dataset.
QVariant getUserInput() const override
Get user input through a common interface.
IMuonFitDataSelector::FitType getFitType() const override
Get type of fit.
The Logger class is in charge of the publishing messages from the framework through various channels.
Definition: Logger.h:52
The AlgorithmProgressDialogPresenter keeps track of the running algorithms and displays a progress ba...
Kernel::Logger g_log("ExperimentInfo")
static logger object