source: trunk/doc/src/snippets/code/doc_src_qtdesigner.qdoc@ 5

Last change on this file since 5 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 6.5 KB
Line 
1//! [0]
2#include <QtDesigner>
3//! [0]
4
5
6//! [1]
7CONFIG += designer
8//! [1]
9
10
11//! [2]
12QDesignerMemberSheetExtension *memberSheet = 0;
13QExtensionManager manager = formEditor->extensionManager();
14
15memberSheet = qt_extension<QDesignerMemberSheetExtension*>(manager, widget);
16int index = memberSheet->indexOf(setEchoMode);
17memberSheet->setVisible(index, false);
18
19delete memberSheet;
20//! [2]
21
22
23//! [3]
24class MyMemberSheetExtension : public QObject,
25 public QDesignerMemberSheetExtension
26{
27 Q_OBJECT
28 Q_INTERFACES(QDesignerMemberSheetExtension)
29
30public:
31 ...
32}
33//! [3]
34
35
36//! [4]
37QObject *ANewExtensionFactory::createExtension(QObject *object,
38 const QString &iid, QObject *parent) const
39{
40 if (iid != Q_TYPEID(QDesignerMemberSheetExtension))
41 return 0;
42
43 if (MyCustomWidget *widget = qobject_cast<MyCustomWidget*>
44 (object))
45 return new MyMemberSheetExtension(widget, parent);
46
47 return 0;
48}
49//! [4]
50
51
52//! [5]
53QObject *AGeneralExtensionFactory::createExtension(QObject *object,
54 const QString &iid, QObject *parent) const
55{
56 MyCustomWidget *widget = qobject_cast<MyCustomWidget*>(object);
57
58 if (widget && (iid == Q_TYPEID(QDesignerTaskMenuExtension))) {
59 return new MyTaskMenuExtension(widget, parent);
60
61 } else if (widget && (iid == Q_TYPEID(QDesignerMemberSheetExtension))) {
62 return new MyMemberSheetExtension(widget, parent);
63
64 } else {
65 return 0;
66 }
67}
68//! [5]
69
70
71//! [6]
72class MyContainerExtension : public QObject,
73 public QDesignerContainerExtension
74{
75 Q_OBJECT
76 Q_INTERFACES(QDesignerContainerExtension)
77
78public:
79 MyContainerExtension(MyCustomWidget *widget,
80 QObject *parent = 0);
81 int count() const;
82 QWidget *widget(int index) const;
83 int currentIndex() const;
84 void setCurrentIndex(int index);
85 void addWidget(QWidget *widget);
86 void insertWidget(int index, QWidget *widget);
87 void remove(int index);
88
89private:
90 MyCustomWidget *myWidget;
91};
92//! [6]
93
94
95//! [7]
96QObject *ANewExtensionFactory::createExtension(QObject *object,
97 const QString &iid, QObject *parent) const
98{
99 if (iid != Q_TYPEID(QDesignerContainerExtension))
100 return 0;
101
102 if (MyCustomWidget *widget = qobject_cast<MyCustomWidget*>
103 (object))
104 return new MyContainerExtension(widget, parent);
105
106 return 0;
107}
108//! [7]
109
110
111//! [8]
112QObject *AGeneralExtensionFactory::createExtension(QObject *object,
113 const QString &iid, QObject *parent) const
114{
115 MyCustomWidget *widget = qobject_cast<MyCustomWidget*>(object);
116
117 if (widget && (iid == Q_TYPEID(QDesignerTaskMenuExtension))) {
118 return new MyTaskMenuExtension(widget, parent);
119
120 } else if (widget && (iid == Q_TYPEID(QDesignerContainerExtension))) {
121 return new MyContainerExtension(widget, parent);
122
123 } else {
124 return 0;
125 }
126}
127//! [8]
128
129
130//! [9]
131class MyTaskMenuExtension : public QObject,
132 public QDesignerTaskMenuExtension
133{
134 Q_OBJECT
135 Q_INTERFACES(QDesignerTaskMenuExtension)
136
137public:
138 MyTaskMenuExtension(MyCustomWidget *widget, QObject *parent);
139
140 QAction *preferredEditAction() const;
141 QList<QAction *> taskActions() const;
142
143private slots:
144 void mySlot();
145
146private:
147 MyCustomWidget *widget;
148 QAction *myAction;
149};
150//! [9]
151
152
153//! [10]
154QObject *ANewExtensionFactory::createExtension(QObject *object,
155 const QString &iid, QObject *parent) const
156{
157 if (iid != Q_TYPEID(QDesignerTaskMenuExtension))
158 return 0;
159
160 if (MyCustomWidget *widget = qobject_cast<MyCustomWidget*>(object))
161 return new MyTaskMenuExtension(widget, parent);
162
163 return 0;
164}
165//! [10]
166
167
168//! [11]
169QObject *AGeneralExtensionFactory::createExtension(QObject *object,
170 const QString &iid, QObject *parent) const
171{
172 MyCustomWidget *widget = qobject_cast<MyCustomWidget*>(object);
173
174 if (widget && (iid == Q_TYPEID(QDesignerContainerExtension))) {
175 return new MyContainerExtension(widget, parent);
176
177 } else if (widget && (iid == Q_TYPEID(QDesignerTaskMenuExtension))) {
178 return new MyTaskMenuExtension(widget, parent);
179
180 } else {
181 return 0;
182 }
183}
184//! [11]
185
186
187//! [12]
188#include customwidgetoneinterface.h
189#include customwidgettwointerface.h
190#include customwidgetthreeinterface.h
191
192#include <QtDesigner/QtDesigner>
193#include <QtCore/qplugin.h>
194
195class MyCustomWidgets: public QObject, public QDesignerCustomWidgetCollectionInterface
196{
197 Q_OBJECT
198 Q_INTERFACES(QDesignerCustomWidgetCollectionInterface)
199
200public:
201 MyCustomWidgets(QObject *parent = 0);
202
203 virtual QList<QDesignerCustomWidgetInterface*> customWidgets() const;
204
205private:
206 QList<QDesignerCustomWidgetInterface*> widgets;
207};
208//! [12]
209
210
211//! [13]
212MyCustomWidgets::MyCustomWidgets(QObject *parent)
213 : QObject(parent)
214{
215 widgets.append(new CustomWidgetOneInterface(this));
216 widgets.append(new CustomWidgetTwoInterface(this));
217 widgets.append(new CustomWidgetThreeInterface(this));
218}
219
220QList<QDesignerCustomWidgetInterface*> MyCustomWidgets::customWidgets() const
221{
222 return widgets;
223}
224
225Q_EXPORT_PLUGIN2(customwidgetsplugin, MyCustomWidgets)
226//! [13]
227
228
229//! [14]
230Q_EXPORT_PLUGIN2(customwidgetplugin, MyCustomWidget)
231//! [14]
232
233
234//! [15]
235QDesignerPropertySheetExtension *propertySheet = 0;
236QExtensionManager manager = formEditor->extensionManager();
237
238propertySheet = qt_extension<QDesignerPropertySheetExtension*>(manager, widget);
239int index = propertySheet->indexOf(QLatin1String("margin"));
240
241propertySheet->setProperty(index, 10);
242propertySheet->setChanged(index, true);
243
244delete propertySheet;
245//! [15]
246
247
248//! [16]
249class MyPropertySheetExtension : public QObject,
250 public QDesignerPropertySheetExtension
251{
252 Q_OBJECT
253 Q_INTERFACES(QDesignerPropertySheetExtension)
254
255public:
256 ...
257}
258//! [16]
259
260
261//! [17]
262QObject *ANewExtensionFactory::createExtension(QObject *object,
263 const QString &iid, QObject *parent) const
264{
265 if (iid != Q_TYPEID(QDesignerPropertySheetExtension))
266 return 0;
267
268 if (MyCustomWidget *widget = qobject_cast<MyCustomWidget*>
269 (object))
270 return new MyPropertySheetExtension(widget, parent);
271
272 return 0;
273}
274//! [17]
275
276
277//! [18]
278QObject *AGeneralExtensionFactory::createExtension(QObject *object,
279 const QString &iid, QObject *parent) const
280{
281 MyCustomWidget *widget = qobject_cast<MyCustomWidget*>(object);
282
283 if (widget && (iid == Q_TYPEID(QDesignerTaskMenuExtension))) {
284 return new MyTaskMenuExtension(widget, parent);
285
286 } else if (widget && (iid == Q_TYPEID(QDesignerPropertySheetExtension))) {
287 return new MyPropertySheetExtension(widget, parent);
288
289 } else {
290 return 0;
291 }
292}
293//! [18]
Note: See TracBrowser for help on using the repository browser.