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
customwidgetsinfo.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:insignificant reason:build-tool
4
6#include "driver.h"
7#include "ui4.h"
8#include "utils.h"
9
10#include <utility>
11
13
14using namespace Qt::StringLiterals;
15
17
18void CustomWidgetsInfo::acceptUI(DomUI *node)
19{
20 m_customWidgets.clear();
21
22 if (node->elementCustomWidgets())
23 acceptCustomWidgets(node->elementCustomWidgets());
24}
25
26void CustomWidgetsInfo::acceptCustomWidgets(DomCustomWidgets *node)
27{
29}
30
31void CustomWidgetsInfo::acceptCustomWidget(DomCustomWidget *node)
32{
33 if (node->elementClass().isEmpty())
34 return;
35
36 m_customWidgets.insert(node->elementClass(), node);
37}
38
39bool CustomWidgetsInfo::extends(const QString &classNameIn, QAnyStringView baseClassName) const
40{
41 if (classNameIn == baseClassName)
42 return true;
43
44 QString className = classNameIn;
45 while (const DomCustomWidget *c = customWidget(className)) {
46 const QString extends = c->elementExtends();
47 if (className == extends) // Faulty legacy custom widget entries exist.
48 return false;
49 if (extends == baseClassName)
50 return true;
51 className = extends;
52 }
53 return false;
54}
55
56bool CustomWidgetsInfo::extendsOneOf(const QString &classNameIn,
57 const QStringList &baseClassNames) const
58{
59 if (baseClassNames.contains(classNameIn))
60 return true;
61
62 QString className = classNameIn;
63 while (const DomCustomWidget *c = customWidget(className)) {
64 const QString extends = c->elementExtends();
65 if (className == extends) // Faulty legacy custom widget entries exist.
66 return false;
67 if (baseClassNames.contains(extends))
68 return true;
69 className = extends;
70 }
71 return false;
72}
73
74bool CustomWidgetsInfo::isCustomWidgetContainer(const QString &className) const
75{
76 if (const DomCustomWidget *dcw = m_customWidgets.value(className, nullptr))
77 if (dcw->hasElementContainer())
78 return dcw->elementContainer() != 0;
79 return false;
80}
81
82// FIXME in 7.0 - QTBUG-124241
83// Remove isAmbiguous logic when widget slots have been disambiguated.
84bool CustomWidgetsInfo::isAmbiguous(const QString &className, const QString &signature,
85 QMetaMethod::MethodType type) const
86{
87 using TypeMap = QHash<QString, QMetaMethod::MethodType>;
88 struct AmbiguousInClass {
89 QLatin1StringView className;
90 TypeMap methodMap;
91 };
92
93 static const QList<AmbiguousInClass> ambiguousList = {
94
95 {"QAction"_L1, {{"triggered"_L1, QMetaMethod::Signal}}},
96 {"QCommandLinkButton"_L1, {{"triggered"_L1, QMetaMethod::Signal},
97 {"clicked"_L1, QMetaMethod::Signal}}},
98 {"QPushButton"_L1, {{"triggered"_L1, QMetaMethod::Signal},
99 {"clicked"_L1, QMetaMethod::Signal}}},
100 {"QCheckBox"_L1, {{"triggered"_L1, QMetaMethod::Signal},
101 {"clicked"_L1, QMetaMethod::Signal}}},
102 {"QRadioButton"_L1, {{"triggered"_L1, QMetaMethod::Signal},
103 {"clicked"_L1, QMetaMethod::Signal}}},
104 {"QToolButton"_L1, {{"triggered"_L1, QMetaMethod::Signal},
105 {"clicked"_L1, QMetaMethod::Signal}}},
106 {"QLabel"_L1, {{"setNum"_L1, QMetaMethod::Slot}}},
107 {"QGraphicsView"_L1, {{"invalidateScene"_L1, QMetaMethod::Slot}}},
108 {"QListView"_L1, {{"dataChanged"_L1, QMetaMethod::Slot}}},
109 {"QColumnView"_L1, {{"dataChanged"_L1, QMetaMethod::Slot}}},
110 {"QListWidget"_L1, {{"dataChanged"_L1, QMetaMethod::Slot},
111 {"scrollToItem"_L1, QMetaMethod::Slot}}},
112 {"QTableView"_L1, {{"dataChanged"_L1, QMetaMethod::Slot}}},
113 {"QTableWidget"_L1, {{"dataChanged"_L1, QMetaMethod::Slot},
114 {"scrollToItem"_L1, QMetaMethod::Slot}}},
115 {"QTreeView"_L1, {{"dataChanged"_L1, QMetaMethod::Slot},
116 {"verticalScrollbarValueChanged"_L1, QMetaMethod::Slot},
117 {"expandRecursively"_L1, QMetaMethod::Slot}}},
118 {"QTreeWidget"_L1, {{"dataChanged"_L1, QMetaMethod::Slot},
119 {"verticalScrollbarValueChanged"_L1, QMetaMethod::Slot}
120 ,{"expandRecursively"_L1, QMetaMethod::Slot}
121 ,{"scrollToItem"_L1, QMetaMethod::Slot}}},
122 {"QUndoView"_L1, {{"dataChanged"_L1, QMetaMethod::Slot}}},
123 {"QLCDNumber"_L1, {{"display"_L1, QMetaMethod::Slot}}},
124 {"QMenuBar"_L1, {{"setVisible"_L1, QMetaMethod::Slot}}},
125 {"QTextBrowser"_L1, {{"setSource"_L1, QMetaMethod::Slot}}},
126
127 /*
128 The following widgets with ambiguities are not used in the widget designer:
129
130 {"QSplashScreen"_L1, {{"showMessage"_L1, QMetaMethod::Slot}}},
131 {"QCompleter"_L1, {{"activated"_L1, QMetaMethod::Signal},
132 {"highlighted"_L1, QMetaMethod::Signal}}},
133 {"QSystemTrayIcon"_L1, {{"showMessage"_L1, QMetaMethod::Slot}}},
134 {"QStyledItemDelegate"_L1, {{"closeEditor"_L1, QMetaMethod::Signal}}},
135 {"QErrorMessage"_L1, {{"showMessage"_L1, QMetaMethod::Slot}}},
136 {"QGraphicsDropShadowEffect"_L1, {{"setOffset"_L1, QMetaMethod::Slot}}},
137 {"QGraphicsScene"_L1, {{"invalidate"_L1, QMetaMethod::Slot}}},
138 {"QItemDelegate"_L1, {{"closeEditor"_L1, QMetaMethod::Signal}}}
139 */
140 };
141
142 for (auto it = ambiguousList.constBegin(); it != ambiguousList.constEnd(); ++it) {
143 if (extends(className, it->className)) {
144 const qsizetype pos = signature.indexOf(u'(');
145 const QString method = signature.left(pos);
146 const auto methodIterator = it->methodMap.find(method);
147 return methodIterator != it->methodMap.constEnd() && type == methodIterator.value();
148 }
149 }
150 return false;
151}
152
153// Is it ambiguous, resulting in different signals for Python
154// "QAbstractButton::clicked(checked=false)"
155bool CustomWidgetsInfo::isAmbiguousSignal(const QString &className,
156 const QString &signalSignature) const
157{
158 return isAmbiguous(className, signalSignature, QMetaMethod::Signal);
159}
160
161bool CustomWidgetsInfo::isAmbiguousSlot(const QString &className,
162 const QString &signalSignature) const
163{
164 return isAmbiguous(className, signalSignature, QMetaMethod::Slot);
165}
166
167QString CustomWidgetsInfo::realClassName(const QString &className)
168{
169 if (className == "Line"_L1)
170 return u"QFrame"_s;
171
172 return className;
173}
174
175QString CustomWidgetsInfo::customWidgetAddPageMethod(const QString &name) const
176{
177 if (DomCustomWidget *dcw = m_customWidgets.value(name, nullptr))
178 return dcw->elementAddPageMethod();
179 return {};
180}
181
182// add page methods for simple containers taking only the widget parameter
183QString CustomWidgetsInfo::simpleContainerAddPageMethod(const QString &name) const
184{
185 using AddPageMethod = std::pair<QString, QString>;
186
187 static const AddPageMethod addPageMethods[] = {
188 {u"QStackedWidget"_s, u"addWidget"_s},
189 {u"QToolBar"_s, u"addWidget"_s},
190 {u"QDockWidget"_s, u"setWidget"_s},
191 {u"QScrollArea"_s, u"setWidget"_s},
192 {u"QSplitter"_s, u"addWidget"_s},
193 {u"QMdiArea"_s, u"addSubWindow"_s}
194 };
195 for (const auto &m : addPageMethods) {
196 if (extends(name, m.first))
197 return m.second;
198 }
199 return {};
200}
201
202QT_END_NAMESPACE
bool isCustomWidgetContainer(const QString &className) const
bool isAmbiguousSlot(const QString &className, const QString &slotSignature) const
void acceptUI(DomUI *node) override
bool isAmbiguousSignal(const QString &className, const QString &signalSignature) const
bool extendsOneOf(const QString &className, const QStringList &baseClassNames) const
QString customWidgetAddPageMethod(const QString &name) const
bool extends(const QString &className, QAnyStringView baseClassName) const
QString simpleContainerAddPageMethod(const QString &name) const
void acceptCustomWidgets(DomCustomWidgets *node) override
void acceptCustomWidget(DomCustomWidget *node) override
Definition qlist.h:82
Combined button and popup list for selecting options.
virtual void acceptCustomWidgets(DomCustomWidgets *customWidgets)