16#include <QDesktopWidget>
65 :
API::AlgorithmDialog(parent), m_form(), m_currentFiles(), m_initialHeight(0), m_populating(false) {
67 m_autoParseOnInit =
false;
80 m_form.fileWidget->blockSignals(
true);
82 m_form.fileWidget->blockSignals(
false);
87 const auto loaderName =
getAlgorithm()->getPropertyValue(
"LoaderName");
88 QString helpPage = (loaderName.empty()) ? QString(
"Load") : QString::fromStdString(loaderName);
98 if (!
m_form.workspaceEdit->isEnabled())
102 QString fileSuggestion;
103 if (
m_form.fileWidget->isValid()) {
104 if (
m_form.fileWidget->getFilenames().size() == 1)
105 fileSuggestion = QFileInfo(
m_form.fileWidget->getFirstFilename()).completeBaseName();
107 fileSuggestion =
"MultiFiles";
109 m_form.workspaceEdit->setText(fileSuggestion);
138 m_form.fileWidget->findFiles();
140 QApplication::instance()->processEvents();
143 m_form.propertyLayout->setEnabled(
true);
146 std::string errMess =
getAlgorithm()->getPointerToProperty(
"Filename")->isValid();
147 if (!errMess.empty()) {
151 AlgorithmDialog::accept();
167 m_form.fileWidget->readSettings(
"Mantid/Algorithms/Load");
170 const std::string &outWsName =
getAlgorithm()->getPropertyValue(
"OutputWorkspace");
171 if (!outWsName.empty()) {
174 m_form.workspaceEdit->setText(QString::fromStdString(outWsName));
195 m_form.fileWidget->saveSettings(
"Mantid/Algorithms/Load");
196 AlgorithmDialog::saveInput();
208 if (
m_form.workspaceLayout->count() == 3) {
209 QLayoutItem *validLbl =
m_form.workspaceLayout->takeAt(2);
210 delete validLbl->widget();
213 tie(
m_form.workspaceEdit,
"OutputWorkspace",
m_form.workspaceLayout, readHistory);
214 tie(
m_form.fileWidget,
"Filename",
nullptr, readHistory);
223 if (layout->count() > 2) {
224 int count = layout->count();
226 QLayoutItem *child = layout->takeAt(
count - 1);
227 if (QWidget *w = child->widget()) {
229 }
else if (QLayout *l = child->layout()) {
230 QLayoutItem *subChild(
nullptr);
231 while ((subChild = l->takeAt(0)) !=
nullptr) {
232 subChild->widget()->deleteLater();
235 count = layout->count();
246 m_form.propertyLayout->setEnabled(
false);
248 if (!
m_form.fileWidget->isValid())
252 const QString filenames =
m_form.fileWidget->getUserInput().toString();
258 loadAlg->setPropertyValue(
"Filename", filenames.toStdString());
259 }
catch (std::exception &exc) {
260 m_form.fileWidget->setFileProblem(QString::fromStdString(exc.what()));
261 m_form.propertyLayout->setEnabled(
true);
262 m_form.propertyLayout->activate();
280 const std::vector<Property *> &inputProps = loadAlg->getProperties();
282 for (
auto prop : inputProps) {
283 const QString propName = QString::fromStdString(prop->name());
284 if (propName ==
"OutputWorkspace" || propName ==
"Filename")
291 m_form.propertyLayout->setEnabled(
true);
292 m_form.propertyLayout->activate();
294 const int screenHeight = QApplication::desktop()->height();
297 if (dialogHeight < 0.8 * screenHeight)
298 this->resize(this->width(), dialogHeight + 20);
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)
void tieStaticWidgets(const bool readHistory)
Tie static widgets to their properties.
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.
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 enableLoadRequests()
Accept requests to load until they are disabled.
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.
void disableLoadRequests()
Ignore requests to load until they are re-enabled.
QString m_currentFiles
The current file.
PreventLoadRequests(LoadDialog &dialog)
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.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...