Skip to content
This repository was archived by the owner on Mar 4, 2023. It is now read-only.

Commit 84ade94

Browse files
committed
ascii warning clean + tr prepare
1 parent 4d066fb commit 84ade94

File tree

5 files changed

+115
-123
lines changed

5 files changed

+115
-123
lines changed

tests/auto/restclient/tests.pri

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ DISTFILES += \
1414
$$PWD/rest-db-setup.bat \
1515
$$PWD/default-test-db.js \
1616
$$PWD/advanced-test-db.js \
17-
$$PWD/build-test-db.js \
18-
$$PWD/rest-db-setup.sh
17+
$$PWD/build-test-db.js \
18+
$$PWD/rest-db-setup.sh
1919

2020
DEFINES += "TEST_SRC_DIR=\\\"$$PWD\\\""
2121

2222
mac: QMAKE_LFLAGS += '-Wl,-rpath,\'$$OUT_PWD/../../../../lib\''
23+
24+
DEFINES -= QT_ASCII_CAST_WARNINGS

tools/qrestbuilder/classbuilder.cpp

Lines changed: 43 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
#include "classbuilder.h"
22
#include <QJsonArray>
3-
#include <QDebug>
43

54
ClassBuilder::ClassBuilder() :
65
classes(),
76
methods(),
8-
defaultExcept("QObject*")
7+
defaultExcept(QStringLiteral("QObject*"))
98
{}
109

1110
void ClassBuilder::build()
1211
{
13-
if(root["type"].toString() == "api")
12+
if(root[QStringLiteral("type")].toString() == QStringLiteral("api"))
1413
generateApi();
15-
else if(root["type"].toString() == "class")
14+
else if(root[QStringLiteral("type")].toString() == QStringLiteral("class"))
1615
generateClass();
1716
else
18-
throw QStringLiteral("REST_API_CLASSES must be either of type api or class");
17+
throw tr("REST_API_CLASSES must be either of type api or class");
1918
}
2019

2120
QString ClassBuilder::specialPrefix()
@@ -25,19 +24,17 @@ QString ClassBuilder::specialPrefix()
2524

2625
QString ClassBuilder::expr(const QString &expression)
2726
{
28-
if(expression.startsWith('$'))
27+
if(expression.startsWith(QLatin1Char('$')))
2928
return expression.mid(1);
3029
else
31-
return '"' + expression + '"';
30+
return QLatin1Char('"') + expression + QLatin1Char('"');
3231
}
3332

