Mantid
Loading...
Searching...
No Matches
BoolPropertyWidget.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 +
9
10using namespace Mantid::Kernel;
11
12namespace MantidQt::API {
13
14//----------------------------------------------------------------------------------------------
18 QGridLayout *layout, int row)
19 : PropertyWidget(prop, parent, layout, row) {
20 m_checkBox = new QCheckBox(QString::fromStdString(prop->name()), m_parent);
21 m_checkBox->setToolTip(m_doc);
22 // Make current value visible
23 this->setValue(QString::fromStdString(m_prop->value()));
24
25 // Make sure the connection comes after updating any values
26 connect(m_checkBox, SIGNAL(stateChanged(int)), this, SLOT(userEditedProperty()));
27 m_widgets.push_back(m_checkBox);
28
29 // Add the checkbox at column 1
30 m_gridLayout->addWidget(m_checkBox, m_row, 1);
31}
32
33//----------------------------------------------------------------------------------------------
37
38//----------------------------------------------------------------------------------------------
41 if (m_checkBox->isChecked())
42 return "1";
43 else
44 return "0";
45}
46
47//----------------------------------------------------------------------------------------------
52 const QString temp = value.isEmpty() ? QString::fromStdString(m_prop->getDefault()) : value;
53
54 if (temp == "0")
55 m_checkBox->setCheckState(Qt::Unchecked);
56 else
57 m_checkBox->setCheckState(Qt::Checked);
58}
59} // namespace MantidQt::API
double value
The value of the point.
Definition: FitMW.cpp:51
void setValueImpl(const QString &value) override
Set the value into the GUI.
BoolPropertyWidget(Mantid::Kernel::PropertyWithValue< bool > *prop, QWidget *parent=nullptr, QGridLayout *layout=nullptr, int row=-1)
Constructor.
~BoolPropertyWidget() override
Destructor.
QCheckBox * m_checkBox
Checkbox widget.
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.
Mantid::Kernel::Property * m_prop
Property being looked at. This is NOT owned by the widget.
The concrete, templated class for properties.
const std::string & name() const
Get the property's name.
Definition: Property.cpp:60
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.