Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
4#include "customwidgetsinfo.h"
5#include "driver.h"
6#include "ui4.h"
7#include "utils.h"
8
9#include <utility>
10
12
13using namespace Qt::StringLiterals;
14
16
18{
19 m_customWidgets.clear();
20
21 if (node->elementCustomWidgets())
23}
24
29
31{
32 if (node->elementClass().isEmpty())
33 return;
34
35 m_customWidgets.insert(node->elementClass(), node);
36}
37
38bool CustomWidgetsInfo::extends(const QString &classNameIn, QAnyStringView baseClassName) const
39{
40 if (classNameIn == baseClassName)
41 return true;
42
43 QString className = classNameIn;
44 while (const DomCustomWidget *c = customWidget(className)) {
45 const QString extends = c->elementExtends();
46 if (className == extends) // Faulty legacy custom widget entries exist.
47 return false;
48 if (extends == baseClassName)
49 return true;
51 }
52 return false;
53}
54
56 const QStringList &baseClassNames) const
57{
58 if (baseClassNames.contains(classNameIn))
59 return true;
60
61 QString className = classNameIn;
62 while (const DomCustomWidget *c = customWidget(className)) {
63 const QString extends = c->elementExtends();
64 if (className == extends) // Faulty legacy custom widget entries exist.
65 return false;
66 if (baseClassNames.contains(extends))
67 return true;
69 }
70 return false;
71}
72
74{
75 if (const DomCustomWidget *dcw = m_customWidgets.value(className, nullptr))
76 if (dcw->hasElementContainer())
77 return dcw->elementContainer() != 0;
78 return false;
79}
80
81// FIXME in 7.0 - QTBUG-124241
82// Remove isAmbiguous logic when widget slots have been disambiguated.
83bool CustomWidgetsInfo::isAmbiguous(const QString &className, const QString &signature,
85{
86 using TypeMap = QHash<QString, QMetaMethod::MethodType>;
87 struct AmbiguousInClass {
89 TypeMap methodMap;
90 };
91
92 static const QList<AmbiguousInClass> ambiguousList = {
93
94 {"QAction"_L1, {{"triggered"_L1, QMetaMethod::Signal}}},
95 {"QCommandLinkButton"_L1, {{"triggered"_L1, QMetaMethod::Signal},
96 {"clicked"_L1, QMetaMethod::Signal}}},
97 {"QPushButton"_L1, {{"triggered"_L1, QMetaMethod::Signal},
98 {"clicked"_L1, QMetaMethod::Signal}}},
99 {"QCheckBox"_L1, {{"triggered"_L1, QMetaMethod::Signal},
100 {"clicked"_L1, QMetaMethod::Signal}}},
101 {"QRadioButton"_L1, {{"triggered"_L1, QMetaMethod::Signal},
102 {"clicked"_L1, QMetaMethod::Signal}}},
103 {"QToolButton"_L1, {{"triggered"_L1, QMetaMethod::Signal},
104 {"clicked"_L1, QMetaMethod::Signal}}},
105 {"QLabel"_L1, {{"setNum"_L1, QMetaMethod::Slot}}},
106 {"QGraphicsView"_L1, {{"invalidateScene"_L1, QMetaMethod::Slot}}},
107 {"QListView"_L1, {{"dataChanged"_L1, QMetaMethod::Slot}}},
108 {"QColumnView"_L1, {{"dataChanged"_L1, QMetaMethod::Slot}}},
109 {"QListWidget"_L1, {{"dataChanged"_L1, QMetaMethod::Slot},
110 {"scrollToItem"_L1, QMetaMethod::Slot}}},
111 {"QTableView"_L1, {{"dataChanged"_L1, QMetaMethod::Slot}}},
112 {"QTableWidget"_L1, {{"dataChanged"_L1, QMetaMethod::Slot},
113 {"scrollToItem"_L1, QMetaMethod::Slot}}},
114 {"QTreeView"_L1, {{"dataChanged"_L1, QMetaMethod::Slot},
115 {"verticalScrollbarValueChanged"_L1, QMetaMethod::Slot},
116 {"expandRecursively"_L1, QMetaMethod::Slot}}},
117 {"QTreeWidget"_L1, {{"dataChanged"_L1, QMetaMethod::Slot},
118 {"verticalScrollbarValueChanged"_L1, QMetaMethod::Slot}
119 ,{"expandRecursively"_L1, QMetaMethod::Slot}
120 ,{"scrollToItem"_L1, QMetaMethod::Slot}}},
121 {"QUndoView"_L1, {{"dataChanged"_L1, QMetaMethod::Slot}}},
122 {"QLCDNumber"_L1, {{"display"_L1, QMetaMethod::Slot}}},
123 {"QMenuBar"_L1, {{"setVisible"_L1, QMetaMethod::Slot}}},
124 {"QTextBrowser"_L1, {{"setSource"_L1, QMetaMethod::Slot}}},
125
126 /*
127 The following widgets with ambiguities are not used in the widget designer:
128
129 {"QSplashScreen"_L1, {{"showMessage"_L1, QMetaMethod::Slot}}},
130 {"QCompleter"_L1, {{"activated"_L1, QMetaMethod::Signal},
131 {"highlighted"_L1, QMetaMethod::Signal}}},
132 {"QSystemTrayIcon"_L1, {{"showMessage"_L1, QMetaMethod::Slot}}},
133 {"QStyledItemDelegate"_L1, {{"closeEditor"_L1, QMetaMethod::Signal}}},
134 {"QErrorMessage"_L1, {{"showMessage"_L1, QMetaMethod::Slot}}},
135 {"QGraphicsDropShadowEffect"_L1, {{"setOffset"_L1, QMetaMethod::Slot}}},
136 {"QGraphicsScene"_L1, {{"invalidate"_L1, QMetaMethod::Slot}}},
137 {"QItemDelegate"_L1, {{"closeEditor"_L1, QMetaMethod::Signal}}}
138 */
139 };
140
141 for (auto it = ambiguousList.constBegin(); it != ambiguousList.constEnd(); ++it) {
142 if (extends(className, it->className)) {
143 const qsizetype pos = signature.indexOf(u'(');
144 const QString method = signature.left(pos);
145 const auto methodIterator = it->methodMap.find(method);
146 return methodIterator != it->methodMap.constEnd() && type == methodIterator.value();
147 }
148 }
149 return false;
150}
151
152// Is it ambiguous, resulting in different signals for Python
153// "QAbstractButton::clicked(checked=false)"
155 const QString &signalSignature) const
156{
157 return isAmbiguous(className, signalSignature, QMetaMethod::Signal);
158}
159
161 const QString &signalSignature) const
162{
163 return isAmbiguous(className, signalSignature, QMetaMethod::Slot);
164}
165
167{
168 if (className == "Line"_L1)
169 return u"QFrame"_s;
170
171 return className;
172}
173
175{
176 if (DomCustomWidget *dcw = m_customWidgets.value(name, nullptr))
177 return dcw->elementAddPageMethod();
178 return QString();
179}
180
181// add page methods for simple containers taking only the widget parameter
183{
184 using AddPageMethod = std::pair<QString, QString>;
185
186 static const AddPageMethod addPageMethods[] = {
187 {u"QStackedWidget"_s, u"addWidget"_s},
188 {u"QToolBar"_s, u"addWidget"_s},
189 {u"QDockWidget"_s, u"setWidget"_s},
190 {u"QScrollArea"_s, u"setWidget"_s},
191 {u"QSplitter"_s, u"addWidget"_s},
192 {u"QMdiArea"_s, u"addSubWindow"_s}
193 };
194 for (const auto &m : addPageMethods) {
195 if (extends(name, m.first))
196 return m.second;
197 }
198 return QString();
199}
200
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 realClassName(const QString &className) 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
DomCustomWidget * customWidget(const QString &name) const
QString elementClass() const
Definition ui4.h:664
Definition ui4.h:116
DomCustomWidgets * elementCustomWidgets() const
Definition ui4.h:205
\inmodule QtCore
iterator insert(const Key &key, const T &value)
Definition qmap.h:688
T value(const Key &key, const T &defaultValue=T()) const
Definition qmap.h:357
void clear()
Definition qmap.h:289
MethodType
\value Method The function is a plain member function.
Definition qmetaobject.h:38
const_iterator constBegin() const noexcept
Definition qset.h:139
const_iterator constEnd() const noexcept
Definition qset.h:143
iterator find(const T &value)
Definition qset.h:159
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:192
QSet< QString >::iterator it
QMetaType signature()
Combined button and popup list for selecting options.
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char * method
const GLfloat * m
GLenum type
GLuint name
const GLubyte * c
ptrdiff_t qsizetype
Definition qtypes.h:165
const char className[16]
[1]
Definition qwizard.cpp:100
virtual void acceptCustomWidgets(DomCustomWidgets *customWidgets)