3 // Author: Frantisek Vacek <fanda.vacek@volny.cz>, (C) 2010
5 // Copyright: See COPYING file that comes with this distribution
8 #include "qfprototypedobjectitemeditorfactory.h"
9 #include "qfprototypedobjectitemeditor.h"
11 #include <qfprototypedobject.h>
16 #include <qflogcust.h>
18 //=================================================
19 // QFPrototypedObjectItemEditorFactory
20 //=================================================
21 QFPrototypedObjectItemEditorFactory::QFPrototypedObjectItemEditorFactory()
22 : QItemEditorFactory()
26 QFPrototypedObjectItemEditorFactory::~QFPrototypedObjectItemEditorFactory()
30 QWidget
* QFPrototypedObjectItemEditorFactory::createEditor(const QVariantMap
&opts
, QWidget
*parent
) const
34 QString delegate_type
= opts
.value(QFPrototypedObject::DELEGATE_KEY
).toString();
35 if(delegate_type
.isEmpty()) delegate_type
= opts
.value(QFPrototypedObject::TYPE_KEY
).toString();
36 qfTrash() << "\t delegate_type:" << delegate_type
;
37 if(delegate_type
== "list") {
38 QVariantMap object_opts
= opts
.value(QFPrototypedObject::OPTIONS_KEY
).toMap();
39 QVariantList items
= object_opts
.value("items").toList();
40 QComboBox
*cbx
= new QComboBox(parent
);
41 foreach(QVariant item
, items
) {
44 QVariantList lst
= item
.toList();
46 caption
= item
.toString();
47 value
= item
.toString();
51 caption
= lst
.value(1).toString();
53 cbx
->addItem(caption
, value
);
55 cbx
->setEditable(object_opts
.value("editable").toBool());
59 QByteArray ba
= delegate_type
.toAscii();
60 QVariant::Type type
= QVariant::nameToType(ba
.constData());
61 if(type
== QVariant::Bool
) {
62 w
= new QCheckBox(parent
);
63 w
->setAutoFillBackground(true);
65 else if(type
== QVariant::Invalid
) {
66 /// needituj policka, ktera neznas
69 w
= QItemEditorFactory::createEditor(type
, NULL
);
72 QFPrototypedObjectItemEditor
*ed
= NULL
;
74 ed
= new QFPrototypedObjectItemEditor(parent
);
75 ed
->setEditorWidget(w
);