Commit c75cb788 authored by Victor Yacovlev's avatar Victor Yacovlev

Choice combo box for actor settings entry

parent 0f17cf50
......@@ -194,7 +194,8 @@ SETTINGS_TYPES = {
"char": "Char",
"bool": "Bool",
"color": "Color",
"font": "Font"
"font": "Font",
"choice": "Choice",
}
......@@ -1099,6 +1100,10 @@ class SettingsEntry:
self._order = json_entry["order"]
else:
self._order = 99999999
if "items" in json_entry:
self._items = json_entry["items"]
else:
self._items = None
def get_entry_cpp_implementation(self, map_to_add):
"""
......@@ -1128,6 +1133,10 @@ class SettingsEntry:
maximum = "QVariant::Invalid"
else:
maximum = unicode(self._maximum)
items = "QStringList()";
if self._items:
for item in self._items:
items += " << QString::fromUtf8(\"" + item + "\")"
return """
{
Widgets::DeclarativeSettingsPage::Entry entry;
......@@ -1136,10 +1145,11 @@ class SettingsEntry:
entry.defaultValue = %s;
entry.minimumValue = %s;
entry.maximumValue = %s;
entry.items = %s;
entry.displayOrder = %s;
%s["%s"] = entry;
}
""" % (title, typee, default, minimum, maximum, self._order, map_to_add, self._key)
""" % (title, typee, default, minimum, maximum, items, self._order, map_to_add, self._key)
class Settings:
......
......@@ -37,6 +37,9 @@ DeclarativeSettingsPage::DeclarativeSettingsPage(
else if (entry.type==String) {
pImpl_->addStringField(key, entry);
}
else if (entry.type==Choice) {
pImpl_->addChoiceField(key, entry);
}
else {
qFatal("Not implemented");
}
......
......@@ -24,7 +24,7 @@ class WIDGETS_EXPORT DeclarativeSettingsPage
friend class DeclarativeSettingsPageImpl;
Q_OBJECT
public:
enum Type { Integer, Double, String, Char, Bool, Color, Font };
enum Type { Integer, Double, String, Char, Bool, Color, Font, Choice };
struct Entry {
Type type;
......@@ -32,6 +32,7 @@ public:
QVariant defaultValue;
QVariant minimumValue;
QVariant maximumValue;
QStringList items;
qreal displayOrder;
QString key;
......
#include "declarativesettingspage_impl.h"
#include <QCheckBox>
#include <QComboBox>
#include <QDoubleSpinBox>
#include <QLineEdit>
#include <QSpinBox>
namespace Widgets {
DeclarativeSettingsPageImpl::DeclarativeSettingsPageImpl(DeclarativeSettingsPage * parent)
......@@ -53,6 +59,17 @@ void DeclarativeSettingsPageImpl::init()
if (control)
control->setChecked(value);
}
else if (entry.type==DeclarativeSettingsPage::Choice) {
QComboBox * control = 0;
if (widgets_.contains(key) && QString(widgets_[key]->metaObject()->className())=="QComboBox") {
control = qobject_cast<QComboBox*>(widgets_[key]);
}
if (control) {
const QString defaultText = control->itemText(entry.defaultValue.toInt());
const QString value = settings_->value(key, defaultText).toString();
control->setCurrentText(value);
}
}
else {
qFatal("Not implemented");
}
......@@ -103,6 +120,15 @@ void DeclarativeSettingsPageImpl::resetToDefaults()
if (control)
control->setChecked(value);
}
else if (entry.type==DeclarativeSettingsPage::Choice) {
QComboBox * control = 0;
if (widgets_.contains(key) && QString(widgets_[key]->metaObject()->className())=="QComboBox") {
control = qobject_cast<QComboBox*>(widgets_[key]);
}
if (control) {
control->setCurrentIndex(entry.defaultValue.toInt());
}
}
else {
qFatal("Not implemented");
}
......@@ -149,6 +175,14 @@ void DeclarativeSettingsPageImpl::accept()
if (control)
settings_->setValue(key, control->isChecked());
}
else if (entry.type==DeclarativeSettingsPage::Choice) {
QComboBox * control = 0;
if (widgets_.contains(key) && QString(widgets_[key]->metaObject()->className())=="QComboBox") {
control = qobject_cast<QComboBox*>(widgets_[key]);
}
if (control)
settings_->setValue(key, control->currentText());
}
else {
qFatal("Not implemented");
}
......@@ -192,6 +226,16 @@ void DeclarativeSettingsPageImpl::addStringField(const QString &key, const Decla
addField(entry.title, control);
}
void DeclarativeSettingsPageImpl::addChoiceField(const QString &key, const DeclarativeSettingsPage::Entry &entry)
{
QComboBox * control = new QComboBox(pClass_);
control->addItems(entry.items);
if (entry.defaultValue.isValid())
control->setCurrentIndex(entry.defaultValue.toInt());
widgets_[key] = control;
addField(entry.title, control);
}
void DeclarativeSettingsPageImpl::addBoolField(const QString &key, const DeclarativeSettingsPage::Entry &entry)
{
QCheckBox * control = new QCheckBox(entry.title, pClass_);
......
......@@ -28,6 +28,7 @@ private /*methods*/:
void addRealField(const QString & key, const DeclarativeSettingsPage::Entry & entry);
void addBoolField(const QString & key, const DeclarativeSettingsPage::Entry & entry);
void addStringField(const QString & key, const DeclarativeSettingsPage::Entry & entry);
void addChoiceField(const QString & key, const DeclarativeSettingsPage::Entry & entry);
void addField(const QString & labelText, QWidget * controlWidget);
private slots:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment