53 :
API::AlgorithmDialog(parent), m_form(), m_currentFiles(), m_initialHeight(0), m_populating(false),
56 m_autoParseOnInit =
false;
69 m_form.fileWidget->blockSignals(
true);
71 m_form.fileWidget->blockSignals(
false);
76 const auto loaderName =
getAlgorithm()->getPropertyValue(
"LoaderName");
77 QString helpPage = (loaderName.empty()) ? QString(
"Load") : QString::fromStdString(loaderName);
87 if (!
m_form.workspaceEdit->isEnabled())
91 QString fileSuggestion;
92 if (
m_form.fileWidget->isValid()) {
93 if (
m_form.fileWidget->getFilenames().size() == 1)
94 fileSuggestion = QFileInfo(
m_form.fileWidget->getFirstFilename()).completeBaseName();
96 fileSuggestion =
"MultiFiles";
98 m_form.workspaceEdit->setText(fileSuggestion);
123 m_form.fileWidget->findFiles();
133 m_form.propertyLayout->setEnabled(
true);
136 std::string errMess =
getAlgorithm()->getPointerToProperty(
"Filename")->isValid();
137 if (!errMess.empty()) {
141 AlgorithmDialog::accept();
158 m_form.fileWidget->readSettings(
"Mantid/Algorithms/Load");
161 const std::string &outWsName =
getAlgorithm()->getPropertyValue(
"OutputWorkspace");
162 if (!outWsName.empty()) {
165 m_form.workspaceEdit->setText(QString::fromStdString(outWsName));
188 m_form.fileWidget->saveSettings(
"Mantid/Algorithms/Load");
189 AlgorithmDialog::saveInput();
191 API::AlgorithmInputHistory::Instance().storeNewValue(
"Load", QPair<QString, QString>(
"Filename",
m_currentFiles));
201 if (
m_form.workspaceLayout->count() == 3) {
202 QLayoutItem *validLbl =
m_form.workspaceLayout->takeAt(2);
203 delete validLbl->widget();
206 tie(
m_form.workspaceEdit,
"OutputWorkspace",
m_form.workspaceLayout, readHistory);
207 tie(
m_form.fileWidget,
"Filename",
nullptr, readHistory);
216 if (layout->count() > 2) {
217 int count = layout->count();
219 QLayoutItem *child = layout->takeAt(
count - 1);
220 if (QWidget *w = child->widget()) {
222 }
else if (QLayout *l = child->layout()) {
223 QLayoutItem *subChild(
nullptr);
224 while ((subChild = l->takeAt(0)) !=
nullptr) {
225 subChild->widget()->deleteLater();
228 count = layout->count();
239 m_form.propertyLayout->setEnabled(
false);
241 if (!
m_form.fileWidget->isValid())
245 const QString filenames =
m_form.fileWidget->getUserInput().toString();
251 loadAlg->setPropertyValue(
"Filename", filenames.toStdString());
252 }
catch (std::exception &exc) {
253 m_form.fileWidget->setFileProblem(QString::fromStdString(exc.what()));
254 m_form.propertyLayout->setEnabled(
true);
255 m_form.propertyLayout->activate();
273 const std::vector<Property *> &inputProps = loadAlg->getProperties();
275 for (
auto prop : inputProps) {
276 const QString propName = QString::fromStdString(prop->name());
277 if (propName ==
"OutputWorkspace" || propName ==
"Filename")
284 m_form.propertyLayout->setEnabled(
true);
285 m_form.propertyLayout->activate();
287 const auto screenSize = screen()->availableSize();
288 const auto screenGeometry = screen()->availableGeometry();
289 dialogHeight = std::min(dialogHeight,
static_cast<int>(screenSize.height() * 0.65));
290 this->resize(this->width(), dialogHeight);
291 const auto xPos = screenGeometry.x() + (screenSize.width() - this->width()) / 2;
292 const auto yPos = screenGeometry.y() + (screenSize.height() - this->
height()) / 2;
293 this->move(xPos, yPos);
297 QString wsName(
m_form.workspaceEdit->text());
298 if (!wsName.isEmpty())
311 QString propName = QString::fromStdString(prop->
name());
312 QWidget *inputWidget(
nullptr);
313 QHBoxLayout *widgetLayout(
nullptr);
314 bool addValidator(
true);
317 if (
const auto *fileType =
dynamic_cast<const FileProperty *
>(prop)) {
319 inputWidget = fileFinder;
320 fileFinder->setLabelText(propName);
321 fileFinder->isForRunFiles(
false);
322 fileFinder->isOptional(fileType->isOptional());
323 fileFinder->doMultiEntry(
false);
324 addValidator =
false;
325 propertyLayout->addWidget(inputWidget);
327 QLabel *nameLbl =
new QLabel(propName, parent);
328 nameLbl->setToolTip(QString::fromStdString(prop->
documentation()));
330 auto *checkBox =
new QCheckBox(parent);
331 inputWidget = checkBox;
332 addValidator =
false;
336 auto *optionsBox =
new QComboBox(parent);
337 inputWidget = optionsBox;
339 std::vector<std::string>::const_iterator vend = items.end();
340 for (std::vector<std::string>::const_iterator vitr = items.begin(); vitr != vend; ++vitr) {
341 optionsBox->addItem(QString::fromStdString(*vitr));
344 int index = optionsBox->findText(QString::fromStdString(prop->
value()));
346 optionsBox->setCurrentIndex(
index);
348 addValidator =
false;
352 auto *textBox =
new QLineEdit(parent);
353 inputWidget = textBox;
355 textBox->setEchoMode(QLineEdit::Password);
358 nameLbl->setBuddy(inputWidget);
359 widgetLayout =
new QHBoxLayout();
360 widgetLayout->addWidget(nameLbl);
361 widgetLayout->addWidget(inputWidget);
362 propertyLayout->addLayout(widgetLayout);
366 tie(inputWidget, propName, widgetLayout);
368 tie(inputWidget, propName,
nullptr);
370 return inputWidget->geometry().height();
#define DECLARE_DIALOG(classname)
std::map< DeltaEMode::Type, std::string > index
bool isMessageAvailable() const
Is there a message string available.
void setAlgorithm(const Mantid::API::IAlgorithm_sptr &)
The following methods were made public for testing in GenericDialogDemo.cpp.
bool setPropertyValues(const QStringList &skipList=QStringList())
Set properties on this algorithm by pulling values from the tied widgets.
bool requiresUserInput(const QString &propName) const
Return a true if the given property requires user input.
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.
void storePropertyValue(const QString &name, const QString &value)
Adds a property (name,value) pair to the stored map.
QWidget * tie(QWidget *widget, const QString &property, QLayout *parent_layout=nullptr, bool readHistory=true)
Tie a widget to a property.
Mantid::API::IAlgorithm_sptr getAlgorithm() const
Get the algorithm pointer.
const QString & getOptionalMessage() const
Get the message string.
static void showAlgorithm(const std::string &name=std::string(), const int version=-1)
This class gives specialised dialog for the Load algorithm.
void tieStaticWidgets(const bool readHistory)
Tie static widgets to their properties.
void resultInspectionFinished()
Accept the load dialog when user input is inspected and is valid.
void saveInput() override
Save the input history.
int m_initialHeight
The initial height.
Ui::LoadDialog m_form
Form.
int createWidgetsForProperty(const Mantid::Kernel::Property *prop, QVBoxLayout *propertyLayout, QWidget *parent)
Create the widgets for a given property.
void helpClicked() override
Override the help button clicked method.
void enableNameSuggestion(const bool on=false)
Connect/Disconnect the signal that updates the workspace name with a suggested value.
void accept() override
Override accept() slot.
bool m_userAccept
Flag to indicate the user accepted the load dialog.
void suggestWSName()
Suggest a workspace name from the file.
void initLayout() override
Initialize the layout.
void createDynamicLayout()
Create.
bool m_populating
Flag to indicating if we are populating the dialog.
void createDynamicWidgets()
Create the widgets and layouts that are dynamic, i.e they depend on the specific load algorithm.
void removeOldInputWidgets(QVBoxLayout *layout)
Clears all of the widgets from the old layout.
QString m_currentFiles
The current file.
A specialized class for dealing with file properties.
A property class for masking the properties.
The concrete, templated class for properties.
Base class for properties.
const std::string & documentation() const
Get the property's documentation string.
const std::string & name() const
Get the property's name.
virtual std::vector< std::string > allowedValues() const
Returns the set of valid values for this property, if such a set exists.
virtual std::string value() const =0
Returns the value of the property as a string.