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
13
14#include <QtDesigner/abstractformwindow.h>
15#include <QtDesigner/abstractformwindowcursor.h>
16#include <QtDesigner/abstractlanguage.h>
17#include <QtDesigner/abstractformeditor.h>
18#include <QtDesigner/qextensionmanager.h>
19
20#include <QtWidgets/qwidget.h>
21#include <QtWidgets/qmenu.h>
22
23#include <QtGui/qaction.h>
24
25#include <QtCore/qdebug.h>
26
28
29static QAction *separatorAction(QObject *parent)
30{
31 QAction *rc = new QAction(parent);
32 rc->setSeparator(true);
33 return rc;
34}
35
36static inline QDesignerLanguageExtension *languageExtension(QDesignerFormEditorInterface *core)
37{
38 return qt_extension<QDesignerLanguageExtension*>(core->extensionManager(), core);
39}
40
41namespace qdesigner_internal {
42
57
59{
60 return m_mode;
61}
62
64{
65 m_mode = m;
66}
67
72
77
82
87
89{
90 // clear out old
94 }
95 // No promotion of main container
97 return NotApplicable;
98
99 // Check for a homogenous selection
101
104
106 // if it is promoted: demote only.
109 QAction *demoteAction = new QAction(label, this);
112 return CanDemote;
113 }
114 // figure out candidates
117 if (candidates.isEmpty()) {
118 // Is this thing promotable at all?
120 }
121
122 QMenu *candidatesMenu = new QMenu();
123 // Create a sub menu
124 // Set up actions and map class names
125 for (auto *item : candidates) {
126 const QString customClassName = item->name();
129 }
130 // Sub menu action
134 return CanPromote;
135}
136
141
144{
146 const auto previousSize = actionList.size();
148
149 // Promotion candidates/demote
151
152 // Edit action depending on context
153 switch (promotionState) {
154 case CanPromote:
156 break;
157 case CanDemote:
158 if (!(flags & SuppressGlobalEdit))
160 if (!languageExtension(fw->core())) {
163 }
164 break;
165 default:
166 if (!(flags & SuppressGlobalEdit))
168 break;
169 }
170 // Add separators if required
171 if (actionList.size() > previousSize) {
176 }
177}
178
185
190
192{
197}
198
199
201{
203}
204
206{
210
211 // ### use the undo stack
215}
216
218{
220 // Check whether invoked over a promotable widget
225 // Show over promotable widget
227 QDialog *promotionEditor = nullptr;
230 if (!promotionEditor)
234 }
235 delete promotionEditor;
236}
237
239{
240 // Global context, show over non-promotable widget
242 if (!fw)
243 return;
245}
246
248{
249 // In multi selection mode, check for a homogenous selection (same class, same promotion state)
250 // and return the list if this is the case. Also make sure m_widget
251 // is the last widget in the list so that it is re-selected as the last
252 // widget by the promotion commands.
253
255
256 if (m_mode != ModeSingleWidget) {
260 const bool promoted = isPromoted(formWindow->core(), m_widget);
261 // Just in case someone plugged an old-style Object Inspector
263 Selection s;
265 // Find objects of similar state
267 for (auto *w : source) {
268 if (w != m_widget) {
269 // Selection state mismatch
271 return PromotionSelectionList();
272 rc.push_back(w);
273 }
274 }
275 }
276 }
277
279 return rc;
280}
281
283{
284 // Use the QObject overload of QDesignerFormWindowInterface::findFormWindow since that works
285 // for QDesignerMenus also.
286 QObject *o = m_widget;
288 Q_ASSERT(result != nullptr);
289 return result;
290}
291
303
305{
307 if (!fw)
308 return;
310}
311} // namespace qdesigner_internal
312
313QT_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)