1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the designer application of the Qt Toolkit.
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.
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.
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.
21
** Contact info@trolltech.com if any conditions of this licensing are
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.
27
****************************************************************************/
29
#include "widgetdatabase_p.h"
30
#include "widgetfactory_p.h"
31
#include "spacer_widget_p.h"
33
#include <pluginmanager_p.h>
34
#include <QtDesigner/customwidget.h>
35
#include <QtDesigner/propertysheet.h>
36
#include <QtDesigner/QExtensionManager>
38
#include <qalgorithms.h>
39
#include <QtCore/qdebug.h>
40
#include <QtCore/QMetaProperty>
42
// ----------------------------------------------------------
43
WidgetDataBaseItem::WidgetDataBaseItem(const QString &name, const QString &group)
54
QString WidgetDataBaseItem::name() const
59
void WidgetDataBaseItem::setName(const QString &name)
64
QString WidgetDataBaseItem::group() const
69
void WidgetDataBaseItem::setGroup(const QString &group)
74
QString WidgetDataBaseItem::toolTip() const
79
void WidgetDataBaseItem::setToolTip(const QString &toolTip)
84
QString WidgetDataBaseItem::whatsThis() const
89
void WidgetDataBaseItem::setWhatsThis(const QString &whatsThis)
91
m_whatsThis = whatsThis;
94
QString WidgetDataBaseItem::includeFile() const
99
void WidgetDataBaseItem::setIncludeFile(const QString &includeFile)
101
m_includeFile = includeFile;
104
QIcon WidgetDataBaseItem::icon() const
109
void WidgetDataBaseItem::setIcon(const QIcon &icon)
114
bool WidgetDataBaseItem::isCompat() const
119
void WidgetDataBaseItem::setCompat(bool b)
124
bool WidgetDataBaseItem::isContainer() const
129
void WidgetDataBaseItem::setContainer(bool b)
134
bool WidgetDataBaseItem::isCustom() const
139
void WidgetDataBaseItem::setCustom(bool b)
144
QString WidgetDataBaseItem::pluginPath() const
149
void WidgetDataBaseItem::setPluginPath(const QString &path)
154
bool WidgetDataBaseItem::isPromoted() const
159
void WidgetDataBaseItem::setPromoted(bool b)
164
QString WidgetDataBaseItem::extends() const
169
void WidgetDataBaseItem::setExtends(const QString &s)
174
void WidgetDataBaseItem::setDefaultPropertyValues(const QList<QVariant> &list)
176
m_defaultPropertyValues = list;
179
QList<QVariant> WidgetDataBaseItem::defaultPropertyValues() const
181
return m_defaultPropertyValues;
184
// ----------------------------------------------------------
185
WidgetDataBase::WidgetDataBase(QDesignerFormEditorInterface *core, QObject *parent)
186
: QDesignerWidgetDataBaseInterface(parent),
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)));
193
#include "widgets.table"
195
#undef DECLARE_COMPAT_WIDGET
196
#undef DECLARE_LAYOUT
197
#undef DECLARE_WIDGET
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")));
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);
221
static_cast<WidgetDataBaseItem *>(item(indexOfClassName(QLatin1String("QWidget"))))->setContainer(true);
222
static_cast<WidgetDataBaseItem *>(item(indexOfClassName(QLatin1String("QDialog"))))->setContainer(true);
225
WidgetDataBase::~WidgetDataBase()
229
QDesignerFormEditorInterface *WidgetDataBase::core() const
234
int WidgetDataBase::indexOfObject(QObject *object, bool /*resolveName*/) const
236
bool resolveName = true; // ### resolveName = false is ignored
239
return QDesignerWidgetDataBaseInterface::indexOfClassName(QLatin1String(WidgetFactory::classNameOf(object)));
241
return QDesignerWidgetDataBaseInterface::indexOfObject(object, resolveName);
244
QDesignerWidgetDataBaseItemInterface *WidgetDataBase::item(int index) const
246
return QDesignerWidgetDataBaseInterface::item(index);
249
void WidgetDataBase::loadPlugins()
251
PluginManager *pluginManager = m_core->pluginManager();
253
QStringList plugins = pluginManager->registeredPlugins();
255
QMutableListIterator<QDesignerWidgetDataBaseItemInterface *> it(m_items);
256
while (it.hasNext()) {
257
QDesignerWidgetDataBaseItemInterface *item = it.next();
259
if (item->isCustom()) {
265
pluginManager->ensureInitialized();
267
foreach (QString plugin, plugins) {
268
QObject *o = pluginManager->instance(plugin);
270
if (QDesignerCustomWidgetInterface *c = qobject_cast<QDesignerCustomWidgetInterface*>(o)) {
271
WidgetDataBaseItem *item = createCustomWidgetItem(c);
272
item->setPluginPath(plugin);
274
} else if (QDesignerCustomWidgetCollectionInterface *coll = qobject_cast<QDesignerCustomWidgetCollectionInterface*>(o)) {
275
foreach (QDesignerCustomWidgetInterface *c, coll->customWidgets()) {
276
WidgetDataBaseItem *item = createCustomWidgetItem(c);
277
item->setPluginPath(plugin);
284
WidgetDataBaseItem *WidgetDataBase::createCustomWidgetItem(QDesignerCustomWidgetInterface *c) const
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());
299
QList<QVariant> WidgetDataBase::defaultPropertyValues(const QString &name)
301
QList<QVariant> result;
303
WidgetFactory factory(m_core);
304
QWidget *w = factory.createWidget(name, 0);
309
QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(m_core->extensionManager(), w);
315
for (int i = 0; i < sheet->count(); ++i) {
316
result.append(sheet->property(i));
324
void WidgetDataBase::grabDefaultPropertyValues()
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);