1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt Designer of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29#include "abstractwidgetdatabase.h"
30#include <QtCore/qdebug.h>
31#include <qalgorithms.h>
32
33QT_BEGIN_NAMESPACE
34
35namespace {
36 enum { debugWidgetDataBase = 0 };
37}
38
39/*!
40 \class QDesignerWidgetDataBaseInterface
41 \brief The QDesignerWidgetDataBaseInterface class provides an interface that is used to
42 access and modify Qt Designer's widget database.
43 \inmodule QtDesigner
44 \internal
45*/
46
47/*!
48 Constructs an interface to the widget database with the given \a parent.
49*/
50QDesignerWidgetDataBaseInterface::QDesignerWidgetDataBaseInterface(QObject *parent)
51 : QObject(parent)
52{
53}
54
55/*!
56 Destroys the interface to the widget database.
57*/
58QDesignerWidgetDataBaseInterface::~QDesignerWidgetDataBaseInterface()
59{
60 qDeleteAll(c: m_items);
61}
62
63/*!
64
65*/
66int QDesignerWidgetDataBaseInterface::count() const
67{
68 return m_items.count();
69}
70
71/*!
72*/
73QDesignerWidgetDataBaseItemInterface *QDesignerWidgetDataBaseInterface::item(int index) const
74{
75 return index != -1 ? m_items.at(i: index) : 0;
76}
77
78/*!
79*/
80int QDesignerWidgetDataBaseInterface::indexOf(QDesignerWidgetDataBaseItemInterface *item) const
81{
82 return m_items.indexOf(t: item);
83}
84
85/*!
86*/
87void QDesignerWidgetDataBaseInterface::insert(int index, QDesignerWidgetDataBaseItemInterface *item)
88{
89 if (debugWidgetDataBase)
90 qDebug() << "insert at " << index << ' ' << item->name() << " derived from " << item->extends();
91
92 m_items.insert(i: index, t: item);
93}
94
95/*!
96*/
97void QDesignerWidgetDataBaseInterface::append(QDesignerWidgetDataBaseItemInterface *item)
98{
99 if (debugWidgetDataBase)
100 qDebug() << "append " << item->name() << " derived from " << item->extends();
101 m_items.append(t: item);
102}
103
104/*!
105*/
106QDesignerFormEditorInterface *QDesignerWidgetDataBaseInterface::core() const
107{
108 return nullptr;
109}
110
111/*!
112*/
113int QDesignerWidgetDataBaseInterface::indexOfClassName(const QString &name, bool) const
114{
115 const int itemCount = count();
116 for (int i=0; i<itemCount; ++i) {
117 const QDesignerWidgetDataBaseItemInterface *entry = item(index: i);
118 if (entry->name() == name)
119 return i;
120 }
121
122 return -1;
123}
124
125/*!
126*/
127int QDesignerWidgetDataBaseInterface::indexOfObject(QObject *object, bool) const
128{
129 if (!object)
130 return -1;
131
132 const QString className = QString::fromUtf8(str: object->metaObject()->className());
133 return indexOfClassName(name: className);
134}
135
136/*!
137*/
138bool QDesignerWidgetDataBaseInterface::isContainer(QObject *object, bool resolveName) const
139{
140 if (const QDesignerWidgetDataBaseItemInterface *i = item(index: indexOfObject(object, resolveName)))
141 return i->isContainer();
142 return false;
143}
144
145/*!
146*/
147bool QDesignerWidgetDataBaseInterface::isCustom(QObject *object, bool resolveName) const
148{
149 if (const QDesignerWidgetDataBaseItemInterface *i = item(index: indexOfObject(object, resolveName)))
150 return i->isCustom();
151 return false;
152}
153
154/*!
155 \fn void QDesignerWidgetDataBaseInterface::changed()
156
157 This signal is emitted ...
158*/
159
160
161// Doc: No implementation - an abstract class
162
163/*!
164 \class QDesignerWidgetDataBaseItemInterface
165 \brief The QDesignerWidgetDataBaseItemInterface class provides an interface that is used to
166 access individual items in Qt Designer's widget database.
167 \inmodule QtDesigner
168 \internal
169
170 This class enables individual items in the widget database to be accessed and modified.
171 Changes to the widget database itself are made through the QDesignerWidgetDataBaseInterface
172 class.
173*/
174
175/*!
176 \fn virtual QDesignerWidgetDataBaseItemInterface::~QDesignerWidgetDataBaseItemInterface()
177
178 Destroys the interface.
179*/
180
181/*!
182 \fn virtual QString QDesignerWidgetDataBaseItemInterface::name() const = 0
183
184 Returns the name of the widget.
185*/
186
187/*!
188 \fn virtual void QDesignerWidgetDataBaseItemInterface::setName(const QString &name) = 0
189*/
190
191/*!
192 \fn virtual QString QDesignerWidgetDataBaseItemInterface::group() const = 0
193
194 Returns the name of the group that the widget belongs to.
195*/
196
197/*!
198 \fn virtual void QDesignerWidgetDataBaseItemInterface::setGroup(const QString &group) = 0
199*/
200
201/*!
202 \fn virtual QString QDesignerWidgetDataBaseItemInterface::toolTip() const = 0
203
204 Returns the tool tip to be used by the widget.
205*/
206
207/*!
208 \fn virtual void QDesignerWidgetDataBaseItemInterface::setToolTip(const QString &toolTip) = 0
209*/
210
211/*!
212 \fn virtual QString QDesignerWidgetDataBaseItemInterface::whatsThis() const = 0
213
214 Returns the "What's This?" help for the widget.
215*/
216
217/*!
218 \fn virtual void QDesignerWidgetDataBaseItemInterface::setWhatsThis(const QString &whatsThis) = 0
219*/
220
221/*!
222 \fn virtual QString QDesignerWidgetDataBaseItemInterface::includeFile() const = 0
223
224 Returns the name of the include file that the widget needs when being built from source.
225*/
226
227/*!
228 \fn virtual void QDesignerWidgetDataBaseItemInterface::setIncludeFile(const QString &includeFile) = 0
229*/
230
231/*!
232 \fn virtual QIcon QDesignerWidgetDataBaseItemInterface::icon() const = 0
233
234 Returns the icon used to represent the item.
235*/
236
237/*!
238 \fn virtual void QDesignerWidgetDataBaseItemInterface::setIcon(const QIcon &icon) = 0
239*/
240
241/*!
242 \fn virtual bool QDesignerWidgetDataBaseItemInterface::isCompat() const = 0
243
244 Returns true if this type of widget is provided for compatibility purposes (e.g. Qt3Support
245 widgets); otherwise returns false.
246
247 \sa setCompat()
248*/
249
250/*!
251 \fn virtual void QDesignerWidgetDataBaseItemInterface::setCompat(bool compat) = 0
252
253 If \a compat is true, the widget is handled as a compatibility widget; otherwise it is
254 handled normally by \QD.
255
256 \sa isCompat()
257*/
258
259/*!
260 \fn virtual bool QDesignerWidgetDataBaseItemInterface::isContainer() const = 0
261
262 Returns true if this widget is intended to be used to hold other widgets; otherwise returns
263 false.
264
265 \sa setContainer()
266*/
267
268/*!
269 \fn virtual void QDesignerWidgetDataBaseItemInterface::setContainer(bool container) = 0
270
271 If \a container is true, the widget can be used to hold other widgets in \QD; otherwise
272 \QD will refuse to let the user place other widgets inside it.
273
274 \sa isContainer()
275*/
276
277/*!
278 \fn virtual bool QDesignerWidgetDataBaseItemInterface::isCustom() const = 0
279
280 Returns true if the widget is a custom widget; otherwise return false if it is a standard
281 Qt widget.
282
283 \sa setCustom()
284*/
285
286/*!
287 \fn virtual void QDesignerWidgetDataBaseItemInterface::setCustom(bool custom) = 0
288
289 If \a custom is true, the widget is handled specially by \QD; otherwise it is handled as
290 a standard Qt widget.
291
292 \sa isCustom()
293*/
294
295/*!
296 \fn virtual QString QDesignerWidgetDataBaseItemInterface::pluginPath() const = 0
297
298 Returns the path to use for the widget plugin.
299*/
300
301/*!
302 \fn virtual void QDesignerWidgetDataBaseItemInterface::setPluginPath(const QString &path) = 0
303*/
304
305/*!
306 \fn virtual bool QDesignerWidgetDataBaseItemInterface::isPromoted() const = 0
307
308 Returns true if the widget is promoted; otherwise returns false.
309
310 Promoted widgets are those that represent custom widgets, but which are represented in
311 \QD by either standard Qt widgets or readily-available custom widgets.
312
313 \sa setPromoted()
314*/
315
316/*!
317 \fn virtual void QDesignerWidgetDataBaseItemInterface::setPromoted(bool promoted) = 0
318
319 If \a promoted is true, the widget is handled as a promoted widget by \QD and will use
320 a placeholder widget to represent it; otherwise it is handled as a standard widget.
321
322 \sa isPromoted()
323*/
324
325/*!
326 \fn virtual QString QDesignerWidgetDataBaseItemInterface::extends() const = 0
327
328 Returns the name of the widget that the item extends.
329*/
330
331/*!
332 \fn virtual void QDesignerWidgetDataBaseItemInterface::setExtends(const QString &s) = 0
333*/
334
335/*!
336 \fn virtual void QDesignerWidgetDataBaseItemInterface::setDefaultPropertyValues(const QList<QVariant> &list) = 0
337
338 Sets the default property values for the widget to the given \a list.
339*/
340
341/*!
342 \fn virtual QList<QVariant> QDesignerWidgetDataBaseItemInterface::defaultPropertyValues() const = 0
343
344 Returns a list of default values to be used as properties for the item.
345*/
346
347QT_END_NAMESPACE
348

source code of qttools/src/designer/src/lib/sdk/abstractwidgetdatabase.cpp