fixed some build related problems
[qsqlmon.git] / libqf / libqfgui / gui / widgets / qfprototypedobjecttreemodel / qfprototypedobjectitemeditorfactory.cpp
blobdc884c5f6272b4eea8a8c0d6c224c363b0b1aa13
2 //
3 // Author: Frantisek Vacek <fanda.vacek@volny.cz>, (C) 2010
4 //
5 // Copyright: See COPYING file that comes with this distribution
6 //
8 #include "qfprototypedobjectitemeditorfactory.h"
9 #include "qfprototypedobjectitemeditor.h"
11 #include <qfprototypedobject.h>
13 #include <QCheckBox>
14 #include <QComboBox>
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
32 qfLogFuncFrame();
33 QWidget *w = NULL;
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) {
42 QString caption;
43 QVariant value;
44 QVariantList lst = item.toList();
45 if(lst.isEmpty()) {
46 caption = item.toString();
47 value = item.toString();
49 else {
50 value = lst.value(0);
51 caption = lst.value(1).toString();
53 cbx->addItem(caption, value);
55 cbx->setEditable(object_opts.value("editable").toBool());
56 w = cbx;
58 else {
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
68 else {
69 w = QItemEditorFactory::createEditor(type, NULL);
72 QFPrototypedObjectItemEditor *ed = NULL;
73 if(w) {
74 ed = new QFPrototypedObjectItemEditor(parent);
75 ed->setEditorWidget(w);
77 return ed;