Mantid
Loading...
Searching...
No Matches
TextPropertyWidget.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
11using namespace Mantid::Kernel;
12
13namespace MantidQt::API {
14
15//----------------------------------------------------------------------------------------------
18TextPropertyWidget::TextPropertyWidget(Mantid::Kernel::Property *prop, QWidget *parent, QGridLayout *layout, int row)
19 : PropertyWidget(prop, parent, layout, row) {
20 // Label at column 0
21 m_label = new QLabel(QString::fromStdString(prop->name()), m_parent);
22 m_label->setToolTip(m_doc);
23 setLabelFont(prop, m_label);
24 m_gridLayout->addWidget(m_label, m_row, 0);
25 m_widgets.push_back(m_label);
26
27 // Text box at column 1
28 m_textbox = new QLineEdit(m_parent);
29 m_textbox->setToolTip(m_doc);
31 // Make current value visible
32 this->setValue(QString::fromStdString(m_prop->value()));
33 // Make sure the connection comes after updating any values
34 connect(m_textbox, SIGNAL(editingFinished()), this, SLOT(userEditedProperty()));
35 m_gridLayout->addWidget(m_textbox, m_row, 1);
36 m_widgets.push_back(m_textbox);
37
38 // Check if this is a masked property
41 // Make it echo those little stars
42 if (maskedProp)
43 m_textbox->setEchoMode(QLineEdit::Password);
44}
45
46//----------------------------------------------------------------------------------------------
50
51//----------------------------------------------------------------------------------------------
53QString TextPropertyWidget::getValue() const { return m_textbox->text(); }
54
55//----------------------------------------------------------------------------------------------
59void TextPropertyWidget::setValueImpl(const QString &value) { m_textbox->setText(value); }
60
61} // namespace MantidQt::API
double value
The value of the point.
Definition: FitMW.cpp:51
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.
static void setFieldPlaceholderText(Mantid::Kernel::Property *prop, QLineEdit *field)
Set the placeholder text of the given field based on the default value of the given property.
static void setLabelFont(Mantid::Kernel::Property *prop, QWidget *label)
Set the font of the given label based on the optional/required status of the given property.
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.
void setValueImpl(const QString &value) override
Set the value into the GUI.
QLineEdit * m_textbox
The text box to edit.
QLabel * m_label
Label (name of the property)
~TextPropertyWidget() override
Destructor.
TextPropertyWidget(Mantid::Kernel::Property *prop, QWidget *parent=nullptr, QGridLayout *layout=nullptr, int row=-1)
Constructor.
A property class for masking the properties.
Base class for properties.
Definition: Property.h:94
const std::string & name() const
Get the property's name.
Definition: Property.cpp:60
virtual std::string value() const =0
Returns the value of the property as a string.