1// Copyright (C) 2018 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
4#ifndef LANGUAGE_H
5#define LANGUAGE_H
6
7#include <QtCore/qstring.h>
8#include <QtCore/qstringview.h>
9#include <QtCore/qstring.h>
10
11QT_FORWARD_DECLARE_CLASS(QTextStream)
12
13enum class Language { Cpp, Python };
14
15enum class ConnectionSyntax { StringBased, MemberFunctionPtr };
16
17namespace language {
18
19Language language();
20void setLanguage(Language);
21
22ConnectionSyntax connectionSyntax();
23void setConnectionSyntax(ConnectionSyntax cs);
24
25extern QString derefPointer;
26extern char listStart;
27extern char listEnd;
28extern QString nullPtr;
29extern QString operatorNew;
30extern QString qtQualifier;
31extern QString qualifier;
32extern QString self;
33extern QString eol;
34extern QString emptyString;
35
36extern QString cppQualifier;
37extern QString cppTrue;
38extern QString cppFalse;
39
40// Base class for streamable objects with one QStringView parameter
41class StringViewStreamable
42{
43public:
44 StringViewStreamable(QStringView parameter) : m_parameter(parameter) {}
45
46 QStringView parameter() const { return m_parameter; }
47
48private:
49 QStringView m_parameter;
50};
51
52class qtConfig : public StringViewStreamable
53{
54public:
55 qtConfig(QStringView name) : StringViewStreamable(name) {}
56};
57
58QTextStream &operator<<(QTextStream &str, const qtConfig &c);
59
60class openQtConfig : public StringViewStreamable
61{
62public:
63 openQtConfig(QStringView name) : StringViewStreamable(name) {}
64};
65
66QTextStream &operator<<(QTextStream &str, const openQtConfig &c);
67
68class closeQtConfig : public StringViewStreamable
69{
70public:
71 closeQtConfig(QStringView name) : StringViewStreamable(name) {}
72};
73
74QTextStream &operator<<(QTextStream &, const closeQtConfig &c);
75
76QString fixClassName(QString className);
77
78const char *toolbarArea(int v);
79const char *sizePolicy(int v);
80const char *dockWidgetArea(int v);
81const char *paletteColorRole(int v);
82
83enum class Encoding { Utf8, Unicode };
84
85void _formatString(QTextStream &str, const QString &value, const QString &indent,
86 bool qString);
87
88template <bool AsQString>
89class _string
90{
91public:
92 explicit _string(const QString &value, const QString &indent = QString())
93 : m_value(value), m_indent(indent) {}
94
95 void format(QTextStream &str) const
96 { _formatString(str, value: m_value, indent: m_indent, qString: AsQString); }
97
98private:
99 const QString &m_value;
100 const QString &m_indent;
101};
102
103template <bool AsQString>
104inline QTextStream &operator<<(QTextStream &str, const language::_string<AsQString> &s)
105{
106 s.format(str);
107 return str;
108}
109
110using charliteral = _string<false>;
111using qstring = _string<true>;
112
113class repeat {
114public:
115 explicit repeat(int count, char c) : m_count(count), m_char(c) {}
116
117 friend QTextStream &operator<<(QTextStream &str, const repeat &r);
118
119private:
120 const int m_count;
121 const char m_char;
122};
123
124class startFunctionDefinition1 {
125public:
126 explicit startFunctionDefinition1(const char *name, const QString &parameterType,
127 const QString &parameterName,
128 const QString &indent,
129 const char *returnType = nullptr);
130
131 friend QTextStream &operator<<(QTextStream &str, const startFunctionDefinition1 &f);
132private:
133 const char *m_name;
134 const QString &m_parameterType;
135 const QString &m_parameterName;
136 const QString &m_indent;
137 const char *m_return;
138};
139
140class endFunctionDefinition {
141public:
142 explicit endFunctionDefinition(const char *name);
143
144 friend QTextStream &operator<<(QTextStream &str, const endFunctionDefinition &f);
145private:
146 const char *m_name;
147};
148
149void _formatStackVariable(QTextStream &str, const char *className, QStringView varName, bool withInitParameters);
150
151template <bool withInitParameters>
152class _stackVariable {
153public:
154 explicit _stackVariable(const char *className, QStringView varName) :
155 m_className(className), m_varName(varName) {}
156
157 void format(QTextStream &str) const
158 { _formatStackVariable(str, className: m_className, varName: m_varName, withInitParameters); }
159
160private:
161 const char *m_className;
162 QStringView m_varName;
163 QStringView m_parameters;
164};
165
166template <bool withInitParameters>
167inline QTextStream &operator<<(QTextStream &str, const _stackVariable<withInitParameters> &s)
168{
169 s.format(str);
170 return str;
171}
172
173using stackVariable = _stackVariable<false>;
174using stackVariableWithInitParameters = _stackVariable<true>;
175
176enum class SignalSlotOption
177{
178 Ambiguous = 0x1
179};
180
181Q_DECLARE_FLAGS(SignalSlotOptions, SignalSlotOption)
182
183struct SignalSlot
184{
185 QString name;
186 QString signature;
187 QString className;
188 SignalSlotOptions options;
189};
190
191void formatConnection(QTextStream &str, const SignalSlot &sender, const SignalSlot &receiver,
192 ConnectionSyntax connectionSyntax);
193
194QString boolValue(bool v);
195
196QString enumValue(const QString &value);
197
198} // namespace language
199
200#endif // LANGUAGE_H
201

source code of qtbase/src/tools/uic/shared/language.h