Mantid
Loading...
Searching...
No Matches
OptionsPropertyWidget.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 +
10#include "MantidKernel/System.h"
11#include <QComboBox>
12#include <QCompleter>
13#include <QLabel>
14#include <QLineEdit>
15
16using namespace Mantid::Kernel;
17using namespace Mantid::API;
18
19namespace MantidQt::API {
20//----------------------------------------------------------------------------------------------
24
25//----------------------------------------------------------------------------------------------
29 int row)
30 : PropertyWidget(prop, parent, layout, row) {
31 // Label at column 0
32 m_label = new QLabel(QString::fromStdString(prop->name()), m_parent);
33 m_label->setToolTip(m_doc);
34 m_gridLayout->addWidget(m_label, m_row, 0);
35 m_widgets.push_back(m_label);
36
37 // It is a choice of certain allowed values and can use a combination box
38 // Check if this is the row that matches the one that we want to link to the
39 // output box and used the saved combo box
40 m_combo = new QComboBox(this);
41 m_combo->setToolTip(m_doc);
42 if (std::string(prop->type()).find("Workspace") != std::string::npos) {
43 m_combo->setEditable(true);
44 m_combo->setInsertPolicy(QComboBox::NoInsert);
45 m_combo->completer()->setCompletionMode(QCompleter::PopupCompletion);
46 connect(m_combo->lineEdit(), SIGNAL(editingFinished()), SLOT(editingFinished()));
47 }
48 m_combo->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLengthWithIcon);
49 m_combo->setMinimumContentsLength(20);
50 m_widgets.push_back(m_combo);
51
52 std::vector<std::string> items = prop->allowedValues();
53 for (auto &item : items) {
54 m_combo->addItem(QString::fromStdString(item));
55 }
56 // Make current value visible
57 this->setValue(QString::fromStdString(m_prop->value()));
58
59 // Make sure the connection comes after updating any values
60 connect(m_combo, SIGNAL(currentIndexChanged(int)), this, SLOT(userEditedProperty()));
61
62 // Put the combo in column 1
63 m_gridLayout->addWidget(m_combo, m_row, 1);
64}
65
66//----------------------------------------------------------------------------------------------
68QString OptionsPropertyWidget::getValue() const { return m_combo->currentText(); }
69
70//----------------------------------------------------------------------------------------------
75 const QString temp = value.isEmpty() ? QString::fromStdString(m_prop->getDefault()) : value;
76
77 int index = m_combo->findText(temp);
78 if (index >= 0)
79 m_combo->setCurrentIndex(index);
80}
81
82//----------------------------------------------------------------------------------------------
85 auto value = m_combo->currentText();
86 const QString temp = value.isEmpty() ? QString::fromStdString(m_prop->getDefault()) : value;
87 int index = m_combo->findText(temp);
88 if (index >= 0)
89 m_combo->setCurrentIndex(index);
90 else {
92 }
93}
94
95} // namespace MantidQt::API
double value
The value of the point.
Definition: FitMW.cpp:51
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
~OptionsPropertyWidget() override
Destructor.
QComboBox * m_combo
Combo box with the allowed options.
void setValueImpl(const QString &value) override
Set the value into the GUI.
void editingFinished()
Performs validation of the inputs when editing is finished.
OptionsPropertyWidget(Mantid::Kernel::Property *prop, QWidget *parent=nullptr, QGridLayout *layout=nullptr, int row=-1)
Constructor.
QLabel * m_label
Label (name of the property)
Base class for widgets that will set Mantid::Kernel::Property* types.
void setValue(const QString &value)
Set the value of the property given into the GUI state.
QGridLayout * m_gridLayout
Grid layout of the dialog to which we are adding widgets.
QString m_doc
Documentation string (tooltip)
QVector< QWidget * > m_widgets
All contained widgets.
QWidget * m_parent
Parent widget to add sub-widgets to.
void userEditedProperty()
To be called when a user edits a property, as opposed to one being set programmatically.
int m_row
If using the GridLayout, this is the row where the widget was inserted.
void updateIconVisibility(const QString &error="")
Update which icons should be shown.
Mantid::Kernel::Property * m_prop
Property being looked at. This is NOT owned by the widget.
Base class for properties.
Definition: Property.h:94
const std::string & name() const
Get the property's name.
Definition: Property.cpp:60
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
const std::string type() const
Returns the type of the property as a string.
Definition: Property.cpp:76
virtual std::string getDefault() const =0
Get the default value for the property which is the value the property was initialised with.
virtual std::string value() const =0
Returns the value of the property as a string.