Mantid
Loading...
Searching...
No Matches
AddWorkspaceMultiDialog.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 +
12#include <QFileInfo>
13#include <utility>
14
15namespace {
16using namespace Mantid::API;
17
18MantidQt::API::IConfiguredAlgorithm_sptr configureLoadAlgorithm(const QString &filename,
19 const AlgorithmRuntimeProps &loadProps) {
20 QFileInfo const fileinfo(filename);
21 auto loader = AlgorithmManager::Instance().createUnmanaged("Load");
22 loader->initialize();
23 loader->setProperty("Filename", filename.toStdString());
24 loader->setProperty("OutputWorkspace", fileinfo.baseName().toStdString());
25 loader->updatePropertyValues(loadProps);
26 auto properties = std::make_unique<AlgorithmRuntimeProps>();
27
28 return std::make_shared<MantidQt::API::ConfiguredAlgorithm>(loader, std::move(properties));
29}
30} // namespace
31
33
35 : QDialog(parent), m_algRunner(std::make_unique<API::QtJobRunner>()), m_loadProperties() {
36 m_uiForm.setupUi(this);
37 m_algRunner->subscribe(this);
38 connect(m_uiForm.pbSelAll, SIGNAL(clicked()), this, SLOT(selectAllSpectra()));
39 connect(m_uiForm.pbResetDefault, SIGNAL(clicked()), this, SLOT(updateSelectedSpectra()));
40 connect(m_uiForm.dsInputFiles, SIGNAL(filesFound()), this, SLOT(handleFilesFound()));
41 connect(m_uiForm.pbUnify, SIGNAL(clicked()), this, SLOT(unifyRange()));
42 connect(m_uiForm.pbAdd, SIGNAL(clicked()), this, SLOT(emitAddData()));
43 connect(m_uiForm.pbClose, SIGNAL(clicked()), this, SLOT(close()));
44}
46 throw std::logic_error("This method is not implemented in AddWorkspaceMultiDialog class and shouldn't be called");
47}
48
49void AddWorkspaceMultiDialog::setup() { m_uiForm.tbWorkspace->setupTable(); }
50
52
53 return m_uiForm.tbWorkspace->retrieveSelectedNameIndexPairs();
54}
55
57 return ((m_uiForm.tbWorkspace->rowCount() == 0) || (m_uiForm.tbWorkspace->selectedItems().isEmpty()));
58}
59
60void AddWorkspaceMultiDialog::setWSSuffices(const QStringList &suffices) {
61 m_uiForm.tbWorkspace->setWSSuffixes(suffices);
62}
63
64void AddWorkspaceMultiDialog::setFBSuffices(const QStringList &suffices) {
65 return m_uiForm.dsInputFiles->setFileExtensions(suffices);
66}
67
76void AddWorkspaceMultiDialog::setLoadProperty(const std::string &propName, bool enable) {
78}
79
80void AddWorkspaceMultiDialog::selectAllSpectra() { return m_uiForm.tbWorkspace->selectAll(); }
81
83
84void AddWorkspaceMultiDialog::updateSelectedSpectra() { return m_uiForm.tbWorkspace->resetIndexRangeToDefault(); }
85
86void AddWorkspaceMultiDialog::unifyRange() { return m_uiForm.tbWorkspace->unifyRange(); }
87
90 auto fileNames = m_uiForm.dsInputFiles->getFilenames();
91 std::deque<API::IConfiguredAlgorithm_sptr> loadQueue;
92 std::transform(fileNames.begin(), fileNames.end(), std::back_inserter(loadQueue),
93 [&](auto const &fileName) { return configureLoadAlgorithm(fileName, m_loadProperties); });
94 m_algRunner->setAlgorithmQueue(std::move(loadQueue));
95 m_algRunner->executeAlgorithmQueue();
96}
97
102
104 std::string const &message) {
105 UNUSED_ARG(algorithm);
107 QMessageBox::warning(this, "Loading error", message.c_str());
108}
109
111 enabled ? m_uiForm.pbAdd->setText("Add Data") : m_uiForm.pbAdd->setText("Loading");
112 m_uiForm.pbAdd->setEnabled(enabled);
113}
114} // namespace MantidQt::MantidWidgets
double error
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
Definition System.h:48
std::vector< std::pair< std::string, std::string > > StringPairVec
void setWSSuffices(const QStringList &suffices) override
void addData(MantidWidgets::IAddWorkspaceDialog *dialog)
void setFBSuffices(const QStringList &suffices) override
void notifyAlgorithmError(API::IConfiguredAlgorithm_sptr &algorithm, std::string const &message) override
std::unique_ptr< MantidQt::API::QtJobRunner > m_algRunner
Algorithm Runner used to run the load algorithm.
void setLoadProperty(const std::string &propname, bool enable) override
Set an extra property on the load algorithm of the workspace multi dialog before execution.
std::shared_ptr< IConfiguredAlgorithm > IConfiguredAlgorithm_sptr
void MANTID_API_DLL update(std::string const &property, std::string const &value, IAlgorithmRuntimeProps &properties)
STL namespace.