~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to tools/designer/src/lib/shared/widgetdatabase.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
 
4
**
 
5
** This file is part of the designer application of the Qt Toolkit.
 
6
**
 
7
** This file may be distributed under the terms of the Q Public License
 
8
** as defined by Trolltech AS of Norway and appearing in the file
 
9
** LICENSE.QPL included in the packaging of this file.
 
10
**
 
11
** This file may be distributed and/or modified under the terms of the
 
12
** GNU General Public License version 2 as published by the Free Software
 
13
** Foundation and appearing in the file LICENSE.GPL included in the
 
14
** packaging of this file.
 
15
**
 
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
 
17
**   information about Qt Commercial License Agreements.
 
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
 
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
 
20
**
 
21
** Contact info@trolltech.com if any conditions of this licensing are
 
22
** not clear to you.
 
23
**
 
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 
26
**
 
27
****************************************************************************/
 
28
 
 
29
#include "widgetdatabase_p.h"
 
30
#include "widgetfactory_p.h"
 
31
#include "spacer_widget_p.h"
 
32
 
 
33
#include <pluginmanager_p.h>
 
34
#include <QtDesigner/customwidget.h>
 
35
#include <QtDesigner/propertysheet.h>
 
36
#include <QtDesigner/QExtensionManager>
 
37
 
 
38
#include <qalgorithms.h>
 
39
#include <QtCore/qdebug.h>
 
40
#include <QtCore/QMetaProperty>
 
41
 
 
42
// ----------------------------------------------------------
 
43
WidgetDataBaseItem::WidgetDataBaseItem(const QString &name, const QString &group)
 
44
    : m_name(name),
 
45
      m_group(group),
 
46
      m_compat(0),
 
47
      m_container(0),
 
48
      m_form(0),
 
49
      m_custom(0),
 
50
      m_promoted(0)
 
51
{
 
52
}
 
53
 
 
54
QString WidgetDataBaseItem::name() const
 
55
{
 
56
    return m_name;
 
57
}
 
58
 
 
59
void WidgetDataBaseItem::setName(const QString &name)
 
60
{
 
61
    m_name = name;
 
62
}
 
63
 
 
64
QString WidgetDataBaseItem::group() const
 
65
{
 
66
    return m_group;
 
67
}
 
68
 
 
69
void WidgetDataBaseItem::setGroup(const QString &group)
 
70
{
 
71
    m_group = group;
 
72
}
 
73
 
 
74
QString WidgetDataBaseItem::toolTip() const
 
75
{
 
76
    return m_toolTip;
 
77
}
 
78
 
 
79
void WidgetDataBaseItem::setToolTip(const QString &toolTip)
 
80
{
 
81
    m_toolTip = toolTip;
 
82
}
 
83
 
 
84
QString WidgetDataBaseItem::whatsThis() const
 
85
{
 
86
    return m_whatsThis;
 
87
}
 
88
 
 
89
void WidgetDataBaseItem::setWhatsThis(const QString &whatsThis)
 
90
{
 
91
    m_whatsThis = whatsThis;
 
92
}
 
93
 
 
94
QString WidgetDataBaseItem::includeFile() const
 
95
{
 
96
    return m_includeFile;
 
97
}
 
98
 
 
99
void WidgetDataBaseItem::setIncludeFile(const QString &includeFile)
 
100
{
 
101
    m_includeFile = includeFile;
 
102
}
 
103
 
 
104
QIcon WidgetDataBaseItem::icon() const
 
105
{
 
106
    return m_icon;
 
107
}
 
108
 
 
109
void WidgetDataBaseItem::setIcon(const QIcon &icon)
 
110
{
 
111
    m_icon = icon;
 
112
}
 
113
 
 
114
bool WidgetDataBaseItem::isCompat() const
 
115
{
 
116
    return m_compat;
 
117
}
 
118
 
 
119
void WidgetDataBaseItem::setCompat(bool b)
 
120
{
 
121
    m_compat = b;
 
122
}
 
123
 
 
124
bool WidgetDataBaseItem::isContainer() const
 
125
{
 
126
    return m_container;
 
127
}
 
128
 
 
129
void WidgetDataBaseItem::setContainer(bool b)
 
130
{
 
131
    m_container = b;
 
132
}
 
133
 
 
134
bool WidgetDataBaseItem::isCustom() const
 
135
{
 
136
    return m_custom;
 
137
}
 
138
 
 
139
void WidgetDataBaseItem::setCustom(bool b)
 
140
{
 
141
    m_custom = b;
 
142
}
 
143
 
 
144
QString WidgetDataBaseItem::pluginPath() const
 
