1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the Qt Designer of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
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 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at [email protected].
|
---|
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) {
|
---|
|
---|