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
container.qdoc
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4/*!
5 \class QDesignerContainerExtension
6 \brief The QDesignerContainerExtension class allows you to add pages to
7 a custom multi-page container in \QD's workspace.
8 \inmodule QtDesigner
9
10 \image containerextension-example.webp {Screenshot of \QD UI
11 editor showing option to insert page before current page to
12 an object}
13
14 QDesignerContainerExtension provide an interface for creating
15 custom container extensions. A container extension consists of a
16 collection of functions that \QD needs to manage a multi-page
17 container plugin, and a list of the container's pages.
18
19 \warning This is \e not an extension for container plugins in
20 general, only custom \e multi-page containers.
21
22 To create a container extension, your extension class must inherit
23 from both QObject and QDesignerContainerExtension. For example:
24
25 \snippet plugins/doc_src_qtdesigner.cpp 6
26
27 Since we are implementing an interface, we must ensure that it's
28 made known to the meta object system using the Q_INTERFACES()
29 macro. This enables \QD to use the qobject_cast() function to
30 query for supported interfaces using nothing but a QObject
31 pointer.
32
33 You must reimplement several functions to enable \QD to manage a
34 custom multi-page container widget: \QD uses count() to keep track
35 of the number pages in your container, widget() to return the page
36 at a given index in the list of the container's pages, and
37 currentIndex() to return the list index of the selected page. \QD
38 uses the addWidget() function to add a given page to the
39 container, expecting it to be appended to the list of pages, while
40 it expects the insertWidget() function to add a given page to the
41 container by inserting it at a given index.
42
43 In \QD the extensions are not created until they are
44 required. For that reason you must also create a
45 QExtensionFactory, i.e a class that is able to make an instance of
46 your extension, and register it using \QD's \l
47 {QExtensionManager}{extension manager}.
48
49 When a container extension is required, \QD's \l
50 {QExtensionManager}{extension manager} will run through all its
51 registered factories calling QExtensionFactory::createExtension()
52 for each until the first one that is able to create a container
53 extension, is found. This factory will then create the extension
54 for the plugin.
55
56 There are four available types of extensions in \QD:
57 QDesignerContainerExtension , QDesignerMemberSheetExtension,
58 QDesignerPropertySheetExtension and QDesignerTaskMenuExtension.
59 \QD's behavior is the same whether the requested extension is
60 associated with a multi page container, a member sheet, a property
61 sheet or a task menu.
62
63 The QExtensionFactory class provides a standard extension factory,
64 and can also be used as an interface for custom extension
65 factories. You can either create a new QExtensionFactory and
66 reimplement the QExtensionFactory::createExtension() function. For
67 example:
68
69 \snippet plugins/doc_src_qtdesigner.cpp 7
70
71 Or you can use an existing factory, expanding the
72 QExtensionFactory::createExtension() function to make the factory
73 able to create a container extension as well. For example:
74
75 \snippet plugins/doc_src_qtdesigner.cpp 8
76
77 For a complete example using the QDesignerContainerExtension
78 class, see the \l {containerextension}{Container
79 Extension example}. The example shows how to create a custom
80 multi-page plugin for \QD.
81
82 \sa QExtensionFactory, QExtensionManager, {Creating Custom Widget
83 Extensions}
84*/
85
86/*!
87 \fn QDesignerContainerExtension::~QDesignerContainerExtension()
88
89 Destroys the extension.
90*/
91
92/*!
93 \fn int QDesignerContainerExtension::count() const
94
95 Returns the number of pages in the container.
96*/
97
98/*!
99 \fn QWidget *QDesignerContainerExtension::widget(int index) const
100
101 Returns the page at the given \a index in the extension's list of
102 pages.
103
104 \sa addWidget(), insertWidget()
105*/
106
107/*!
108 \fn int QDesignerContainerExtension::currentIndex() const
109
110 Returns the index of the currently selected page in the
111 container.
112
113 \sa setCurrentIndex()
114*/
115
116/*!
117 \fn void QDesignerContainerExtension::setCurrentIndex(int index)
118
119 Sets the currently selected page in the container to be the
120 page at the given \a index in the extension's list of pages.
121
122 \sa currentIndex()
123*/
124
125/*!
126 \fn void QDesignerContainerExtension::addWidget(QWidget *page)
127
128 Adds the given \a page to the container by appending it to the
129 extension's list of pages.
130
131 \sa insertWidget(), remove(), widget()
132*/
133
134/*!
135 \fn void QDesignerContainerExtension::insertWidget(int index, QWidget *page)
136
137 Adds the given \a page to the container by inserting it at the
138 given \a index in the extension's list of pages.
139
140 \sa addWidget(), remove(), widget()
141*/
142
143/*!
144 \fn void QDesignerContainerExtension::remove(int index)
145
146 Removes the page at the given \a index from the extension's list
147 of pages.
148
149 \sa addWidget(), insertWidget()
150*/
151
152/*!
153 \fn bool QDesignerContainerExtension::canAddWidget() const
154
155 Returns whether a widget can be added. This determines whether
156 the context menu options to add or insert pages are enabled.
157
158 This should return false for containers that have a single, fixed
159 page, for example QScrollArea or QDockWidget.
160
161 \since 5.0
162 \sa addWidget(), canRemove()
163*/
164
165/*!
166 \fn bool QDesignerContainerExtension::canRemove(int index) const
167
168 Returns whether the widget at the given \a index can be removed.
169 This determines whether the context menu option to remove the current
170 page is enabled.
171
172 This should return false for containers that have a single, fixed
173 page, for example QScrollArea or QDockWidget.
174
175 \since 5.0
176 \sa remove(), canAddWidget()
177*/