145
{
 
146
    return m_pluginPath;
 
147
}
 
148
 
 
149
void WidgetDataBaseItem::setPluginPath(const QString &path)
 
150
{
 
151
    m_pluginPath = path;
 
152
}
 
153
 
 
154
bool WidgetDataBaseItem::isPromoted() const
 
155
{
 
156
    return m_promoted;
 
157
}
 
158
 
 
159
void WidgetDataBaseItem::setPromoted(bool b)
 
160
{
 
161
    m_promoted = b;
 
162
}
 
163
 
 
164
QString WidgetDataBaseItem::extends() const
 
165
{
 
166
    return m_extends;
 
167
}
 
168
 
 
169
void WidgetDataBaseItem::setExtends(const QString &s)
 
170
{
 
171
    m_extends = s;
 
172
}
 
173
 
 
174
void WidgetDataBaseItem::setDefaultPropertyValues(const QList<QVariant> &list)
 
175
{
 
176
    m_defaultPropertyValues = list;
 
177
}
 
178
 
 
179
QList<QVariant> WidgetDataBaseItem::defaultPropertyValues() const
 
180
{
 
181
    return m_defaultPropertyValues;
 
182
}
 
183
 
 
184
// ----------------------------------------------------------
 
185
WidgetDataBase::WidgetDataBase(QDesignerFormEditorInterface *core, QObject *parent)
 
186
    : QDesignerWidgetDataBaseInterface(parent),
 
187
      m_core(core)
 
188
{
 
189
#define DECLARE_LAYOUT(L, C)
 
190
#define DECLARE_COMPAT_WIDGET(W, C) DECLARE_WIDGET(W, C)
 
191
#define DECLARE_WIDGET(W, C) append(new WidgetDataBaseItem(QString::fromUtf8(#W)));
 
192
 
 
193
#include "widgets.table"
 
194
 
 
195
#undef DECLARE_COMPAT_WIDGET
 
196
#undef DECLARE_LAYOUT
 
197
#undef DECLARE_WIDGET
 
198
 
 
199
    append(new WidgetDataBaseItem(QString::fromUtf8("Line")));
 
200
    append(new WidgetDataBaseItem(QString::fromUtf8("Spacer")));
 
201
    append(new WidgetDataBaseItem(QString::fromUtf8("QSplitter")));
 
202
    append(new WidgetDataBaseItem(QString::fromUtf8("QLayoutWidget")));
 
203
    append(new WidgetDataBaseItem(QString::fromUtf8("QDesignerWidget")));
 
204
    append(new WidgetDataBaseItem(QString::fromUtf8("QDesignerDialog")));
 
205
    append(new WidgetDataBaseItem(QString::fromUtf8("QDesignerCompatWidget")));
 
206
 
 
207
    // ### remove me
 
208
    // ### check the casts
 
209
    static_cast<WidgetDataBaseItem *>(item(indexOfClassName(QLatin1String("QTabWidget"))))->setContainer(true);
 
210
    static_cast<WidgetDataBaseItem *>(item(indexOfClassName(QLatin1String("QGroupBox"))))->setContainer(true);
 
211
    static_cast<WidgetDataBaseItem *>(item(indexOfClassName(QLatin1String("QStackedWidget"))))->setContainer(true);
 
212
    static_cast<WidgetDataBaseItem *>(item(indexOfClassName(QLatin1String("QToolBox"))))->setContainer(true);
 
213
    static_cast<WidgetDataBaseItem *>(item(indexOfClassName(QLatin1String("QFrame"))))->setContainer(true);
 
214
    static_cast<WidgetDataBaseItem *>(item(indexOfClassName(QLatin1String("QLayoutWidget"))))->setContainer(true);
 
215
    static_cast<WidgetDataBaseItem *>(item(indexOfClassName(QLatin1String("QDesignerWidget"))))->setContainer(true);
 
216
    static_cast<WidgetDataBaseItem *>(item(indexOfClassName(QLatin1String("QDesignerDialog"))))->setContainer(true);
 
217
    static_cast<WidgetDataBaseItem *>(item(indexOfClassName(QLatin1String("QSplitter"))))->setContainer(true);
 
218
    static_cast<WidgetDataBaseItem *>(item(indexOfClassName(QLatin1String("QMainWindow"))))->setContainer(true);
 
219
    static_cast<WidgetDataBaseItem *>(item(indexOfClassName(QLatin1String("QDockWidget"))))->setContainer(true);
 
220
 
 
221
    static_cast<WidgetDataBaseItem *>(item(indexOfClassName(QLatin1String("QWidget"))))->setContainer(true);
 
222
    static_cast<WidgetDataBaseItem *>(item(indexOfClassName(QLatin1String("QDialog"))))->setContainer(true);
 
223
}
 
