1/****************************************************************************
2**
3** Copyright (C) 2018 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the tools applications of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29#ifndef LANGUAGE_H
30#define LANGUAGE_H
31
32#include <QtCore/qstring.h>
33#include <QtCore/qstringview.h>
34#include <QtCore/qstring.h>
35
36QT_FORWARD_DECLARE_CLASS(QTextStream)
37
38enum class Language { Cpp, Python };
39
40enum class ConnectionSyntax { StringBased, MemberFunctionPtr };
41
42namespace language {
43
44Language language();
45void setLanguage(Language);
46
47ConnectionSyntax connectionSyntax();
48void setConnectionSyntax(ConnectionSyntax cs);
49
50extern QString derefPointer;
51extern QString nullPtr;
52extern QString operatorNew;
53extern QString qtQualifier;
54extern QString qualifier;
55extern QString self;
56extern QString eol;
57extern QString emptyString;
58
59extern QString cppQualifier;
60extern QString cppTrue;
61extern QString cppFalse;
62
63// Base class for streamable objects with one QStringView parameter
64class StringViewStreamable
65{
66public:
67 StringViewStreamable(QStringView parameter) : m_parameter(parameter) {}
68
69 QStringView parameter() const { return m_parameter; }
70
71private:
72 QStringView m_parameter;
73};
74
75class qtConfig : public StringViewStreamable
76{
77public:
78 qtConfig(QStringView name) : StringViewStreamable(name) {}
79};
80
81QTextStream &operator<<(QTextStream &str, const qtConfig &c);
82
83class openQtConfig : public StringViewStreamable
84{
85public:
86 openQtConfig(QStringView name) : StringViewStreamable(name) {}
87};
88
89QTextStream &operator<<(QTextStream &str, const openQtConfig &c);
90
91class closeQtConfig : public StringViewStreamable
92{
93public:
94 closeQtConfig(QStringView name) : StringViewStreamable(name) {}
95};
96
97QTextStream &operator<<(QTextStream &, const closeQtConfig &c);
98
99QString fixClassName(QString className);
100
101const char *toolbarArea(int v);
102const char *sizePolicy(int v);
103const char *dockWidgetArea(int v);
104const char *paletteColorRole(int v);
105
106enum class Encoding { Utf8, Unicode };
107
108void _formatString(QTextStream &str, const QString &value, const QString &indent,
109 bool qString);
110
111template <bool AsQString>
112class _string
113{
114public:
115 explicit _string(const QString &value, const QString &indent = QString())
116 : m_value(value), m_indent(indent) {}
117
118 void format(QTextStream &str) const
119 { _formatString(str, m_value, m_indent, AsQString); }
120
121private:
122 const QString &m_value;
123 const QString &m_indent;
124};
125
126template <bool AsQString>
127inline QTextStream &operator<<(QTextStream &str, const language::_string<AsQString> &s)
128{
129 s.format(str);
130 return str;
131}
132
133using charliteral = _string<false>;
134using qstring = _string<true>;
135
136class repeat {
137public:
138 explicit repeat(int count, char c) : m_count(count), m_char(c) {}
139
140 friend QTextStream &operator<<(QTextStream &str, const repeat &r);
141
142private:
143 const int m_count;
144 const char m_char;
145};
146
147class startFunctionDefinition1 {
148public:
149 explicit startFunctionDefinition1(const char *name, const QString &parameterType,
150 const QString &parameterName,
151 const QString &indent,
152 const char *returnType = nullptr);
153
154 friend QTextStream &operator<<(QTextStream &str, const startFunctionDefinition1 &f);
155private:
156 const char *m_name;
157 const QString &m_parameterType;
158 const QString &m_parameterName;
159 const QString &m_indent;
160 const char *m_return;
161};
162
163class endFunctionDefinition {
164public:
165 explicit endFunctionDefinition(const char *name);
166
167 friend QTextStream &operator<<(QTextStream &str, const endFunctionDefinition &f);
168private:
169 const char *m_name;
170};
171
172void _formatStackVariable(QTextStream &str, const char *className, QStringView varName, bool withInitParameters);
173
174template <bool withInitParameters>
175class _stackVariable {
176public:
177 explicit _stackVariable(const char *className, QStringView varName) :
178 m_className(className), m_varName(varName) {}
179
180 void format(QTextStream &str) const
181 { _formatStackVariable(str, m_className, m_varName, withInitParameters); }
182
183private:
184 const char *m_className;
185 QStringView m_varName;
186 QStringView m_parameters;
187};
188
189template <bool withInitParameters>
190inline QTextStream &operator<<(QTextStream &str, const _stackVariable<withInitParameters> &s)
191{
192 s.format(str);
193 return str;
194}
195
196using stackVariable = _stackVariable<false>;
197using stackVariableWithInitParameters = _stackVariable<true>;
198
199struct SignalSlot
200{
201 QString name;
202 QString signature;
203 QString className;
204};
205
206void formatConnection(QTextStream &str, const SignalSlot &sender, const SignalSlot &receiver,
207 ConnectionSyntax connectionSyntax);
208
209QString boolValue(bool v);
210
211QString enumValue(const QString &value);
212
213} // namespace language
214
215#endif // LANGUAGE_H
216