3433
void ClassBuilder::generateClass()
3534
{
36-
qInfo() << "generating class:" << className;
37-
3835
readClasses();
3936
readMethods();
40-
auto parent = root["parent"].toString("QObject");
37+
auto parent = root[QStringLiteral("parent")].toString(QStringLiteral("QObject"));
4138

4239
//write header
4340
writeClassBeginDeclaration(parent);
@@ -51,11 +48,9 @@ void ClassBuilder::generateClass()
5148

5249
void ClassBuilder::generateApi()
5350
{
54-
qInfo() << "generating api:" << className;
55-
5651
readClasses();
5752
readMethods();
58-
auto parent = root["parent"].toString("QObject");
53+
auto parent = root[QStringLiteral("parent")].toString(QStringLiteral("QObject"));
5954

6055
//write header
6156
writeClassBeginDeclaration(parent);
@@ -77,7 +72,7 @@ void ClassBuilder::generateApi()
7772
writeClassMainDefinition(parent);
7873

7974
//write API generation
80-
auto globalName = root["globalName"].toString();
75+
auto globalName = root[QStringLiteral("globalName")].toString();
8176
if(!globalName.isEmpty())
8277
writeGlobalApiGeneration(globalName);
8378
else
@@ -87,10 +82,10 @@ void ClassBuilder::generateApi()
8782
void ClassBuilder::writeClassBeginDeclaration(const QString &parent)
8883
{
8984
auto includes = readIncludes();
90-
includes.append("QtRestClient/restclient.h");
91-
includes.append("QtRestClient/restclass.h");
92-
includes.append("QtCore/qstring.h");
93-
includes.append("QtCore/qstringlist.h");
85+
includes.append(QStringLiteral("QtRestClient/restclient.h"));
86+
includes.append(QStringLiteral("QtRestClient/restclass.h"));
87+
includes.append(QStringLiteral("QtCore/qstring.h"));
88+
includes.append(QStringLiteral("QtCore/qstringlist.h"));
9489

9590
writeIncludes(header, includes);
9691
header << "class " << exportedClassName << " : public " << parent << "\n"
@@ -123,7 +118,7 @@ void ClassBuilder::writeClassBeginDefinition()
123118
<< "#include <QtCore/qtimer.h>\n"
124119
<< "#include <QtCore/qpointer.h>\n"
125120
<< "using namespace QtRestClient;\n\n"
126-
<< "const QString " << className << "::Path(" << expr(root["path"].toString()) << ");\n";
121+
<< "const QString " << className << "::Path(" << expr(root[QStringLiteral("path")].toString()) << ");\n";
127122
generateFactoryDefinition();
128123
}
129124

@@ -155,33 +150,33 @@ void ClassBuilder::writeClassMainDefinition(const QString &parent)
155150

156151
void ClassBuilder::readClasses()
157152
{
158-
auto cls = root["classes"].toObject();
153+
auto cls = root[QStringLiteral("classes")].toObject();
159154
for(auto it = cls.constBegin(); it != cls.constEnd(); it++)
160155
classes.insert(it.key(), it.value().toString());
161156
}
162157

163158
void ClassBuilder::readMethods()
164159
{
165-
defaultExcept = root["except"].toString(defaultExcept);
166-
auto member = root["methods"].toObject();
160+
defaultExcept = root[QStringLiteral("except")].toString(defaultExcept);
161+
auto member = root[QStringLiteral("methods")].toObject();
167162
for(auto it = member.constBegin(); it != member.constEnd(); it++) {
168163
auto obj = it.value().toObject();
169164
MethodInfo info;
170-
info.path = obj["path"].toString(info.path);
171-
info.url = obj["url"].toString(info.url);
165+
info.path = obj[QStringLiteral("path")].toString(info.path);
166+
info.url = obj[QStringLiteral("url")].toString(info.url);
172167
if(!info.path.isEmpty() && !info.url.isEmpty())
173-
throw QStringLiteral("You can only use either path or url, not both!");
174-
info.verb = obj["verb"].toString(info.verb);
175-
foreach(auto value, obj["pathParams"].toArray())
168+
throw tr("You can only use either path or url, not both!");
169+
info.verb = obj[QStringLiteral("verb")].toString(info.verb);
170+
foreach(auto value, obj[QStringLiteral("pathParams")].toArray())
176171
info.pathParams.append(value.toString());
177-
foreach(auto value, obj["parameters"].toArray())
172+
foreach(auto value, obj[QStringLiteral("parameters")].toArray())
178173
info.parameters.append(value.toString());
179-
auto headers = obj["headers"].toObject();
174+
auto headers = obj[QStringLiteral("headers")].toObject();
180175
for(auto jt = headers.constBegin(); jt != headers.constEnd(); jt++)
181176
info.headers.insert(jt.key(), jt.value().toString());
182-
info.body = obj["body"].toString(info.body);
183-
info.returns = obj["returns"].toString(info.returns);
184-
info.except = obj["except"].toString(defaultExcept);
177+
info.body = obj[QStringLiteral("body")].toString(info.body);
178+
info.returns = obj[QStringLiteral("returns")].toString(info.returns);
179+
info.except = obj[QStringLiteral("except")].toString(defaultExcept);
185180

186181
methods.insert(it.key(), info);
187182
}
@@ -224,12 +219,12 @@ void ClassBuilder::writeMethodDeclarations()
224219
header << "\tQtRestClient::GenericRestReply<" << it->returns << ", " << it->except << "> *" << it.key() << "(";
225220
QStringList parameters;
226221
if(!it->body.isEmpty())
227-
parameters.append(it->body + " __body");
222+
parameters.append(it->body + QStringLiteral(" __body"));
228223
foreach(auto path, it->pathParams)
229224
parameters.append(path.write(true));
230225
foreach(auto param, it->parameters)
231226
parameters.append(param.write(true));
232-
header << parameters.join(", ") << ");\n";
227+
header << parameters.join(QStringLiteral(", ")) << ");\n";
233228
}
234229
if(!methods.isEmpty())
235230
header << '\n';
@@ -283,12 +278,12 @@ void ClassBuilder::writeMethodDefinitions()
283278
source << "\nQtRestClient::GenericRestReply<" << it->returns << ", " << it->except << "> *" << className << "::" << it.key() << "(";
284279
QStringList parameters;
285280
if(!it->body.isEmpty())
286-
parameters.append(it->body + " __body");
281+
parameters.append(it->body + QStringLiteral(" __body"));
287282
foreach(auto path, it->pathParams)
288283
parameters.append(path.write(false));
289284
foreach(auto param, it->parameters)
290285
parameters.append(param.write(false));
291-
source << parameters.join(", ") << ")\n"
286+
source << parameters.join(QStringLiteral(", ")) << ")\n"
292287
<< "{\n";
293288

294289
//create parameters
@@ -361,7 +356,7 @@ void ClassBuilder::writeGlobalApiGeneration(const QString &globalName)
361356
<< "\treturn client;\n"
362357
<< "}\n";
363358

364-
if(root["autoCreate"].toBool(true)) {
359+
if(root[QStringLiteral("autoCreate")].toBool(true)) {
365360
source << "\nstatic void __" << className << "_app_construct()\n"
366361
<< "{\n"
367362
<< "\tQTimer::singleShot(0, &" << className << "::factory);\n"
@@ -373,14 +368,14 @@ void ClassBuilder::writeGlobalApiGeneration(const QString &globalName)
373368
void ClassBuilder::writeApiCreation()
374369
{
375370
source << "\t\tclient = new RestClient(QCoreApplication::instance());\n"
376-
<< "\t\tclient->setBaseUrl(QUrl(" << expr(root["baseUrl"].toString()) << "));\n";
377-
auto version = root["apiVersion"].toString();
371+
<< "\t\tclient->setBaseUrl(QUrl(" << expr(root[QStringLiteral("baseUrl")].toString()) << "));\n";
372+
auto version = root[QStringLiteral("apiVersion")].toString();
378373
if(!version.isEmpty())
379374
source << "\t\tclient->setApiVersion(QVersionNumber::fromString(" << expr(version) << "));\n";
380-
auto headers = root["headers"].toObject();
375+
auto headers = root[QStringLiteral("headers")].toObject();
381376
for(auto it = headers.constBegin(); it != headers.constEnd(); it++)
382377
source << "\t\tclient->addGlobalHeader(\"" << it.key() << "\", " << expr(it.value().toString()) << ");\n";
383-
auto parameters = root["parameters"].toObject();
378+
auto parameters = root[QStringLiteral("parameters")].toObject();
384379
for(auto it = parameters.constBegin(); it != parameters.constEnd(); it++)
385380
source << "\t\tclient->addGlobalParameter(\"" << it.key() << "\", " << expr(it.value().toString()) << ");\n";
386381
}
@@ -406,20 +401,20 @@ bool ClassBuilder::writeMethodPath(const MethodInfo &info)
406401

407402
ClassBuilder::MethodInfo::MethodInfo() :
408403
path(),
409-
verb("GET"),
404+
verb(QStringLiteral("GET")),
410405
pathParams(),
411406
parameters(),
412407
headers(),
413408
body(),
414-
returns("QObject*"),
415-
except("QObject*")
409+
returns(QStringLiteral("QObject*")),
410+
except(QStringLiteral("QObject*"))
416411
{}
417412

418413
ClassBuilder::MethodInfo::Parameter::Parameter(const QString &data)
419414
{
420-
auto param = data.split(';');
415+
auto param = data.split(QLatin1Char(';'));
421416
if(param.size() < 2 || param.size() > 3)
422-
throw QStringLiteral("Element in pathParams must be of format \"name;type[;default]>\"");
417+
throw tr("Element in pathParams must be of format \"name;type[;default]>\"");
423418
type = param[1];
424419
name = param[0];
425420
if(param.size() == 3)
@@ -428,8 +423,8 @@ ClassBuilder::MethodInfo::Parameter::Parameter(const QString &data)
428423

429424
QString ClassBuilder::MethodInfo::Parameter::write(bool withDefault) const
430425
{
431-
QString res = type + ' ' + name;
426+
QString res = type + QLatin1Char(' ') + name;
432427
if(withDefault && !defaultValue.isEmpty())
433-
res += " = " + defaultValue;
428+
res += QStringLiteral(" = ") + defaultValue;
434429
return res;
435430
}

tools/qrestbuilder/main.cpp

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,56 +9,56 @@
99
int main(int argc, char *argv[])
1010
{
1111
QCoreApplication a(argc, argv);
12-
QCoreApplication::setApplicationName(TARGET);
13-
QCoreApplication::setApplicationVersion(VERSION);
14-
QCoreApplication::setOrganizationName(COMPANY);
15-
QCoreApplication::setOrganizationDomain(BUNDLE_PREFIX);
12+
QCoreApplication::setApplicationName(QStringLiteral(TARGET));
13+
QCoreApplication::setApplicationVersion(QStringLiteral(VERSION));
14+
QCoreApplication::setOrganizationName(QStringLiteral(COMPANY));
15+
QCoreApplication::setOrganizationDomain(QStringLiteral(BUNDLE_PREFIX));
1616

1717
QCommandLineParser parser;
18-
parser.setApplicationDescription("A tool to create code for a rest API based on an API description");
18+
parser.setApplicationDescription(QCoreApplication::translate("GLOBAL", "A tool to create code for a rest API based on an API description"));
1919
parser.addVersionOption();
2020
parser.addHelpOption();
2121

2222
parser.addOption({
23-
"class",
24-
"Set the builders mode to build an api class"
23+
QStringLiteral("class"),
24+
QCoreApplication::translate("GLOBAL", "Set the builders mode to build an api class")
2525
});
2626
parser.addOption({
27-
"object",
28-
"Set the builders mode to build an api object"
27+
QStringLiteral("object"),
28+
QCoreApplication::translate("GLOBAL", "Set the builders mode to build an api object")
2929
});
3030
parser.addOption({
31-
"in",
32-
"The input JSON <file> containing the API definition",
33-
"file"
31+
QStringLiteral("in"),
32+
QCoreApplication::translate("GLOBAL", "The input JSON <file> containing the API definition"),
33+
QCoreApplication::translate("GLOBAL", "file")
3434
});
3535
parser.addOption({
36-
"header",
37-
"The <name> of the header file to generate",
38-
"name"
36+
QStringLiteral("header"),
37+
QCoreApplication::translate("GLOBAL", "The <name> of the header file to generate"),
38+
QCoreApplication::translate("GLOBAL", "name")
3939
});
4040
parser.addOption({
41-
"impl",
42-
"The <name> of the implementation file to generate",
43-
"name"
41+
QStringLiteral("impl"),
42+
QCoreApplication::translate("GLOBAL", "The <name> of the implementation file to generate"),
43+
QCoreApplication::translate("GLOBAL", "name")
4444
});
4545

4646
parser.process(a);
4747

4848
try {
4949
QScopedPointer<RestBuilder> builder;
50-
if(parser.isSet("class"))
50+
if(parser.isSet(QStringLiteral("class")))
5151
builder.reset(new ClassBuilder());
52-
else if(parser.isSet("object"))
52+
else if(parser.isSet(QStringLiteral("object")))
5353
builder.reset(new ObjectBuilder());
5454
else
55-
throw QStringLiteral("Invalid mode! You must specify either --class or --object");
55+
throw QCoreApplication::translate("GLOBAL", "Invalid mode! You must specify either --class or --object");
5656

57-
builder->build(parser.value("in"),
58-
parser.value("header"),
59-
parser.value("impl"));
57+
builder->build(parser.value(QStringLiteral("in")),
58+
parser.value(QStringLiteral("header")),
59+
parser.value(QStringLiteral("impl")));
6060
return EXIT_SUCCESS;
61-
} catch (QString &str) {
61+
} catch (const QString &str) {
6262
std::cerr << str.toStdString() << std::endl;
6363
return EXIT_FAILURE;
6464
}

0 commit comments

Comments
 (0)