Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
abstractwidgetbox.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
5
6QT_BEGIN_NAMESPACE
7
8/*!
9 \class QDesignerWidgetBoxInterface
10
11 \brief The QDesignerWidgetBoxInterface class allows you to control
12 the contents of \QD's widget box.
13
14 \inmodule QtDesigner
15
16 QDesignerWidgetBoxInterface contains a collection of functions
17 that is typically used to manipulate the contents of \QD's widget
18 box.
19
20 \QD uses an XML file to populate its widget box. The name of that
21 file is one of the widget box's properties, and you can retrieve
22 it using the fileName() function.
23
24 QDesignerWidgetBoxInterface also provides the save() function that
25 saves the contents of the widget box in the file specified by the
26 widget box's file name property. If you have made changes to the
27 widget box, for example by dropping a widget into the widget box,
28 without calling the save() function, the original content can be
29 restored by a simple invocation of the load() function:
30
31 \snippet lib/tools_designer_src_lib_sdk_abstractwidgetbox.cpp 0
32
33 The QDesignerWidgetBoxInterface class is not intended to be
34 instantiated directly. You can retrieve an interface to Qt
35 Designer's widget box using the
36 QDesignerFormEditorInterface::widgetBox() function. A pointer to
37 \QD's current QDesignerFormEditorInterface object (\c formEditor
38 in the example above) is provided by the
39 QDesignerCustomWidgetInterface::initialize() function's
40 parameter. When implementing a custom widget plugin, you must
41 subclass the QDesignerCustomWidgetInterface to expose your plugin
42 to \QD.
43
44 If you want to save your changes, and at the same time preserve
45 the original contents, you can use the save() function combined
46 with the setFileName() function to save your changes into another
47 file. Remember to store the name of the original file first:
48
49 \snippet lib/tools_designer_src_lib_sdk_abstractwidgetbox.cpp 1
50
51 Then you can restore the original contents of the widget box by
52 resetting the file name to the original file and calling load():
53
54 \snippet lib/tools_designer_src_lib_sdk_abstractwidgetbox.cpp 2
55
56 In a similar way, you can later use your customized XML file:
57
58 \snippet lib/tools_designer_src_lib_sdk_abstractwidgetbox.cpp 3
59
60
61 \sa QDesignerFormEditorInterface
62*/
63
64/*!
65 Constructs a widget box interface with the given \a parent and
66 the specified window \a flags.
67*/
68QDesignerWidgetBoxInterface::QDesignerWidgetBoxInterface(QWidget *parent, Qt::WindowFlags flags)
69 : QWidget(parent, flags)
70{
71}
72
73/*!
74 Destroys the widget box interface.
75*/
76QDesignerWidgetBoxInterface::~QDesignerWidgetBoxInterface() = default;
77
78/*!
79 \internal
80*/
81int QDesignerWidgetBoxInterface::findOrInsertCategory(const QString &categoryName)
82{
83 int count = categoryCount();
84 for (int index=0; index<count; ++index) {
85 Category c = category(index);
86 if (c.name() == categoryName)
87 return index;
88 }
89
90 addCategory(Category(categoryName));
91 return count;
92}
93
94/*!
95 \internal
96 \fn int QDesignerWidgetBoxInterface::categoryCount() const
97*/
98
99/*!
100 \internal
101 \fn Category QDesignerWidgetBoxInterface::category(int cat_idx) const
102*/
103
104/*!
105 \internal
106 \fn void QDesignerWidgetBoxInterface::addCategory(const Category &cat)
107*/
108
109/*!
110 \internal
111 \fn void QDesignerWidgetBoxInterface::removeCategory(int cat_idx)
112*/
113
114/*!
115 \internal
116 \fn int QDesignerWidgetBoxInterface::widgetCount(int cat_idx) const
117*/
118
119/*!
120 \internal
121 \fn Widget QDesignerWidgetBoxInterface::widget(int cat_idx, int wgt_idx) const
122*/
123
124/*!
125 \internal
126 \fn void QDesignerWidgetBoxInterface::addWidget(int cat_idx, const Widget &wgt)
127*/
128
129/*!
130 \internal
131 \fn void QDesignerWidgetBoxInterface::removeWidget(int cat_idx, int wgt_idx)
132*/
133
134/*!
135 \internal
136 \fn void QDesignerWidgetBoxInterface::dropWidgets(const QList<QDesignerDnDItemInterface*> &item_list, const QPoint &global_mouse_pos)
137
138*/
139
140/*!
141 \fn void QDesignerWidgetBoxInterface::setFileName(const QString &fileName)
142
143 Sets the XML file that \QD will use to populate its widget box, to
144 \a fileName. You must call load() to update the widget box with
145 the new XML file.
146
147 \sa fileName(), load()
148*/
149
150/*!
151 \fn QString QDesignerWidgetBoxInterface::fileName() const
152
153 Returns the name of the XML file \QD is currently using to
154 populate its widget box.
155
156 \sa setFileName()
157*/
158
159/*!
160 \fn bool QDesignerWidgetBoxInterface::load()
161
162 Populates \QD's widget box by loading (or reloading) the currently
163 specified XML file. Returns true if the file is successfully
164 loaded; otherwise false.
165
166 \sa setFileName()
167*/
168
169/*!
170 \fn bool QDesignerWidgetBoxInterface::save()
171
172 Saves the contents of \QD's widget box in the file specified by
173 the fileName() function. Returns true if the content is
174 successfully saved; otherwise false.
175
176 \sa fileName(), setFileName()
177*/
178
179
180/*!
181 \internal
182
183 \class QDesignerWidgetBoxInterface::Widget
184
185 \brief The Widget class specified a widget in \QD's widget
186 box component.
187*/
188
189/*!
190 \enum QDesignerWidgetBoxInterface::Widget::Type
191
192 \value Default
193 \value Custom
194*/
195
196/*!
197 \fn QDesignerWidgetBoxInterface::Widget::Widget(const QString &aname, const QString &xml, const QString &icon_name, Type atype)
198*/
199
200/*!
201 \fn QString QDesignerWidgetBoxInterface::Widget::name() const
202*/
203
204/*!
205 \fn void QDesignerWidgetBoxInterface::Widget::setName(const QString &aname)
206*/
207
208/*!
209 \fn QString QDesignerWidgetBoxInterface::Widget::domXml() const
210*/
211
212/*!
213 \fn void QDesignerWidgetBoxInterface::Widget::setDomXml(const QString &xml)
214*/
215
216/*!
217 \fn QString QDesignerWidgetBoxInterface::Widget::iconName() const
218*/
219
220/*!
221 \fn void QDesignerWidgetBoxInterface::Widget::setIconName(const QString &icon_name)
222*/
223
224/*!
225 \fn Type QDesignerWidgetBoxInterface::Widget::type() const
226*/
227
228/*!
229 \fn void QDesignerWidgetBoxInterface::Widget::setType(Type atype)
230*/
231
232/*!
233 \fn bool QDesignerWidgetBoxInterface::Widget::isNull() const
234*/
235
236
237/*!
238 \class QDesignerWidgetBoxInterface::Category
239 \brief The Category class specifies a category in \QD's widget box component.
240 \internal
241*/
242
243/*!
244 \enum QDesignerWidgetBoxInterface::Category::Type
245
246 \value Default
247 \value Scratchpad
248*/
249
250/*!
251 \fn QDesignerWidgetBoxInterface::Category::Category(const QString &aname, Type atype)
252*/
253
254/*!
255 \fn QString QDesignerWidgetBoxInterface::Category::name() const
256*/
257
258/*!
259 \fn void QDesignerWidgetBoxInterface::Category::setName(const QString &aname)
260*/
261
262/*!
263 \fn int QDesignerWidgetBoxInterface::Category::widgetCount() const
264*/
265
266/*!
267 \fn Widget QDesignerWidgetBoxInterface::Category::widget(int idx) const
268*/
269
270/*!
271 \fn void QDesignerWidgetBoxInterface::Category::removeWidget(int idx)
272*/
273
274/*!
275 \fn void QDesignerWidgetBoxInterface::Category::addWidget(const Widget &awidget)
276*/
277
278/*!
279 \fn Type QDesignerWidgetBoxInterface::Category::type() const
280*/
281
282/*!
283 \fn void QDesignerWidgetBoxInterface::Category::setType(Type atype)
284*/
285
286/*!
287 \fn bool QDesignerWidgetBoxInterface::Category::isNull() const
288*/
289
290/*!
291 \typedef QDesignerWidgetBoxInterface::CategoryList
292 \internal
293*/
294
295/*!
296 \typedef QDesignerWidgetBoxInterface::WidgetList
297 \internal
298*/
299
300QT_END_NAMESPACE