Mantid
Loading...
Searching...
No Matches
ListPropertyWidget.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 +
11
12#include <QLabel>
13
14#include <sstream>
15
16using namespace Mantid::Kernel;
17using namespace Mantid::API;
18
19namespace MantidQt::API {
20
21//----------------------------------------------------------------------------------------------
25
26//----------------------------------------------------------------------------------------------
29ListPropertyWidget::ListPropertyWidget(Mantid::Kernel::Property *prop, QWidget *parent, QGridLayout *layout, 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 list box
38 // Check if this is the row that matches the one that we want to link to the
39 // output box
40 m_list = new QListWidget(this);
41 m_list->setToolTip(m_doc);
42 m_list->setSortingEnabled(false);
43 m_list->setSelectionMode(QAbstractItemView::ExtendedSelection);
44 m_widgets.push_back(m_list);
45
46 std::vector<std::string> items = prop->allowedValues();
47 for (auto const &item : items) {
48 m_list->addItem(QString::fromStdString(item));
49 }
50 // Make current value visible
51 this->setValue(QString::fromStdString(m_prop->value()));
52
53 // Make sure the connection comes after updating any values
54 connect(m_list, SIGNAL(itemSelectionChanged()), this, SLOT(userEditedProperty()));
55
56 // Put the combo in column 1
57 m_gridLayout->addWidget(m_list, m_row, 1);
58}
59
60//----------------------------------------------------------------------------------------------
63 auto selectedItems = m_list->selectedItems();
64 std::stringstream ss;
65 for (int i = 0; i < selectedItems.size(); ++i) {
66 if (i != 0) {
67 ss << ",";
68 }
69 ss << selectedItems[i]->text().toStdString();
70 }
71 return QString::fromStdString(ss.str());
72}
73
74//----------------------------------------------------------------------------------------------
79 const QString temp = value.isEmpty() ? QString::fromStdString(m_prop->getDefault()) : value;
80
81 auto items = m_list->findItems(temp, Qt::MatchWildcard);
82 for (auto item : items) {
83 item->setSelected(true);
84 m_list->setCurrentItem(item);
85 m_list->scrollToItem(item);
86 }
87}
88} // namespace MantidQt::API
double value
The value of the point.
Definition FitMW.cpp:51
QListWidget * m_list
List box with the allowed List.
QLabel * m_label
Label (name of the property)
ListPropertyWidget(Mantid::Kernel::Property *prop, QWidget *parent=nullptr, QGridLayout *layout=nullptr, int row=-1)
Constructor.
~ListPropertyWidget() override
Destructor.
void setValueImpl(const QString &value) override
Set the value into the GUI.
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)
QList< 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.
Base class for properties.
Definition Property.h:95
const std::string & name() const
Get the property's name.
Definition Property.cpp:63
virtual std::vector< std::string > allowedValues() const
Returns the set of valid values for this property, if such a set exists.
Definition Property.cpp:155
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.