54 :
API::AlgorithmDialog(parent), m_form(), m_currentFiles(), m_initialHeight(0), m_populating(false),
57 m_autoParseOnInit =
false;
70 m_form.fileWidget->blockSignals(
true);
72 m_form.fileWidget->blockSignals(
false);
77 const auto loaderName =
getAlgorithm()->getPropertyValue(
"LoaderName");
78 QString helpPage = (loaderName.empty()) ? QString(
"Load") : QString::fromStdString(loaderName);
88 if (!
m_form.workspaceEdit->isEnabled())
92 QString fileSuggestion;
93 if (
m_form.fileWidget->isValid()) {
94 if (
m_form.fileWidget->getFilenames().size() == 1)
95 fileSuggestion = QFileInfo(
m_form.fileWidget->getFirstFilename()).completeBaseName();
97 fileSuggestion =
"MultiFiles";
99 m_form.workspaceEdit->setText(fileSuggestion);
124 m_form.fileWidget->findFiles();
134 m_form.propertyLayout->setEnabled(
true);
137 std::string errMess =
getAlgorithm()->getPointerToProperty(
"Filename")->isValid();
138 if (!errMess.empty()) {
142 AlgorithmDialog::accept();
160 settings.beginGroup(
"Mantid/Algorithms/Load");
161 m_form.fileWidget->restoreSettings(FileFinderWidget::readSettings(settings));
164 const std::string &outWsName =
getAlgorithm()->getPropertyValue(
"OutputWorkspace");
165 if (!outWsName.empty()) {
168 m_form.workspaceEdit->setText(QString::fromStdString(outWsName));
192 settings.beginGroup(
"Mantid/Algorithms/Load");
193 m_form.fileWidget->saveSettings(settings,
m_form.fileWidget->captureSettings());
194 AlgorithmDialog::saveInput();
196 API::AlgorithmInputHistory::Instance().storeNewValue(
"Load", std::pair<QString, QString>(
"Filename",
m_currentFiles));
206 if (
m_form.workspaceLayout->count() == 3) {
207 QLayoutItem *validLbl =
m_form.workspaceLayout->takeAt(2);
208 delete validLbl->widget();
211 tie(
m_form.workspaceEdit,
"OutputWorkspace",
m_form.workspaceLayout, readHistory);
212 tie(
m_form.fileWidget,
"Filename",
nullptr, readHistory);
221 if (layout->count() > 2) {
222 int count = layout->count();
224 QLayoutItem *child = layout->takeAt(
count - 1);
225 if (QWidget *w = child->widget()) {
227 }
else if (QLayout *l = child->layout()) {
228 QLayoutItem *subChild(
nullptr);
229 while ((subChild = l->takeAt(0)) !=
nullptr) {
230 subChild->widget()->deleteLater();
233 count = layout->count();
244 m_form.propertyLayout->setEnabled(
false);
246 if (!
m_form.fileWidget->isValid())
250 const QString filenames =
m_form.fileWidget->getUserInput().toString();
256 loadAlg->setPropertyValue(
"Filename", filenames.toStdString());
257 }
catch (std::exception &exc) {
258 m_form.fileWidget->setFileProblem(QString::fromStdString(exc.what()));
259 m_form.propertyLayout->setEnabled(
true);
260 m_form.propertyLayout->activate();
278 const std::vector<Property *> &inputProps = loadAlg->getProperties();
280 for (
auto prop : inputProps) {
281 const QString propName = QString::fromStdString(prop->name());
282 if (propName ==
"OutputWorkspace" || propName ==
"Filename")
289 m_form.propertyLayout->setEnabled(
true);
290 m_form.propertyLayout->activate();
292 const auto screenSize = screen()->availableSize();
293 const auto screenGeometry = screen()->availableGeometry();
294 dialogHeight = std::min(dialogHeight,
static_cast<int>(screenSize.height() * 0.65));
295 this->resize(this->width(), dialogHeight);
296 const auto xPos = screenGeometry.x() + (screenSize.width() - this->width()) / 2;
297 const auto yPos = screenGeometry.y() + (screenSize.height() - this->
height()) / 2;
298 this->move(xPos, yPos);
302 QString wsName(
m_form.workspaceEdit->text());
303 if (!wsName.isEmpty())
316 QString propName = QString::fromStdString(prop->
name());
317 QWidget *inputWidget(
nullptr);
318 QHBoxLayout *widgetLayout(
nullptr);
319 bool addValidator(
true);
322 if (
const auto *fileType =
dynamic_cast<const FileProperty *
>(prop)) {
324 inputWidget = fileFinder;
325 fileFinder->setLabelText(propName);
326 fileFinder->isForRunFiles(
false);
327 fileFinder->isOptional(fileType->isOptional());
328 fileFinder->doMultiEntry(
false);
329 addValidator =
false;
330 propertyLayout->addWidget(inputWidget);
332 QLabel *nameLbl =
new QLabel(propName, parent);
333 nameLbl->setToolTip(QString::fromStdString(prop->
documentation()));
335 auto *checkBox =
new QCheckBox(parent);
336 inputWidget = checkBox;
337 addValidator =
false;
341 auto *optionsBox =
new QComboBox(parent);
342 inputWidget = optionsBox;
344 std::vector<std::string>::const_iterator vend = items.end();
345 for (std::vector<std::string>::const_iterator vitr = items.begin(); vitr != vend; ++vitr) {
346 optionsBox->addItem(QString::fromStdString(*vitr));
349 int index = optionsBox->findText(QString::fromStdString(prop->
value()));
351 optionsBox->setCurrentIndex(
index);
353 addValidator =
false;
357 auto *textBox =
new QLineEdit(parent);
358 inputWidget = textBox;
360 textBox->setEchoMode(QLineEdit::Password);
363 nameLbl->setBuddy(inputWidget);
364 widgetLayout =
new QHBoxLayout();
365 widgetLayout->addWidget(nameLbl);
366 widgetLayout->addWidget(inputWidget);
367 propertyLayout->addLayout(widgetLayout);
371 tie(inputWidget, propName, widgetLayout);
373 tie(inputWidget, propName,
nullptr);
375 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.