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