45 #include <QHBoxLayout> 47 #include <QPushButton> 51 #include "../parser/context.hh" 52 #include "selectionWidget.hh" 70 QHBoxLayout *hL =
new QHBoxLayout;
72 if (_hints.contains (
"names"))
74 QStringList n = _hints[
"names"].split (
',');
77 if (_hints.contains (
"descriptions"))
79 d = _hints[
"descriptions"].split (
',');
80 if (n.length () != d.length ())
84 for (
int i = 0; i < n.length (); i++)
85 names_.append (QPair<QString,QString> (n[i], d[i]));
88 names_.append (QPair<QString,QString> (
"none",
"None"));
90 if (_hints.contains (
"multiple"))
93 if (_hints.contains (
"default"))
94 default_ = _hints[
"default"].split (
',');
98 combo_ =
new QComboBox ();
99 for (
int i = 0; i < names_.size (); i++)
100 combo_->addItem (names_[i].second, names_[i].first);
102 if (default_.length ())
103 combo_->setCurrentIndex (combo_->findData (default_[0]));
105 combo_->setCurrentIndex (0);
107 hL->addWidget (combo_);
111 QGridLayout *gL =
new QGridLayout;
112 for (
int i = 0; i < names_.size (); i++)
114 QCheckBox *c =
new QCheckBox (names_[i].second);
115 checkBox_.append (c);
116 gL->addWidget (c, i / 2, i & 1);
118 if (default_.contains (names_[i].first))
119 c->setChecked (
true);
121 c->setChecked (
false);
132 SelectionWidget::~ SelectionWidget()
145 rv = combo_->itemData (combo_->currentIndex ()).toString ();
151 for (
int i = 0; i < names_.size (); i++)
153 if (checkBox_[i]->isChecked ())
154 sl << names_[i].first;
160 return "\"" + rv +
"\"";
168 if (_from.isEmpty ())
171 combo_->setCurrentIndex (0);
173 foreach (QCheckBox *c, checkBox_)
174 c->setChecked (
false);
179 _from.remove (_from.length () - 1, 1);
181 QStringList values = _from.split (
',');
185 if (values.length ())
186 combo_->setCurrentIndex (combo_->findData (values[0]));
188 combo_->setCurrentIndex (0);
191 for (
int i = 0; i < names_.size (); i++)
193 if (values.contains (names_[i].first))
194 checkBox_[i]->setChecked (
true);
196 checkBox_[i]->setChecked (
false);
207 if (default_.length ())
208 combo_->setCurrentIndex (combo_->findData (default_[0]));
210 combo_->setCurrentIndex (0);
213 for (
int i = 0; i < names_.size (); i++)
215 if (default_.contains (names_[i].first))
216 checkBox_[i]->setChecked (
true);
218 checkBox_[i]->setChecked (
false);
void toDefault()
Reset to default.
QString toValue()
Convert current value to string.
void fromValue(QString _from)
Read value from string.
static bool strToBool(QString _str)
Converts the given string to bool.
SelectionWidget(QMap< QString, QString > &_hints, QString _typeName, QWidget *_parent=NULL)
Constructor.