51 #include <QHBoxLayout> 53 #include <QPushButton> 57 #include "../parser/context.hh" 58 #include "selectionWidget.hh" 76 QHBoxLayout *hL =
new QHBoxLayout;
78 if (_hints.contains (
"names"))
80 QStringList n = _hints[
"names"].split (
',');
83 if (_hints.contains (
"descriptions"))
85 d = _hints[
"descriptions"].split (
',');
86 if (n.length () != d.length ())
90 for (
int i = 0; i < n.length (); i++)
91 names_.append (QPair<QString,QString> (n[i], d[i]));
94 names_.append (QPair<QString,QString> (
"none",
"None"));
96 if (_hints.contains (
"multiple"))
99 if (_hints.contains (
"default"))
100 default_ = _hints[
"default"].split (
',');
104 combo_ =
new QComboBox ();
105 for (
int i = 0; i < names_.size (); i++)
106 combo_->addItem (names_[i].second, names_[i].first);
108 if (default_.length ())
109 combo_->setCurrentIndex (combo_->findData (default_[0]));
111 combo_->setCurrentIndex (0);
113 hL->addWidget (combo_);
117 QGridLayout *gL =
new QGridLayout;
118 for (
int i = 0; i < names_.size (); i++)
120 QCheckBox *c =
new QCheckBox (names_[i].second);
121 checkBox_.append (c);
122 gL->addWidget (c, i / 2, i & 1);
124 if (default_.contains (names_[i].first))
125 c->setChecked (
true);
127 c->setChecked (
false);
151 rv = combo_->itemData (combo_->currentIndex ()).toString ();
157 for (
int i = 0; i < names_.size (); i++)
159 if (checkBox_[i]->isChecked ())
160 sl << names_[i].first;
166 return "\"" + rv +
"\"";
174 if (_from.isEmpty ())
177 combo_->setCurrentIndex (0);
179 foreach (QCheckBox *c, checkBox_)
180 c->setChecked (
false);
185 _from.remove (_from.length () - 1, 1);
187 QStringList values = _from.split (
',');
191 if (values.length ())
192 combo_->setCurrentIndex (combo_->findData (values[0]));
194 combo_->setCurrentIndex (0);
197 for (
int i = 0; i < names_.size (); i++)
199 if (values.contains (names_[i].first))
200 checkBox_[i]->setChecked (
true);
202 checkBox_[i]->setChecked (
false);
213 if (default_.length ())
214 combo_->setCurrentIndex (combo_->findData (default_[0]));
216 combo_->setCurrentIndex (0);
219 for (
int i = 0; i < names_.size (); i++)
221 if (default_.contains (names_[i].first))
222 checkBox_[i]->setChecked (
true);
224 checkBox_[i]->setChecked (
false);
static bool strToBool(QString _str)
Converts the given string to bool.
SelectionWidget(QMap< QString, QString > &_hints, QString _typeName, QWidget *_parent=NULL)
Constructor.
void toDefault()
Reset to default.
QString toValue()
Convert current value to string.
void fromValue(QString _from)
Read value from string.
~SelectionWidget()
Destructor.