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
taskmenu.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 QDesignerTaskMenuExtension
6
\brief The QDesignerTaskMenuExtension class allows you to add custom
7
menu entries to \QD's task menu.
8
\inmodule QtDesigner
9
10
QDesignerTaskMenuExtension provides an interface for creating
11
custom task menu extensions. It is typically used to create task
12
menu entries that are specific to a plugin in \QD.
13
14
\QD uses the QDesignerTaskMenuExtension to feed its task
15
menu. Whenever a task menu is requested, \QD will query
16
for the selected widget's task menu extension.
17
18
\image taskmenuextension-example.webp {Screenshot of a custom "Edit State..."
19
action in a context menu of \QD.}
20
21
A task menu extension is a collection of QActions. The actions
22
appear as entries in the task menu when the plugin with the
23
specified extension is selected. The image above shows the custom
24
\gui {Edit State...} action which appears in addition to \QD's
25
default task menu entries: \gui Cut, \gui Copy, \gui Paste etc.
26
27
To create a custom task menu extension, your extension class must
28
inherit from both QObject and QDesignerTaskMenuExtension. For
29
example:
30
31
\snippet plugins/doc_src_qtdesigner.cpp 9
32
33
Since we are implementing an interface, we must ensure that it
34
is made known to the meta-object system using the Q_INTERFACES()
35
macro. This enables \QD to use the qobject_cast() function to
36
query for supported interfaces using nothing but a QObject
37
pointer.
38
39
You must reimplement the taskActions() function to return a list
40
of actions that will be included in \QD task menu. Optionally, you
41
can reimplement the preferredEditAction() function to set the
42
action that is invoked when selecting your plugin and pressing
43
\key F2. The preferred edit action must be one of the actions
44
returned by taskActions() and, if it's not defined, pressing the
45
\key F2 key will simply be ignored.
46
47
In \QD, extensions are not created until they are required. A
48
task menu extension, for example, is created when you click the
49
right mouse button over a widget in \QD's workspace. For that
50
reason you must also construct an extension factory, using either
51
QExtensionFactory or a subclass, and register it using \QD's
52
\l {QExtensionManager}{extension manager}.
53
54
When a task menu extension is required, \QD's \l
55
{QExtensionManager}{extension manager} will run through all its
56
registered factories calling QExtensionFactory::createExtension()
57
for each until it finds one that is able to create a task menu
58
extension for the selected widget. This factory will then make an
59
instance of the extension.
60
61
There are four available types of extensions in \QD:
62
QDesignerContainerExtension, QDesignerMemberSheetExtension,
63
QDesignerPropertySheetExtension, and QDesignerTaskMenuExtension.
64
\QD's behavior is the same whether the requested extension is
65
associated with a container, a member sheet, a property sheet or a
66
task menu.
67
68
The QExtensionFactory class provides a standard extension factory,
69
and can also be used as an interface for custom extension
70
factories. You can either create a new QExtensionFactory and
71
reimplement the QExtensionFactory::createExtension() function. For
72
example:
73
74
\snippet plugins/doc_src_qtdesigner.cpp 10
75
76
Or you can use an existing factory, expanding the
77
QExtensionFactory::createExtension() function to make the factory
78
able to create a task menu extension as well. For example:
79
80
\snippet plugins/doc_src_qtdesigner.cpp 11
81
82
For a complete example using the QDesignerTaskMenuExtension class,
83
see the \l {taskmenuextension}{Task Menu Extension
84
example}. The example shows how to create a custom widget plugin
85
for \QD, and how to use the QDesignerTaskMenuExtension
86
class to add custom items to \QD's task menu.
87
88
\sa QExtensionFactory, QExtensionManager, {Creating Custom Widget
89
Extensions}
90
*/
91
92
/*!
93
\fn QDesignerTaskMenuExtension::~QDesignerTaskMenuExtension()
94
95
Destroys the task menu extension.
96
*/
97
98
/*!
99
\fn QAction *QDesignerTaskMenuExtension::preferredEditAction() const
100
101
Returns the action that is invoked when selecting a plugin with
102
the specified extension and pressing \key F2.
103
104
The action must be one of the actions returned by taskActions().
105
*/
106
107
/*!
108
\fn QList<QAction*> QDesignerTaskMenuExtension::taskActions() const
109
110
Returns the task menu extension as a list of actions which will be
111
included in \QD's task menu when a plugin with the specified
112
extension is selected.
113
114
The function must be reimplemented to add actions to the list.
115
*/
qttools
src
designer
src
lib
sdk
taskmenu.qdoc
Generated on
for Qt by
1.14.0