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