0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
** All rights reserved.
|
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
6 |
**
|
|
7 |
** This file is part of the Qt Designer of the Qt Toolkit.
|
|
8 |
**
|
|
9 |
** $QT_BEGIN_LICENSE:LGPL$
|
|
10 |
** No Commercial Usage
|
|
11 |
** This file contains pre-release code and may not be distributed.
|
|
12 |
** You may use this file in accordance with the terms and conditions
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
15 |
**
|
|
16 |
** GNU Lesser General Public License Usage
|
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
18 |
** General Public License version 2.1 as published by the Free Software
|
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
20 |
** packaging of this file. Please review the following information to
|
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
23 |
**
|
|
24 |
** In addition, as a special exception, Nokia gives you certain additional
|
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
27 |
**
|
|
28 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
36 |
**
|
|
37 |
**
|
|
38 |
** $QT_END_LICENSE$
|
|
39 |
**
|
|
40 |
****************************************************************************/
|
|
41 |
|
|
42 |
#include "metadatabase_p.h"
|
|
43 |
#include "widgetdatabase_p.h"
|
|
44 |
|
|
45 |
// sdk
|
|
46 |
#include <QtDesigner/QDesignerFormEditorInterface>
|
|
47 |
|
|
48 |
// Qt
|
|
49 |
#include <QtGui/QWidget>
|
|
50 |
#include <QtCore/qalgorithms.h>
|
|
51 |
#include <QtCore/qdebug.h>
|
|
52 |
|
|
53 |
QT_BEGIN_NAMESPACE
|
|
54 |
|
|
55 |
namespace {
|
|
56 |
const bool debugMetaDatabase = false;
|
|
57 |
}
|
|
58 |
|
|
59 |
namespace qdesigner_internal {
|
|
60 |
|
|
61 |
MetaDataBaseItem::MetaDataBaseItem(QObject *object)
|
|
62 |
: m_object(object),
|
|
63 |
m_enabled(true)
|
|
64 |
{
|
|
65 |
}
|
|
66 |
|
|
67 |
MetaDataBaseItem::~MetaDataBaseItem()
|
|
68 |
{
|
|
69 |
}
|
|
70 |
|
|
71 |
QString MetaDataBaseItem::name() const
|
|
72 |
{
|
|
73 |
Q_ASSERT(m_object);
|
|
74 |
return m_object->objectName();
|
|
75 |
}
|
|
76 |
|
|
77 |
void MetaDataBaseItem::setName(const QString &name)
|
|
78 |
{
|
|
79 |
Q_ASSERT(m_object);
|
|
80 |
m_object->setObjectName(name);
|
|
81 |
}
|
|
82 |
|
|
83 |
QString MetaDataBaseItem::customClassName() const
|
|
84 |
{
|
|
85 |
return m_customClassName;
|
|
86 |
}
|
|
87 |
void MetaDataBaseItem::setCustomClassName(const QString &customClassName)
|
|
88 |
{
|
|
89 |
m_customClassName = customClassName;
|
|
90 |
}
|
|
91 |
|
|
92 |
|
|
93 |
MetaDataBaseItem::TabOrder MetaDataBaseItem::tabOrder() const
|
|
94 |
{
|
|
95 |
return m_tabOrder;
|
|
96 |
}
|
|
97 |
|
|
98 |
void MetaDataBaseItem::setTabOrder(const TabOrder &tabOrder)
|
|
99 |
{
|
|
100 |
m_tabOrder = tabOrder;
|
|
101 |
}
|
|
102 |
|
|
103 |
bool MetaDataBaseItem::enabled() const
|
|
104 |
{
|
|
105 |
return m_enabled;
|
|
106 |
}
|
|
107 |
|
|
108 |
void MetaDataBaseItem::setEnabled(bool b)
|
|
109 |
{
|
|
110 |
m_enabled = b;
|
|
111 |
}
|
|
112 |
|
|
113 |
QString MetaDataBaseItem::script() const
|
|
114 |
{
|
|
115 |
return m_script;
|
|
116 |
}
|
|
117 |
|
|
118 |
void MetaDataBaseItem::setScript(const QString &script)
|
|
119 |
{
|
|
120 |
m_script = script;
|
|
121 |
}
|
|
122 |
|
|
123 |
QStringList MetaDataBaseItem::fakeSlots() const
|
|
124 |
{
|
|
125 |
return m_fakeSlots;
|
|
126 |
}
|
|
127 |
|
|
128 |
void MetaDataBaseItem::setFakeSlots(const QStringList &fs)
|
|
129 |
{
|
|
130 |
m_fakeSlots = fs;
|
|
131 |
}
|
|
132 |
|
|
133 |
QStringList MetaDataBaseItem::fakeSignals() const
|
|
134 |
{
|
|
135 |
return m_fakeSignals;
|
|
136 |
}
|
|
137 |
|
|
138 |
void MetaDataBaseItem::setFakeSignals(const QStringList &fs)
|
|
139 |
{
|
|
140 |
m_fakeSignals = fs;
|
|
141 |
}
|
|
142 |
|
|
143 |
// -----------------------------------------------------
|
|
144 |
MetaDataBase::MetaDataBase(QDesignerFormEditorInterface *core, QObject *parent)
|
|
145 |
: QDesignerMetaDataBaseInterface(parent),
|
|
146 |
m_core(core)
|
|
147 |
{
|
|
148 |
}
|
|
149 |
|
|
150 |
MetaDataBase::~MetaDataBase()
|
|
151 |
{
|
|
152 |
qDeleteAll(m_items);
|
|
153 |
}
|
|
154 |
|
|
155 |
MetaDataBaseItem *MetaDataBase::metaDataBaseItem(QObject *object) const
|
|
156 |
{
|
|
157 |
MetaDataBaseItem *i = m_items.value(object);
|
|
158 |
if (i == 0 || !i->enabled())
|
|
159 |
return 0;
|
|
160 |
return i;
|
|
161 |
}
|
|
162 |
|
|
163 |
void MetaDataBase::add(QObject *object)
|
|
164 |
{
|
|
165 |
MetaDataBaseItem *item = m_items.value(object);
|
|
166 |
if (item != 0) {
|
|
167 |
item->setEnabled(true);
|
|
168 |
if (debugMetaDatabase) {
|
|
169 |
qDebug() << "MetaDataBase::add: Existing item for " << object->metaObject()->className() << item->name();
|
|
170 |
}
|
|
171 |
return;
|
|
172 |
}
|
|
173 |
|
|
174 |
item = new MetaDataBaseItem(object);
|
|
175 |
m_items.insert(object, item);
|
|
176 |
if (debugMetaDatabase) {
|
|
177 |
qDebug() << "MetaDataBase::add: New item " << object->metaObject()->className() << item->name();
|
|
178 |
}
|
|
179 |
connect(object, SIGNAL(destroyed(QObject*)),
|
|
180 |
this, SLOT(slotDestroyed(QObject*)));
|
|
181 |
|
|
182 |
emit changed();
|
|
183 |
}
|
|
184 |
|
|
185 |
void MetaDataBase::remove(QObject *object)
|
|
186 |
{
|
|
187 |
Q_ASSERT(object);
|
|
188 |
|
|
189 |
if (MetaDataBaseItem *item = m_items.value(object)) {
|
|
190 |
item->setEnabled(false);
|
|
191 |
emit changed();
|
|
192 |
}
|
|
193 |
}
|
|
194 |
|
|
195 |
QList<QObject*> MetaDataBase::objects() const
|
|
196 |
{
|
|
197 |
QList<QObject*> result;
|
|
198 |
|
|
199 |
ItemMap::const_iterator it = m_items.begin();
|
|
200 |
for (; it != m_items.end(); ++it) {
|
|
201 |
if (it.value()->enabled())
|
|
202 |
result.append(it.key());
|
|
203 |
}
|
|
204 |
|
|
205 |
return result;
|
|
206 |
}
|
|
207 |
|
|
208 |
QDesignerFormEditorInterface *MetaDataBase::core() const
|
|
209 |
{
|
|
210 |
return m_core;
|
|
211 |
}
|
|
212 |
|
|
213 |
void MetaDataBase::slotDestroyed(QObject *object)
|
|
214 |
{
|
|
215 |
if (m_items.contains(object)) {
|
|
216 |
MetaDataBaseItem *item = m_items.value(object);
|
|
217 |
delete item;
|
|
218 |
m_items.remove(object);
|
|
219 |
}
|
|
220 |
}
|
|
221 |
|
|
222 |
// promotion convenience
|
|
223 |
QDESIGNER_SHARED_EXPORT bool promoteWidget(QDesignerFormEditorInterface *core,QWidget *widget,const QString &customClassName)
|
|
224 |
{
|
|
225 |
|
|
226 |
MetaDataBase *db = qobject_cast<MetaDataBase *>(core->metaDataBase());
|
|
227 |
if (!db)
|
|
228 |
return false;
|
|
229 |
MetaDataBaseItem *item = db->metaDataBaseItem(widget);
|
|
230 |
if (!item) {
|
|
231 |
db ->add(widget);
|
|
232 |
item = db->metaDataBaseItem(widget);
|
|
233 |
}
|
|
234 |
// Recursive promotion occurs if there is a plugin missing.
|
|
235 |
const QString oldCustomClassName = item->customClassName();
|
|
236 |
if (!oldCustomClassName.isEmpty()) {
|
|
237 |
qDebug() << "WARNING: Recursive promotion of " << oldCustomClassName << " to " << customClassName
|
|
238 |
<< ". A plugin is missing.";
|
|
239 |
}
|
|
240 |
item->setCustomClassName(customClassName);
|
|
241 |
if (debugMetaDatabase) {
|
|
242 |
qDebug() << "Promoting " << widget->metaObject()->className() << " to " << customClassName;
|
|
243 |
}
|
|
244 |
return true;
|
|
245 |
}
|
|
246 |
|
|
247 |
QDESIGNER_SHARED_EXPORT void demoteWidget(QDesignerFormEditorInterface *core,QWidget *widget)
|
|
248 |
{
|
|
249 |
MetaDataBase *db = qobject_cast<MetaDataBase *>(core->metaDataBase());
|
|
250 |
if (!db)
|
|
251 |
return;
|
|
252 |
MetaDataBaseItem *item = db->metaDataBaseItem(widget);
|
|
253 |
item->setCustomClassName(QString());
|
|
254 |
if (debugMetaDatabase) {
|
|
255 |
qDebug() << "Demoting " << widget;
|
|
256 |
}
|
|
257 |
}
|
|
258 |
|
|
259 |
QDESIGNER_SHARED_EXPORT bool isPromoted(QDesignerFormEditorInterface *core, QWidget* widget)
|
|
260 |
{
|
|
261 |
const MetaDataBase *db = qobject_cast<const MetaDataBase *>(core->metaDataBase());
|
|
262 |
if (!db)
|
|
263 |
return false;
|
|
264 |
const MetaDataBaseItem *item = db->metaDataBaseItem(widget);
|
|
265 |
if (!item)
|
|
266 |
return false;
|
|
267 |
return !item->customClassName().isEmpty();
|
|
268 |
}
|
|
269 |
|
|
270 |
QDESIGNER_SHARED_EXPORT QString promotedCustomClassName(QDesignerFormEditorInterface *core, QWidget* widget)
|
|
271 |
{
|
|
272 |
const MetaDataBase *db = qobject_cast<const MetaDataBase *>(core->metaDataBase());
|
|
273 |
if (!db)
|
|
274 |
return QString();
|
|
275 |
const MetaDataBaseItem *item = db->metaDataBaseItem(widget);
|
|
276 |
if (!item)
|
|
277 |
return QString();
|
|
278 |
return item->customClassName();
|
|
279 |
}
|
|
280 |
|
|
281 |
QDESIGNER_SHARED_EXPORT QString promotedExtends(QDesignerFormEditorInterface *core, QWidget* widget)
|
|
282 |
{
|
|
283 |
const QString customClassName = promotedCustomClassName(core,widget);
|
|
284 |
if (customClassName.isEmpty())
|
|
285 |
return QString();
|
|
286 |
const int i = core->widgetDataBase()->indexOfClassName(customClassName);
|
|
287 |
if (i == -1)
|
|
288 |
return QString();
|
|
289 |
return core->widgetDataBase()->item(i)->extends();
|
|
290 |
}
|
|
291 |
|
|
292 |
|
|
293 |
} // namespace qdesigner_internal
|
|
294 |
|
|
295 |
QT_END_NAMESPACE
|