1 | // Copyright (C) 2021 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 "writeincludesbase.h" |
5 | #include "ui4.h" |
6 | #include <uic.h> |
7 | #include <databaseinfo.h> |
8 | |
9 | QT_BEGIN_NAMESPACE |
10 | |
11 | static const ClassInfoEntry qclass_lib_map[] = { |
12 | #define QT_CLASS_LIB(klass, module, header) { #klass, #module, #header }, |
13 | #include "qclass_lib_map.h" |
14 | #undef QT_CLASS_LIB |
15 | }; |
16 | |
17 | ClassInfoEntries classInfoEntries() |
18 | { |
19 | const ClassInfoEntry *classLibEnd = qclass_lib_map + sizeof(qclass_lib_map)/sizeof(ClassInfoEntry); |
20 | return {.m_begin: qclass_lib_map, .m_end: classLibEnd}; |
21 | } |
22 | |
23 | // Base class for implementing a class that determines includes and equivalents |
24 | // in other languages by implementing doAdd(). It makes sure all dependent |
25 | // classes are known. |
26 | WriteIncludesBase::WriteIncludesBase(Uic *uic) : m_uic(uic) |
27 | { |
28 | } |
29 | |
30 | void WriteIncludesBase::acceptUI(DomUI *node) |
31 | { |
32 | m_knownClasses.clear(); |
33 | m_laidOut = false; |
34 | |
35 | if (node->elementIncludes()) |
36 | acceptIncludes(includes: node->elementIncludes()); |
37 | |
38 | // Populate known custom widgets first |
39 | if (node->elementCustomWidgets()) |
40 | TreeWalker::acceptCustomWidgets(customWidgets: node->elementCustomWidgets()); |
41 | |
42 | add(QStringLiteral("QApplication" )); |
43 | add(QStringLiteral("QVariant" )); |
44 | |
45 | if (node->elementButtonGroups()) |
46 | add(QStringLiteral("QButtonGroup" )); |
47 | |
48 | TreeWalker::acceptUI(ui: node); |
49 | } |
50 | |
51 | void WriteIncludesBase::acceptWidget(DomWidget *node) |
52 | { |
53 | add(className: node->attributeClass()); |
54 | TreeWalker::acceptWidget(widget: node); |
55 | } |
56 | |
57 | void WriteIncludesBase::acceptLayout(DomLayout *node) |
58 | { |
59 | add(className: node->attributeClass()); |
60 | m_laidOut = true; |
61 | TreeWalker::acceptLayout(layout: node); |
62 | } |
63 | |
64 | void WriteIncludesBase::acceptSpacer(DomSpacer *node) |
65 | { |
66 | add(QStringLiteral("QSpacerItem" )); |
67 | TreeWalker::acceptSpacer(spacer: node); |
68 | } |
69 | |
70 | void WriteIncludesBase::acceptProperty(DomProperty *node) |
71 | { |
72 | if (node->kind() == DomProperty::Date) |
73 | add(QStringLiteral("QDate" )); |
74 | if (node->kind() == DomProperty::Locale) |
75 | add(QStringLiteral("QLocale" )); |
76 | if (node->kind() == DomProperty::IconSet) |
77 | add(QStringLiteral("QIcon" )); |
78 | TreeWalker::acceptProperty(property: node); |
79 | } |
80 | |
81 | void WriteIncludesBase::add(const QString &className, const DomCustomWidget *dcw) |
82 | { |
83 | if (className.isEmpty() || m_knownClasses.contains(value: className)) |
84 | return; |
85 | |
86 | m_knownClasses.insert(value: className); |
87 | |
88 | const CustomWidgetsInfo *cwi = m_uic->customWidgetsInfo(); |
89 | static const QStringList = { |
90 | QStringLiteral("QTreeView" ), QStringLiteral("QTreeWidget" ), |
91 | QStringLiteral("QTableView" ), QStringLiteral("QTableWidget" ) |
92 | }; |
93 | if (cwi->extendsOneOf(className, baseClassNames: treeViewsWithHeaders)) |
94 | add(QStringLiteral("QHeaderView" )); |
95 | |
96 | if (!m_laidOut && cwi->extends(className, baseClassName: "QToolBox" )) |
97 | add(QStringLiteral("QLayout" )); // spacing property of QToolBox) |
98 | |
99 | if (className == QStringLiteral("Line" )) { // ### hmm, deprecate me! |
100 | add(QStringLiteral("QFrame" )); |
101 | return; |
102 | } |
103 | |
104 | if (cwi->extends(className, baseClassName: "QDialogButtonBox" )) |
105 | add(QStringLiteral("QAbstractButton" )); // for signal "clicked(QAbstractButton*)" |
106 | |
107 | doAdd(className, dcw); |
108 | } |
109 | |
110 | void WriteIncludesBase::acceptCustomWidget(DomCustomWidget *node) |
111 | { |
112 | const QString className = node->elementClass(); |
113 | if (!className.isEmpty()) |
114 | add(className, dcw: node); |
115 | } |
116 | |
117 | void WriteIncludesBase::acceptActionGroup(DomActionGroup *node) |
118 | { |
119 | add(QStringLiteral("QActionGroup" )); |
120 | TreeWalker::acceptActionGroup(actionGroup: node); |
121 | } |
122 | |
123 | void WriteIncludesBase::acceptAction(DomAction *node) |
124 | { |
125 | add(QStringLiteral("QAction" )); |
126 | TreeWalker::acceptAction(action: node); |
127 | } |
128 | |
129 | void WriteIncludesBase::acceptActionRef(DomActionRef *node) |
130 | { |
131 | add(QStringLiteral("QAction" )); |
132 | TreeWalker::acceptActionRef(actionRef: node); |
133 | } |
134 | |
135 | QT_END_NAMESPACE |
136 | |