16#include <QDesktopWidget>
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();
159 m_form.fileWidget->readSettings(
"Mantid/Algorithms/Load");
162 const std::string &outWsName =
getAlgorithm()->getPropertyValue(
"OutputWorkspace");
163 if (!outWsName.empty()) {
166 m_form.workspaceEdit->setText(QString::fromStdString(outWsName));
189 m_form.fileWidget->saveSettings(
"Mantid/Algorithms/Load");
190 AlgorithmDialog::saveInput();
192 API::AlgorithmInputHistory::Instance().storeNewValue(
"Load", QPair<QString, QString>(
"Filename",
m_currentFiles));
202 if (
m_form.workspaceLayout->count() == 3) {
203 QLayoutItem *validLbl =
m_form.workspaceLayout->takeAt(2);
204 delete validLbl->widget();
207 tie(
m_form.workspaceEdit,
"OutputWorkspace",
m_form.workspaceLayout, readHistory);
208 tie(
m_form.fileWidget,
"Filename",
nullptr, readHistory);
217 if (layout->count() > 2) {
218 int count = layout->count();
220 QLayoutItem *child = layout->takeAt(
count - 1);
221 if (QWidget *w = child->widget()) {
223 }
else if (QLayout *l = child->layout()) {
224 QLayoutItem *subChild(
nullptr);
225 while ((subChild = l->takeAt(0)) !=
nullptr) {
226 subChild->widget()->deleteLater();
229 count = layout->count();
240 m_form.propertyLayout->setEnabled(
false);
242 if (!
m_form.fileWidget->isValid())
246 const QString filenames =
m_form.fileWidget->getUserInput().toString();
252 loadAlg->setPropertyValue(
"Filename", filenames.toStdString());
253 }
catch (std::exception &exc) {
254 m_form.fileWidget->setFileProblem(QString::fromStdString(exc.what()));
255 m_form.propertyLayout->setEnabled(
true);
256 m_form.propertyLayout->activate();
274 const std::vector<Property *> &inputProps = loadAlg->getProperties();
276 for (
auto prop : inputProps) {
277 const QString propName = QString::fromStdString(prop->name());
278 if (propName ==
"OutputWorkspace" || propName ==
"Filename")
285 m_form.propertyLayout->setEnabled(
true);
286 m_form.propertyLayout->activate();
288 const auto screenSize = screen()->availableSize();
289 const auto screenGeometry = screen()->availableGeometry();
290 dialogHeight = std::min(dialogHeight,
static_cast<int>(screenSize.height() * 0.65));
291 this->resize(this->width(), dialogHeight);
292 const auto xPos = screenGeometry.x() + (screenSize.width() - this->width()) / 2;
293 const auto yPos = screenGeometry.y() + (screenSize.height() - this->
height()) / 2;
294 this->move(xPos, yPos);
298 QString wsName(
m_form.workspaceEdit->text());
299 if (!wsName.isEmpty())
312 QString propName = QString::fromStdString(prop->
name());
313 QWidget *inputWidget(
nullptr);
314 QHBoxLayout *widgetLayout(
nullptr);
315 bool addValidator(
true);
318 if (
const auto *fileType =
dynamic_cast<const FileProperty *
>(prop)) {
320 inputWidget = fileFinder;
321 fileFinder->setLabelText(propName);
322 fileFinder->isForRunFiles(
false);
323 fileFinder->isOptional(fileType->isOptional());
324 fileFinder->doMultiEntry(
false);
325 addValidator =
false;
326 propertyLayout->addWidget(inputWidget);
328 QLabel *nameLbl =
new QLabel(propName, parent);
329 nameLbl->setToolTip(QString::fromStdString(prop->
documentation()));
331 auto *checkBox =
new QCheckBox(parent);
332 inputWidget = checkBox;
333 addValidator =
false;
337 auto *optionsBox =
new QComboBox(parent);
338 inputWidget = optionsBox;
340 std::vector<std::string>::const_iterator vend = items.end();
341 for (std::vector<std::string>::const_iterator vitr = items.begin(); vitr != vend; ++vitr) {
342 optionsBox->addItem(QString::fromStdString(*vitr));
345 int index = optionsBox->findText(QString::fromStdString(prop->
value()));
347 optionsBox->setCurrentIndex(
index);
349 addValidator =
false;
353 auto *textBox =
new QLineEdit(parent);
354 inputWidget = textBox;
356 textBox->setEchoMode(QLineEdit::Password);
359 nameLbl->setBuddy(inputWidget);
360 widgetLayout =
new QHBoxLayout();
361 widgetLayout->addWidget(nameLbl);
362 widgetLayout->addWidget(inputWidget);
363 propertyLayout->addLayout(widgetLayout);
367 tie(inputWidget, propName, widgetLayout);
369 tie(inputWidget, propName,
nullptr);
371 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.