224
 
 
225
WidgetDataBase::~WidgetDataBase()
 
226
{
 
227
}
 
228
 
 
229
QDesignerFormEditorInterface *WidgetDataBase::core() const
 
230
{
 
231
    return m_core;
 
232
}
 
233
 
 
234
int WidgetDataBase::indexOfObject(QObject *object, bool /*resolveName*/) const
 
235
{
 
236
    bool resolveName = true; // ### resolveName = false is ignored
 
237
 
 
238
    if (resolveName)
 
239
        return QDesignerWidgetDataBaseInterface::indexOfClassName(QLatin1String(WidgetFactory::classNameOf(object)));
 
240
 
 
241
    return QDesignerWidgetDataBaseInterface::indexOfObject(object, resolveName);
 
242
}
 
243
 
 
244
QDesignerWidgetDataBaseItemInterface *WidgetDataBase::item(int index) const
 
245
{
 
246
    return QDesignerWidgetDataBaseInterface::item(index);
 
247
}
 
248
 
 
249
void WidgetDataBase::loadPlugins()
 
250
{
 
251
    PluginManager *pluginManager = m_core->pluginManager();
 
252
 
 
253
    QStringList plugins = pluginManager->registeredPlugins();
 
254
 
 
255
    QMutableListIterator<QDesignerWidgetDataBaseItemInterface *> it(m_items);
 
256
    while (it.hasNext()) {
 
257
        QDesignerWidgetDataBaseItemInterface *item = it.next();
 
258
 
 
259
        if (item->isCustom()) {
 
260
            it.remove();
 
261
            delete item;
 
262
        }
 
263
    }
 
264
 
 
265
    pluginManager->ensureInitialized();
 
266
 
 
267
    foreach (QString plugin, plugins) {
 
268
        QObject *o = pluginManager->instance(plugin);
 
269
 
 
270
        if (QDesignerCustomWidgetInterface *c = qobject_cast<QDesignerCustomWidgetInterface*>(o)) {
 
271
            WidgetDataBaseItem *item = createCustomWidgetItem(c);
 
272
            item->setPluginPath(plugin);
 
273
            append(item);
 
274
        } else if (QDesignerCustomWidgetCollectionInterface *coll = qobject_cast<QDesignerCustomWidgetCollectionInterface*>(o)) {
 
275
            foreach (QDesignerCustomWidgetInterface *c, coll->customWidgets()) {
 
276
                WidgetDataBaseItem *item = createCustomWidgetItem(c);
 
277
                item->setPluginPath(plugin);
 
278
                append(item);
 
279
            }
 
280
        }
 
281
    }
 
282
}
 
283
 
 
284
WidgetDataBaseItem *WidgetDataBase::createCustomWidgetItem(QDesignerCustomWidgetInterface *c) const
 
285
{
 
286
    WidgetDataBaseItem *item = new WidgetDataBaseItem();
 
287
    item->setContainer(c->isContainer());
 
288
    item->setCustom(true);
 
289
    item->setGroup(c->group());
 
290
    item->setIcon(c->icon());
 
291
    item->setIncludeFile(c->includeFile());
 
292
    item->setName(c->name());
 
293
    item->setToolTip(c->toolTip());
 
294
    item->setWhatsThis(c->whatsThis());
 
295
 
 
296
    return item;
 
297
}
 
298
 
 
299
QList<QVariant> WidgetDataBase::defaultPropertyValues(const QString &name)
 
300
{
 
301
    QList<QVariant> result;
 
302
 
 
303
    WidgetFactory factory(m_core);
 
304
    QWidget *w = factory.createWidget(name, 0);
 
305
    if (w == 0) {
 
306
        return result;
 
307
    }
 
308
 
 
309
    QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(m_core->extensionManager(), w);
 
310
    if (sheet == 0) {
 
311
        delete w;
 
312
        return result;
 
313
    }
 
314
 
 
315
    for (int i = 0; i < sheet->count(); ++i) {
 
316
        result.append(sheet->property(i));
 
317
    }
 
318
 
 
319
    delete w;
 
320
 
 
321
    return result;
 
322
}
 
323
 
 
324
void WidgetDataBase::grabDefaultPropertyValues()
 
325
{
 
326
    for (int i = 0; i < count(); ++i) {
 
327
        QDesignerWidgetDataBaseItemInterface *item = this->item(i);
 
328
        QList<QVariant> default_prop_values = defaultPropertyValues(item->name());
 
329
        item->setDefaultPropertyValues(default_prop_values);
 
330
 
 
331
    }
 
332
}