1 | //! [0]
|
---|
2 | #include <QtDesigner>
|
---|
3 | //! [0]
|
---|
4 |
|
---|
5 |
|
---|
6 | //! [1]
|
---|
7 | CONFIG += designer
|
---|
8 | //! [1]
|
---|
9 |
|
---|
10 |
|
---|
11 | //! [2]
|
---|
12 | QDesignerMemberSheetExtension *memberSheet = 0;
|
---|
13 | QExtensionManager manager = formEditor->extensionManager();
|
---|
14 |
|
---|
15 | memberSheet = qt_extension<QDesignerMemberSheetExtension*>(manager, widget);
|
---|
16 | int index = memberSheet->indexOf(setEchoMode);
|
---|
17 | memberSheet->setVisible(index, false);
|
---|
18 |
|
---|
19 | delete memberSheet;
|
---|
20 | //! [2]
|
---|
21 |
|
---|
22 |
|
---|
23 | //! [3]
|
---|
24 | class MyMemberSheetExtension : public QObject,
|
---|
25 | public QDesignerMemberSheetExtension
|
---|
26 | {
|
---|
27 | Q_OBJECT
|
---|
28 | Q_INTERFACES(QDesignerMemberSheetExtension)
|
---|
29 |
|
---|
30 | public:
|
---|
31 | ...
|
---|
32 | }
|
---|
33 | //! [3]
|
---|
34 |
|
---|
35 |
|
---|
36 | //! [4]
|
---|
37 | QObject *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]
|
---|
53 | QObject *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]
|
---|
72 | class MyContainerExtension : public QObject,
|
---|
73 | public QDesignerContainerExtension
|
---|
74 | {
|
---|
75 | Q_OBJECT
|
---|
76 | Q_INTERFACES(QDesignerContainerExtension)
|
---|
77 |
|
---|
78 | public:
|
---|
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 |
|
---|
89 | private:
|
---|
90 | MyCustomWidget *myWidget;
|
---|
91 | };
|
---|
92 | //! [6]
|
---|
93 |
|
---|
94 |
|
---|
95 | //! [7]
|
---|
96 | QObject *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]
|
---|
112 | QObject *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]
|
---|
131 | class MyTaskMenuExtension : public QObject,
|
---|
132 | public QDesignerTaskMenuExtension
|
---|
133 | {
|
---|
134 | Q_OBJECT
|
---|
135 | Q_INTERFACES(QDesignerTaskMenuExtension)
|
---|
136 |
|
---|
137 | public:
|
---|
138 | MyTaskMenuExtension(MyCustomWidget *widget, QObject *parent);
|
---|
139 |
|
---|
140 | QAction *preferredEditAction() const;
|
---|
141 | QList<QAction *> taskActions() const;
|
---|
142 |
|
---|
143 | private slots:
|
---|
144 | void mySlot();
|
---|
145 |
|
---|
146 | private:
|
---|
147 | MyCustomWidget *widget;
|
---|
148 | QAction *myAction;
|
---|
149 | };
|
---|
150 | //! [9]
|
---|
151 |
|
---|
152 |
|
---|
153 | //! [10]
|
---|
154 | QObject *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]
|
---|
169 | QObject *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 |
|
---|
195 | class MyCustomWidgets: public QObject, public QDesignerCustomWidgetCollectionInterface
|
---|
196 | {
|
---|
197 | Q_OBJECT
|
---|
198 | Q_INTERFACES(QDesignerCustomWidgetCollectionInterface)
|
---|
199 |
|
---|
200 | public:
|
---|
201 | MyCustomWidgets(QObject *parent = 0);
|
---|
202 |
|
---|
203 | virtual QList<QDesignerCustomWidgetInterface*> customWidgets() const;
|
---|
204 |
|
---|
205 | private:
|
---|
206 | QList<QDesignerCustomWidgetInterface*> widgets;
|
---|
207 | };
|
---|
208 | //! [12]
|
---|
209 |
|
---|
210 |
|
---|
211 | //! [13]
|
---|
212 | MyCustomWidgets::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 |
|
---|
220 | QList<QDesignerCustomWidgetInterface*> MyCustomWidgets::customWidgets() const
|
---|
221 | {
|
---|
222 | return widgets;
|
---|
223 | }
|
---|
224 |
|
---|
225 | Q_EXPORT_PLUGIN2(customwidgetsplugin, MyCustomWidgets)
|
---|
226 | //! [13]
|
---|
227 |
|
---|
228 |
|
---|
229 | //! [14]
|
---|
230 | Q_EXPORT_PLUGIN2(customwidgetplugin, MyCustomWidget)
|
---|
231 | //! [14]
|
---|
232 |
|
---|
233 |
|
---|
234 | //! [15]
|
---|
235 | QDesignerPropertySheetExtension *propertySheet = 0;
|
---|
236 | QExtensionManager manager = formEditor->extensionManager();
|
---|
237 |
|
---|
238 | propertySheet = qt_extension<QDesignerPropertySheetExtension*>(manager, widget);
|
---|
239 | int index = propertySheet->indexOf(QLatin1String("margin"));
|
---|
240 |
|
---|
241 | propertySheet->setProperty(index, 10);
|
---|
242 | propertySheet->setChanged(index, true);
|
---|
243 |
|
---|
244 | delete propertySheet;
|
---|
245 | //! [15]
|
---|
246 |
|
---|
247 |
|
---|
248 | //! [16]
|
---|
249 | class MyPropertySheetExtension : public QObject,
|
---|
250 | public QDesignerPropertySheetExtension
|
---|
251 | {
|
---|
252 | Q_OBJECT
|
---|
253 | Q_INTERFACES(QDesignerPropertySheetExtension)
|
---|
254 |
|
---|
255 | public:
|
---|
256 | ...
|
---|
257 | }
|
---|
258 | //! [16]
|
---|
259 |
|
---|
260 |
|
---|
261 | //! [17]
|
---|
262 | QObject *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]
|
---|
278 | QObject *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]
|
---|