Mantid
Loading...
Searching...
No Matches
LoadRawDialog.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
11
12#include <QCheckBox>
13#include <QComboBox>
14#include <QDir>
15#include <QFileInfo>
16#include <QFontMetrics>
17#include <QGridLayout>
18#include <QGroupBox>
19#include <QHBoxLayout>
20#include <QLabel>
21#include <QLineEdit>
22#include <QPushButton>
23#include <QVBoxLayout>
24
25// Add this class to the list of specialized dialogs in this namespace
28} // namespace MantidQt::CustomDialogs
29
30// Just to save writing this everywhere
31using namespace MantidQt::CustomDialogs;
32
33//---------------------------------------
34// Public member functions
35//---------------------------------------
39LoadRawDialog::LoadRawDialog(QWidget *parent) : AlgorithmDialog(parent), m_pathBox(nullptr), m_wsBox(nullptr) {}
40
45
46//---------------------------------------
47// Private member functions
48//---------------------------------------
53 QVBoxLayout *main_layout = new QVBoxLayout(this);
54
55 // Add the helpful summary message
57 this->addOptionalMessage(main_layout);
58
59 //------------- Filename property ---------------------
60 auto *prop_line = new QHBoxLayout;
61 prop_line->addWidget(new QLabel("Select a file to load:"));
62
63 m_pathBox = new QLineEdit;
64 m_pathBox->setMinimumWidth(m_pathBox->fontMetrics().maxWidth() * 13);
65 prop_line->addWidget(m_pathBox);
66 tie(m_pathBox, "Filename", prop_line);
67
68 auto *browseBtn = new QPushButton("Browse");
69 connect(browseBtn, SIGNAL(clicked()), this, SLOT(browseClicked()));
70 browseBtn->setEnabled(isWidgetEnabled("Filename"));
71 prop_line->addWidget(browseBtn);
72
73 main_layout->addLayout(prop_line);
74
75 //------------- OutputWorkspace property ---------------------
76 m_wsBox = new QLineEdit;
77
78 prop_line = new QHBoxLayout;
79 prop_line->addWidget(new QLabel("Enter name for workspace:"));
80 prop_line->addWidget(m_wsBox);
81 tie(m_wsBox, "OutputWorkspace", prop_line);
82 prop_line->addStretch();
83 main_layout->addLayout(prop_line);
84
85 //------------- Spectra properties ---------------------
86 auto *groupbox = new QGroupBox("Spectra Options");
87 prop_line = new QHBoxLayout;
88
89 auto *text_field = new QLineEdit;
90 text_field->setMaximumWidth(m_wsBox->fontMetrics().horizontalAdvance("888888"));
91 prop_line->addWidget(new QLabel("Start:"));
92 prop_line->addWidget(text_field);
93 tie(text_field, "SpectrumMin", prop_line);
94
95 text_field = new QLineEdit;
96 text_field->setMaximumWidth(m_wsBox->fontMetrics().horizontalAdvance("888888"));
97 prop_line->addWidget(new QLabel("End:"));
98 prop_line->addWidget(text_field);
99 tie(text_field, "SpectrumMax", prop_line);
100
101 text_field = new QLineEdit;
102 prop_line->addWidget(new QLabel("List:"));
103 prop_line->addWidget(text_field);
104 tie(text_field, "SpectrumList", prop_line);
105
106 prop_line->addStretch();
107 groupbox->setLayout(prop_line);
108 main_layout->addWidget(groupbox);
109
110 //------------- Period properties ---------------------
111 prop_line = new QHBoxLayout;
112 text_field = new QLineEdit;
113 prop_line->addWidget(new QLabel("Periods:"));
114 prop_line->addWidget(text_field);
115 prop_line->addStretch();
116 tie(text_field, "PeriodList", prop_line);
117
118 main_layout->addLayout(prop_line);
119
120 //------------- Cache option , log files options and Monitors Options
121 //---------------------
122
124 if (cacheProp) {
125 auto *cacheBox = new QComboBox;
126 std::vector<std::string> items = cacheProp->allowedValues();
127 std::vector<std::string>::const_iterator vend = items.end();
128 for (std::vector<std::string>::const_iterator vitr = items.begin(); vitr != vend; ++vitr) {
129 cacheBox->addItem(QString::fromStdString(*vitr));
130 }
131 prop_line = new QHBoxLayout;
132 prop_line->addWidget(new QLabel("Cache file locally:"), 0, Qt::AlignRight);
133 prop_line->addWidget(cacheBox, 0, Qt::AlignLeft);
134 tie(cacheBox, "Cache", prop_line);
135 }
136
137 prop_line->addStretch();
138 // If the algorithm version supports the LoadLog property add a check box for
139 // it
140 Mantid::Kernel::Property *loadlogs = getAlgorithmProperty("LoadLogFiles");
141 if (loadlogs) {
142 QCheckBox *checkbox = new QCheckBox("Load Log Files", this);
143 prop_line->addWidget(checkbox);
144 tie(checkbox, "LoadLogFiles", prop_line);
145 }
146 prop_line->addStretch();
147 //------------- If the algorithm version supports the LoadMonitors property
148 // add a check box for it ----
149 Mantid::Kernel::Property *loadMonitors = getAlgorithmProperty("LoadMonitors");
150 if (loadMonitors) {
151 auto *monitorsBox = new QComboBox;
152 std::vector<std::string> monitoritems = loadMonitors->allowedValues();
153 std::vector<std::string>::const_iterator mend = monitoritems.end();
154 for (std::vector<std::string>::const_iterator mitr = monitoritems.begin(); mitr != mend; ++mitr) {
155 monitorsBox->addItem(QString::fromStdString(*mitr));
156 }
157 prop_line->addWidget(new QLabel("LoadMonitors:"), 0, Qt::AlignRight);
158 prop_line->addWidget(monitorsBox);
159 tie(monitorsBox, "LoadMonitors", prop_line);
160 }
161
162 if (prop_line)
163 main_layout->addLayout(prop_line);
164
165 // Buttons
166 main_layout->addLayout(createDefaultButtonLayout("?", "Load", "Cancel"));
167}
168
173 if (!m_pathBox->text().isEmpty()) {
175 QFileInfo(m_pathBox->text()).absoluteDir().path());
176 }
177
178 QString filepath = this->openFileDialog("Filename");
179 if (!filepath.isEmpty()) {
180 m_pathBox->clear();
181 m_pathBox->setText(filepath.trimmed());
182 }
183
184 // Add a suggestion for workspace name
185 if (m_wsBox->isEnabled() && !filepath.isEmpty())
186 m_wsBox->setText(QFileInfo(filepath).baseName());
187}
#define DECLARE_DIALOG(classname)
bool isMessageAvailable() const
Is there a message string available.
bool isWidgetEnabled(const QString &propName) const
Check is a given property should have its control enabled or not.
QString openFileDialog(const QString &propName)
Open a file dialog to select a file.
QLayout * createDefaultButtonLayout(const QString &helpText=QString("?"), const QString &loadText=QString("Run"), const QString &cancelText=QString("Close"), const QString &keepOpenText=QString("Keep Open"))
Create a row layout of buttons with specified text.
QWidget * tie(QWidget *widget, const QString &property, QLayout *parent_layout=nullptr, bool readHistory=true)
Tie a widget to a property.
void addOptionalMessage(QVBoxLayout *mainLay)
Add the optional message to the given layout.
Mantid::Kernel::Property * getAlgorithmProperty(const QString &propName) const
Get a pointer to the named property.
This class gives specialised dialog for the LoadRaw algorithm.
Definition: LoadRawDialog.h:33
void browseClicked()
A slot for the browse button clicked signal.
~LoadRawDialog() override
Destructor.
QLineEdit * m_pathBox
The line inputs.
Definition: LoadRawDialog.h:57
LoadRawDialog(QWidget *parent=nullptr)
Constructor.
void initLayout() override
Create the layout.
Base class for properties.
Definition: Property.h:94
virtual std::vector< std::string > allowedValues() const
Returns the set of valid values for this property, if such a set exists.
Definition: Property.cpp:140
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...