1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the Qt Designer of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
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 http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file. Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include "abstractformeditor.h"
43 #include "abstractdialoggui_p.h"
44 #include "abstractintrospection_p.h"
45 #include "abstractsettings_p.h"
46 #include "abstractoptionspage_p.h"
47
48 #include <QtDesigner/QDesignerWidgetBoxInterface>
49 #include <QtDesigner/QDesignerPropertyEditorInterface>
50 #include <QtDesigner/QDesignerFormWindowManagerInterface>
51 #include <QtDesigner/QExtensionManager>
52 #include <QtDesigner/QDesignerMetaDataBaseInterface>
53 #include <QtDesigner/QDesignerWidgetDataBaseInterface>
54 #include <QtDesigner/QDesignerWidgetFactoryInterface>
55 #include <QtDesigner/QDesignerObjectInspectorInterface>
56 #include <QtDesigner/QDesignerBrushManagerInterface>
57 #include <QtDesigner/QDesignerIntegrationInterface>
58 #include <QtDesigner/QDesignerIconCacheInterface>
59 #include <QtDesigner/QDesignerActionEditorInterface>
60 #include <pluginmanager_p.h>
61 #include <qtresourcemodel_p.h>
62 #include <qtgradientmanager.h>
63 #include <widgetfactory_p.h>
64 #include <shared_settings_p.h>
65 #include <formwindowbase_p.h>
66 #include <grid_p.h>
67 #include <QtDesigner/QDesignerPromotionInterface>
68
69 // Must be done outside of the Qt namespace
initResources()70 static void initResources()
71 {
72 Q_INIT_RESOURCE(shared);
73 Q_INIT_RESOURCE(ClamshellPhone);
74 Q_INIT_RESOURCE(PortableMedia);
75 Q_INIT_RESOURCE(S60_nHD_Touchscreen);
76 Q_INIT_RESOURCE(S60_QVGA_Candybar);
77 Q_INIT_RESOURCE(SmartPhone2);
78 Q_INIT_RESOURCE(SmartPhone);
79 Q_INIT_RESOURCE(SmartPhoneWithButtons);
80 Q_INIT_RESOURCE(TouchscreenPhone);
81 }
82
83 QT_BEGIN_NAMESPACE
84
85 class QDesignerFormEditorInterfacePrivate {
86 public:
87 QDesignerFormEditorInterfacePrivate();
88 ~QDesignerFormEditorInterfacePrivate();
89
90
91 QPointer<QWidget> m_topLevel;
92 QPointer<QDesignerWidgetBoxInterface> m_widgetBox;
93 QPointer<QDesignerPropertyEditorInterface> m_propertyEditor;
94 QPointer<QDesignerFormWindowManagerInterface> m_formWindowManager;
95 QPointer<QExtensionManager> m_extensionManager;
96 QPointer<QDesignerMetaDataBaseInterface> m_metaDataBase;
97 QPointer<QDesignerWidgetDataBaseInterface> m_widgetDataBase;
98 QPointer<QDesignerWidgetFactoryInterface> m_widgetFactory;
99 QPointer<QDesignerObjectInspectorInterface> m_objectInspector;
100 QPointer<QDesignerBrushManagerInterface> m_brushManager;
101 QPointer<QDesignerIntegrationInterface> m_integration;
102 QPointer<QDesignerIconCacheInterface> m_iconCache;
103 QPointer<QDesignerActionEditorInterface> m_actionEditor;
104 QDesignerSettingsInterface *m_settingsManager;
105 QDesignerPluginManager *m_pluginManager;
106 QDesignerPromotionInterface *m_promotion;
107 QDesignerIntrospectionInterface *m_introspection;
108 QDesignerDialogGuiInterface *m_dialogGui;
109 QPointer<QtResourceModel> m_resourceModel;
110 QPointer<QtGradientManager> m_gradientManager; // instantiated and deleted by designer_integration
111 QList<QDesignerOptionsPageInterface*> m_optionsPages;
112 };
113
QDesignerFormEditorInterfacePrivate()114 QDesignerFormEditorInterfacePrivate::QDesignerFormEditorInterfacePrivate() :
115 m_settingsManager(0),
116 m_pluginManager(0),
117 m_promotion(0),
118 m_introspection(0),
119 m_dialogGui(0),
120 m_resourceModel(0),
121 m_gradientManager(0)
122 {
123 }
124
~QDesignerFormEditorInterfacePrivate()125 QDesignerFormEditorInterfacePrivate::~QDesignerFormEditorInterfacePrivate()
126 {
127 delete m_settingsManager;
128 delete m_formWindowManager;
129 delete m_promotion;
130 delete m_introspection;
131 delete m_dialogGui;
132 delete m_resourceModel;
133 qDeleteAll(m_optionsPages);
134 }
135
136 /*!
137 \class QDesignerFormEditorInterface
138
139 \brief The QDesignerFormEditorInterface class allows you to access
140 Qt Designer's various components.
141
142 \inmodule QtDesigner
143
144 \QD's current QDesignerFormEditorInterface object holds
145 information about all \QD's components: The action editor, the
146 object inspector, the property editor, the widget box, and the
147 extension and form window managers. QDesignerFormEditorInterface
148 contains a collection of functions that provides interfaces to all
149 these components. They are typically used to query (and
150 manipulate) the respective component. For example:
151
152 \snippet doc/src/snippets/code/tools_designer_src_lib_sdk_abstractformeditor.cpp 0
153
154 QDesignerFormEditorInterface is not intended to be instantiated
155 directly. A pointer to \QD's current QDesignerFormEditorInterface
156 object (\c formEditor in the example above) is provided by the
157 QDesignerCustomWidgetInterface::initialize() function's
158 parameter. When implementing a custom widget plugin, you must
159 subclass the QDesignerCustomWidgetInterface to expose your plugin
160 to \QD.
161
162 QDesignerFormEditorInterface also provides functions that can set
163 the action editor, property editor, object inspector and widget
164 box. These are only useful if you want to provide your own custom
165 components.
166
167 If designer is embedded in another program, one could to provide its
168 own settings manager. The manager is used by the components of \QD
169 to store/retrieve persistent configuration settings. The default
170 manager uses QSettings as the backend.
171
172 Finally, QDesignerFormEditorInterface provides the topLevel()
173 function that returns \QD's top-level widget.
174
175 \sa QDesignerCustomWidgetInterface
176 */
177
178 /*!
179 Constructs a QDesignerFormEditorInterface object with the given \a
180 parent.
181 */
182
QDesignerFormEditorInterface(QObject * parent)183 QDesignerFormEditorInterface::QDesignerFormEditorInterface(QObject *parent)
184 : QObject(parent),
185 d(new QDesignerFormEditorInterfacePrivate())
186 {
187 initResources();
188 }
189
190 /*!
191 Destroys the QDesignerFormEditorInterface object.
192 */
~QDesignerFormEditorInterface()193 QDesignerFormEditorInterface::~QDesignerFormEditorInterface()
194 {
195 delete d;
196 }
197
198 /*!
199 Returns an interface to \QD's widget box.
200
201 \sa setWidgetBox()
202 */
widgetBox() const203 QDesignerWidgetBoxInterface *QDesignerFormEditorInterface::widgetBox() const
204 {
205 return d->m_widgetBox;
206 }
207
208 /*!
209 Sets \QD's widget box to be the specified \a widgetBox.
210
211 \sa widgetBox()
212 */
setWidgetBox(QDesignerWidgetBoxInterface * widgetBox)213 void QDesignerFormEditorInterface::setWidgetBox(QDesignerWidgetBoxInterface *widgetBox)
214 {
215 d->m_widgetBox = widgetBox;
216 }
217
218 /*!
219 Returns an interface to \QD's property editor.
220
221 \sa setPropertyEditor()
222 */
propertyEditor() const223 QDesignerPropertyEditorInterface *QDesignerFormEditorInterface::propertyEditor() const
224 {
225 return d->m_propertyEditor;
226 }
227
228 /*!
229 Sets \QD's property editor to be the specified \a propertyEditor.
230
231 \sa propertyEditor()
232 */
setPropertyEditor(QDesignerPropertyEditorInterface * propertyEditor)233 void QDesignerFormEditorInterface::setPropertyEditor(QDesignerPropertyEditorInterface *propertyEditor)
234 {
235 d->m_propertyEditor = propertyEditor;
236 }
237
238 /*!
239 Returns an interface to \QD's action editor.
240
241 \sa setActionEditor()
242 */
actionEditor() const243 QDesignerActionEditorInterface *QDesignerFormEditorInterface::actionEditor() const
244 {
245 return d->m_actionEditor;
246 }
247
248 /*!
249 Sets \QD's action editor to be the specified \a actionEditor.
250
251 \sa actionEditor()
252 */
setActionEditor(QDesignerActionEditorInterface * actionEditor)253 void QDesignerFormEditorInterface::setActionEditor(QDesignerActionEditorInterface *actionEditor)
254 {
255 d->m_actionEditor = actionEditor;
256 }
257
258 /*!
259 Returns \QD's top-level widget.
260 */
topLevel() const261 QWidget *QDesignerFormEditorInterface::topLevel() const
262 {
263 return d->m_topLevel;
264 }
265
266 /*!
267 \internal
268 */
setTopLevel(QWidget * topLevel)269 void QDesignerFormEditorInterface::setTopLevel(QWidget *topLevel)
270 {
271 d->m_topLevel = topLevel;
272 }
273
274 /*!
275 Returns an interface to \QD's form window manager.
276 */
formWindowManager() const277 QDesignerFormWindowManagerInterface *QDesignerFormEditorInterface::formWindowManager() const
278 {
279 return d->m_formWindowManager;
280 }
281
282 /*!
283 \internal
284 */
setFormManager(QDesignerFormWindowManagerInterface * formWindowManager)285 void QDesignerFormEditorInterface::setFormManager(QDesignerFormWindowManagerInterface *formWindowManager)
286 {
287 d->m_formWindowManager = formWindowManager;
288 }
289
290 /*!
291 Returns an interface to \QD's extension manager.
292 */
extensionManager() const293 QExtensionManager *QDesignerFormEditorInterface::extensionManager() const
294 {
295 return d->m_extensionManager;
296 }
297
298 /*!
299 \internal
300 */
setExtensionManager(QExtensionManager * extensionManager)301 void QDesignerFormEditorInterface::setExtensionManager(QExtensionManager *extensionManager)
302 {
303 d->m_extensionManager = extensionManager;
304 }
305
306 /*!
307 \internal
308
309 Returns an interface to the meta database used by the form editor.
310 */
metaDataBase() const311 QDesignerMetaDataBaseInterface *QDesignerFormEditorInterface::metaDataBase() const
312 {
313 return d->m_metaDataBase;
314 }
315
316 /*!
317 \internal
318 */
setMetaDataBase(QDesignerMetaDataBaseInterface * metaDataBase)319 void QDesignerFormEditorInterface::setMetaDataBase(QDesignerMetaDataBaseInterface *metaDataBase)
320 {
321 d->m_metaDataBase = metaDataBase;
322 }
323
324 /*!
325 \internal
326
327 Returns an interface to the widget database used by the form editor.
328 */
widgetDataBase() const329 QDesignerWidgetDataBaseInterface *QDesignerFormEditorInterface::widgetDataBase() const
330 {
331 return d->m_widgetDataBase;
332 }
333
334 /*!
335 \internal
336 */
setWidgetDataBase(QDesignerWidgetDataBaseInterface * widgetDataBase)337 void QDesignerFormEditorInterface::setWidgetDataBase(QDesignerWidgetDataBaseInterface *widgetDataBase)
338 {
339 d->m_widgetDataBase = widgetDataBase;
340 }
341
342 /*!
343 \internal
344
345 Returns an interface to the designer promotion handler.
346 */
347
promotion() const348 QDesignerPromotionInterface *QDesignerFormEditorInterface::promotion() const
349 {
350 return d->m_promotion;
351 }
352
353 /*!
354 \internal
355
356 Sets the designer promotion handler.
357 */
358
setPromotion(QDesignerPromotionInterface * promotion)359 void QDesignerFormEditorInterface::setPromotion(QDesignerPromotionInterface *promotion)
360 {
361 if (d->m_promotion)
362 delete d->m_promotion;
363 d->m_promotion = promotion;
364 }
365
366 /*!
367 \internal
368
369 Returns an interface to the widget factory used by the form editor
370 to create widgets for the form.
371 */
widgetFactory() const372 QDesignerWidgetFactoryInterface *QDesignerFormEditorInterface::widgetFactory() const
373 {
374 return d->m_widgetFactory;
375 }
376
377 /*!
378 \internal
379 */
setWidgetFactory(QDesignerWidgetFactoryInterface * widgetFactory)380 void QDesignerFormEditorInterface::setWidgetFactory(QDesignerWidgetFactoryInterface *widgetFactory)
381 {
382 d->m_widgetFactory = widgetFactory;
383 }
384
385 /*!
386 Returns an interface to \QD's object inspector.
387 */
objectInspector() const388 QDesignerObjectInspectorInterface *QDesignerFormEditorInterface::objectInspector() const
389 {
390 return d->m_objectInspector;
391 }
392
393 /*!
394 Sets \QD's object inspector to be the specified \a
395 objectInspector.
396
397 \sa objectInspector()
398 */
setObjectInspector(QDesignerObjectInspectorInterface * objectInspector)399 void QDesignerFormEditorInterface::setObjectInspector(QDesignerObjectInspectorInterface *objectInspector)
400 {
401 d->m_objectInspector = objectInspector;
402 }
403
404 /*!
405 \internal
406
407 Returns an interface to the brush manager used by the palette editor.
408 */
brushManager() const409 QDesignerBrushManagerInterface *QDesignerFormEditorInterface::brushManager() const
410 {
411 return d->m_brushManager;
412 }
413
414 /*!
415 \internal
416 */
setBrushManager(QDesignerBrushManagerInterface * brushManager)417 void QDesignerFormEditorInterface::setBrushManager(QDesignerBrushManagerInterface *brushManager)
418 {
419 d->m_brushManager = brushManager;
420 }
421
422 /*!
423 \internal
424
425 Returns an interface to the integration.
426 */
integration() const427 QDesignerIntegrationInterface *QDesignerFormEditorInterface::integration() const
428 {
429 return d->m_integration;
430 }
431
432 /*!
433 \internal
434 */
setIntegration(QDesignerIntegrationInterface * integration)435 void QDesignerFormEditorInterface::setIntegration(QDesignerIntegrationInterface *integration)
436 {
437 d->m_integration = integration;
438 }
439
440 /*!
441 \internal
442
443 Returns an interface to the icon cache used by the form editor to
444 manage icons.
445 */
iconCache() const446 QDesignerIconCacheInterface *QDesignerFormEditorInterface::iconCache() const
447 {
448 return d->m_iconCache;
449 }
450
451 /*!
452 \internal
453 */
setIconCache(QDesignerIconCacheInterface * cache)454 void QDesignerFormEditorInterface::setIconCache(QDesignerIconCacheInterface *cache)
455 {
456 d->m_iconCache = cache;
457 }
458
459 /*!
460 \internal
461 \since 4.5
462 Returns the list of options pages that allow the user to configure \QD components.
463 */
optionsPages() const464 QList<QDesignerOptionsPageInterface*> QDesignerFormEditorInterface::optionsPages() const
465 {
466 return d->m_optionsPages;
467 }
468
469 /*!
470 \internal
471 \since 4.5
472 Sets the list of options pages that allow the user to configure \QD components.
473 */
setOptionsPages(const QList<QDesignerOptionsPageInterface * > & optionsPages)474 void QDesignerFormEditorInterface::setOptionsPages(const QList<QDesignerOptionsPageInterface*> &optionsPages)
475 {
476 d->m_optionsPages = optionsPages;
477 }
478
479
480 /*!
481 \internal
482
483 Returns the plugin manager used by the form editor.
484 */
pluginManager() const485 QDesignerPluginManager *QDesignerFormEditorInterface::pluginManager() const
486 {
487 return d->m_pluginManager;
488 }
489
490 /*!
491 \internal
492
493 Sets the plugin manager used by the form editor to the specified
494 \a pluginManager.
495 */
setPluginManager(QDesignerPluginManager * pluginManager)496 void QDesignerFormEditorInterface::setPluginManager(QDesignerPluginManager *pluginManager)
497 {
498 d->m_pluginManager = pluginManager;
499 }
500
501 /*!
502 \internal
503 \since 4.4
504 Returns the resource model used by the form editor.
505 */
resourceModel() const506 QtResourceModel *QDesignerFormEditorInterface::resourceModel() const
507 {
508 return d->m_resourceModel;
509 }
510
511 /*!
512 \internal
513
514 Sets the resource model used by the form editor to the specified
515 \a resourceModel.
516 */
setResourceModel(QtResourceModel * resourceModel)517 void QDesignerFormEditorInterface::setResourceModel(QtResourceModel *resourceModel)
518 {
519 d->m_resourceModel = resourceModel;
520 }
521
522 /*!
523 \internal
524 \since 4.4
525 Returns the gradient manager used by the style sheet editor.
526 */
gradientManager() const527 QtGradientManager *QDesignerFormEditorInterface::gradientManager() const
528 {
529 return d->m_gradientManager;
530 }
531
532 /*!
533 \internal
534
535 Sets the gradient manager used by the style sheet editor to the specified
536 \a gradientManager.
537 */
setGradientManager(QtGradientManager * gradientManager)538 void QDesignerFormEditorInterface::setGradientManager(QtGradientManager *gradientManager)
539 {
540 d->m_gradientManager = gradientManager;
541 }
542
543 /*!
544 \internal
545 \since 4.5
546 Returns the settings manager used by the components to store persistent settings.
547 */
settingsManager() const548 QDesignerSettingsInterface *QDesignerFormEditorInterface::settingsManager() const
549 {
550 return d->m_settingsManager;
551 }
552
553 /*!
554 \internal
555 \since 4.5
556 Sets the settings manager used to store/retrieve the persistent settings of the components.
557 */
setSettingsManager(QDesignerSettingsInterface * settingsManager)558 void QDesignerFormEditorInterface::setSettingsManager(QDesignerSettingsInterface *settingsManager)
559 {
560 if (d->m_settingsManager)
561 delete d->m_settingsManager;
562 d->m_settingsManager = settingsManager;
563
564 // This is a (hopefully) safe place to perform settings-dependent
565 // initializations.
566 const qdesigner_internal::QDesignerSharedSettings settings(this);
567 qdesigner_internal::FormWindowBase::setDefaultDesignerGrid(settings.defaultGrid());
568 }
569
570 /*!
571 \internal
572 \since 4.4
573 Returns the introspection used by the form editor.
574 */
introspection() const575 QDesignerIntrospectionInterface *QDesignerFormEditorInterface::introspection() const
576 {
577 return d->m_introspection;
578 }
579
580 /*!
581 \internal
582 \since 4.4
583
584 Sets the introspection used by the form editor to the specified \a introspection.
585 */
setIntrospection(QDesignerIntrospectionInterface * introspection)586 void QDesignerFormEditorInterface::setIntrospection(QDesignerIntrospectionInterface *introspection)
587 {
588 if (d->m_introspection)
589 delete d->m_introspection;
590 d->m_introspection = introspection;
591 }
592
593 /*!
594 \internal
595
596 Returns the path to the resources used by the form editor.
597 */
resourceLocation() const598 QString QDesignerFormEditorInterface::resourceLocation() const
599 {
600 #ifdef Q_WS_MAC
601 return QLatin1String(":/trolltech/formeditor/images/mac");
602 #else
603 return QLatin1String(":/trolltech/formeditor/images/win");
604 #endif
605 }
606
607 /*!
608 \internal
609
610 Returns the dialog GUI used by the form editor.
611 */
612
dialogGui() const613 QDesignerDialogGuiInterface *QDesignerFormEditorInterface::dialogGui() const
614 {
615 return d->m_dialogGui;
616 }
617
618 /*!
619 \internal
620
621 Sets the dialog GUI used by the form editor to the specified \a dialogGui.
622 */
623
setDialogGui(QDesignerDialogGuiInterface * dialogGui)624 void QDesignerFormEditorInterface::setDialogGui(QDesignerDialogGuiInterface *dialogGui)
625 {
626 delete d->m_dialogGui;
627 d->m_dialogGui = dialogGui;
628 }
629
630 QT_END_NAMESPACE
631