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
promotiontaskmenu.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3// Qt-Security score:significant reason:default
4
14
15#include <QtDesigner/abstractformwindow.h>
16#include <QtDesigner/abstractformwindowcursor.h>
17#include <QtDesigner/abstractlanguage.h>
18#include <QtDesigner/abstractformeditor.h>
19#include <QtDesigner/qextensionmanager.h>
20
21#include <QtWidgets/qwidget.h>
22#include <QtWidgets/qmenu.h>
23
24#include <QtGui/qaction.h>
25
26#include <QtCore/qdebug.h>
27
29
30static QAction *separatorAction(QObject *parent)
31{
32 QAction *rc = new QAction(parent);
33 rc->setSeparator(true);
34 return rc;
35}
36
37static inline QDesignerLanguageExtension *languageExtension(QDesignerFormEditorInterface *core)
38{
39 return qt_extension<QDesignerLanguageExtension*>(core->extensionManager(), core);
40}
41
42namespace qdesigner_internal {
43
58
60{
61 return m_mode;
62}
63
65{
66 m_mode = m;
67}
68
73
78
83
88
90{
91 // clear out old
95 }
96 // No promotion of main container
98 return NotApplicable;
99
100 // Check for a homogenous selection
102
105
107 // if it is promoted: demote only.
110 QAction *demoteAction = new QAction(label, this);
113 return CanDemote;
114 }
115 // figure out candidates
118 if (candidates.isEmpty()) {
119 // Is this thing promotable at all?
121 }
122
123 QMenu *candidatesMenu = new QMenu();
124 // Create a sub menu
125 // Set up actions and map class names
126 for (auto *item : candidates) {
127 const QString customClassName = item->name();
130 }
131 // Sub menu action
135 return CanPromote;
136}
137
142
145{
147 const auto previousSize = actionList.size();
149
150 // Promotion candidates/demote
152
153 // Edit action depending on context
154 switch (promotionState) {
155 case CanPromote:
157 break;
158 case CanDemote:
159 if (!(flags & SuppressGlobalEdit))
161 if (!languageExtension(fw->core())) {
164 }
165 break;
166 default:
167 if (!(flags & SuppressGlobalEdit))
169 break;
170 }
171 // Add separators if required
172 if (actionList.size() > previousSize) {
177 }
178}
179
186
191
193{
198}
199
200
202{
204}
205
207{
211
212 // ### use the undo stack
216}
217
219{
221 // Check whether invoked over a promotable widget
226 // Show over promotable widget
228 QDialog *promotionEditor = nullptr;
231 if (!promotionEditor)
235 }
236 delete promotionEditor;
237}
238
240{
241 // Global context, show over non-promotable widget
243 if (!fw)
244 return;
246}
247
249{
250 // In multi selection mode, check for a homogenous selection (same class, same promotion state)
251 // and return the list if this is the case. Also make sure m_widget
252 // is the last widget in the list so that it is re-selected as the last
253 // widget by the promotion commands.
254
256
257 if (m_mode != ModeSingleWidget) {
261 const bool promoted = isPromoted(formWindow->core(), m_widget);
262 // Just in case someone plugged an old-style Object Inspector
264 Selection s;
266 // Find objects of similar state
268 for (auto *w : source) {
269 if (w != m_widget) {
270 // Selection state mismatch
272 return PromotionSelectionList();
273 rc.push_back(w);
274 }
275 }
276 }
277 }
278
280 return rc;
281}
282
284{
285 // Use the QObject overload of QDesignerFormWindowInterface::findFormWindow since that works
286 // for QDesignerMenus also.
287 QObject *o = m_widget;
289 Q_ASSERT(result != nullptr);
290 return result;
291}
292
304
306{
308 if (!fw)
309 return;
311}
312} // namespace qdesigner_internal
313
314QT_END_NAMESPACE
Combined button and popup list for selecting options.
Auxiliary methods to store/retrieve settings.
static QT_BEGIN_NAMESPACE QAction * separatorAction(QObject *parent)
static QDesignerLanguageExtension * languageExtension(QDesignerFormEditorInterface *core)