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

source code of qttools/src/designer/src/lib/sdk/abstractformeditor.cpp