Skip to content

Commit

Permalink
Use C++11-style QStringList local-initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
steveire committed Jul 20, 2019
1 parent beb89e8 commit 73bd221
Show file tree
Hide file tree
Showing 18 changed files with 84 additions and 93 deletions.
4 changes: 2 additions & 2 deletions templates/defaulttags/for.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ Node *ForNodeFactory::getNode(const QString &tagContent, Parser *p) const

auto n = new ForNode(vars, fe, reversed, p);

auto loopNodes = p->parse(n, QStringList() << QStringLiteral("empty")
<< QStringLiteral("endfor"));
auto loopNodes
= p->parse(n, {QStringLiteral("empty"), QStringLiteral("endfor")});
n->setLoopList(loopNodes);

NodeList emptyNodes;
Expand Down
10 changes: 4 additions & 6 deletions templates/defaulttags/if.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ Node *IfNodeFactory::getNode(const QString &tagContent, Parser *p) const

IfParser ip(p, expr);
auto cond = ip.parse();
auto nodelist = p->parse(n, QStringList() << QStringLiteral("elif")
<< QStringLiteral("else")
<< QStringLiteral("endif"));
auto nodelist = p->parse(n, {QStringLiteral("elif"), QStringLiteral("else"),
QStringLiteral("endif")});
nodelistConditions.push_back(qMakePair(cond, nodelist));

auto token = p->takeNextToken();
Expand All @@ -48,9 +47,8 @@ Node *IfNodeFactory::getNode(const QString &tagContent, Parser *p) const

IfParser ep(p, expr);
cond = ep.parse();
nodelist = p->parse(n, QStringList() << QStringLiteral("elif")
<< QStringLiteral("else")
<< QStringLiteral("endif"));
nodelist = p->parse(n, {QStringLiteral("elif"), QStringLiteral("else"),
QStringLiteral("endif")});
nodelistConditions.push_back(qMakePair(cond, nodelist));

token = p->takeNextToken();
Expand Down
4 changes: 2 additions & 2 deletions templates/defaulttags/ifchanged.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ Node *IfChangedNodeFactory::getNode(const QString &tagContent, Parser *p) const
expr.takeAt(0);
auto n = new IfChangedNode(getFilterExpressionList(expr, p), p);

auto trueList = p->parse(n, QStringList() << QStringLiteral("else")
<< QStringLiteral("endifchanged"));
auto trueList
= p->parse(n, {QStringLiteral("else"), QStringLiteral("endifchanged")});
n->setTrueList(trueList);
NodeList falseList;

Expand Down
3 changes: 1 addition & 2 deletions templates/defaulttags/ifequal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ Node *IfEqualNodeFactory::do_getNode(const QString &tagContent, Parser *p,
auto n = new IfEqualNode(val1, val2, negate, p);

const QString endTag(QStringLiteral("end") + expr.first());
auto trueList
= p->parse(n, QStringList() << QStringLiteral("else") << endTag);
auto trueList = p->parse(n, {QStringLiteral("else"), endTag});
n->setTrueList(trueList);
NodeList falseList;
if (p->takeNextToken().content == QStringLiteral("else")) {
Expand Down
2 changes: 1 addition & 1 deletion templates/lib/cachingloaderdecorator.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class CachingLoaderDecoratorPrivate;
* @code
* Grantlee::FileSystemTemplateLoader::Ptr loader( new
* Grantlee::FileSystemTemplateLoader() );
* loader->setTemplateDirs( QStringList() << "/path/one" << "/path/two" );
* loader->setTemplateDirs({"/path/one", "/path/two"});
*
* Grantlee::CachingLoaderDecorator::Ptr cache( new
* Grantlee::CachingLoaderDecorator( loader ) );
Expand Down
2 changes: 1 addition & 1 deletion templates/lib/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class EnginePrivate;
Engine *engine = new Engine();
auto loader = QSharedPointer<FileSystemTemplateLoader>::create();
loader->setTemplateDirs( QStringList() << "/usr/share/myapp/templates" );
loader->setTemplateDirs( {"/usr/share/myapp/templates"} );
engine->addTemplateLoader( loader );
engine->addPluginPath( "/usr/lib/myapp" );
Expand Down
2 changes: 1 addition & 1 deletion templates/lib/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ QSharedPointer<Filter> Parser::getFilter(const QString &name) const
NodeList Parser::parse(Node *parent, const QString &stopAt)
{
Q_D(Parser);
return d->parse(parent, QStringList() << stopAt);
return d->parse(parent, {stopAt});
}

NodeList Parser::parse(TemplateImpl *parent, const QStringList &stopAt)
Expand Down
18 changes: 12 additions & 6 deletions templates/lib/templateloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,10 @@ class FileSystemTemplateLoaderPrivate;
are checked in order, and the first match hit is parsed and returned.
@code
loader->setTemplateDirs(QStringList() << "/home/user/app/templates" <<
"/usr/local/share/app/templates" );
loader->setTemplateDirs({
"/home/user/app/templates",
"/usr/local/share/app/templates"
});
engine->setTemplateLoader( loader );
// This will try /home/user/app/templates/mytemplate.html
Expand All @@ -99,8 +101,10 @@ class FileSystemTemplateLoaderPrivate;
appended to search paths before the template name.
@code
loader->setTemplateDirs(QStringList() << "/home/user/app/templates" <<
"/usr/local/share/app/templates" );
loader->setTemplateDirs({
"/home/user/app/templates" <<
"/usr/local/share/app/templates"
});
loader->setTheme( "simple_theme" );
engine->setTemplateLoader( loader );
Expand All @@ -113,8 +117,10 @@ class FileSystemTemplateLoaderPrivate;
queried for templates.
@code
loader->setTemplateDirs(QStringList() << "/home/user/app/templates" <<
"/usr/local/share/app/templates" );
loader->setTemplateDirs({
"/home/user/app/templates",
"/usr/local/share/app/templates"
});
loader->setTheme( "simple_theme" );
engine->setTemplateLoader( loader );
Expand Down
5 changes: 2 additions & 3 deletions templates/loadertags/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,8 @@ Node *BlockNodeFactory::getNode(const QString &tagContent, Parser *p) const
const auto list = p->parse(n, QStringLiteral("endblock"));

auto endBlock = p->takeNextToken();
const auto acceptableBlocks = QStringList()
<< QStringLiteral("endblock")
<< QStringLiteral("endblock ") + blockName;
const QStringList acceptableBlocks{QStringLiteral("endblock"),
QStringLiteral("endblock ") + blockName};
if (!acceptableBlocks.contains(endBlock.content)) {
p->invalidBlockTag(endBlock, QStringLiteral("endblock"), acceptableBlocks);
}
Expand Down
34 changes: 15 additions & 19 deletions templates/tests/testbuiltins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ void TestBuiltinSyntax::testRenderAfterError()
{

Engine engine;
engine.setPluginPaths(QStringList() << QStringLiteral(GRANTLEE_PLUGIN_PATH));
engine.setPluginPaths({QStringLiteral(GRANTLEE_PLUGIN_PATH)});

QSharedPointer<InMemoryTemplateLoader> loader(new InMemoryTemplateLoader);
loader->setTemplate(QStringLiteral("template1"),
Expand Down Expand Up @@ -302,7 +302,7 @@ void TestBuiltinSyntax::initTestCase()
Engine *TestBuiltinSyntax::getEngine()
{
auto engine = new Engine(this);
engine->setPluginPaths(QStringList() << QStringLiteral(GRANTLEE_PLUGIN_PATH));
engine->setPluginPaths({QStringLiteral(GRANTLEE_PLUGIN_PATH)});
return engine;
}

Expand Down Expand Up @@ -1164,7 +1164,7 @@ void TestBuiltinSyntax::testTemplatePathSafety()

auto loader = new FileSystemTemplateLoader();

loader->setTemplateDirs(QStringList() << QStringLiteral("."));
loader->setTemplateDirs({QStringLiteral(".")});

QFile f(inputPath);
auto opened = f.open(QFile::WriteOnly | QFile::Text);
Expand Down Expand Up @@ -1201,7 +1201,7 @@ void TestBuiltinSyntax::testMediaPathSafety()

auto loader = new FileSystemTemplateLoader();

loader->setTemplateDirs(QStringList() << QStringLiteral("."));
loader->setTemplateDirs({QStringLiteral(".")});

QFile f(inputPath);
auto opened = f.open(QFile::WriteOnly | QFile::Text);
Expand Down Expand Up @@ -1267,29 +1267,25 @@ void TestBuiltinSyntax::testTypeAccessorsUnordered_data()

dict.insert(QStringLiteral("hash"), itemsHash);

QTest::newRow("type-accessors-hash-unordered01") << QStringLiteral(
"{% for key,value in hash.items %}{{ key }}:{{ value }};{% endfor %}")
<< dict
<< (QStringList()
<< QStringLiteral(
"one:1;")
<< QStringLiteral(
"two:2;")
<< QStringLiteral(
"three:3;"))
<< NoError;
QTest::newRow("type-accessors-hash-unordered01")
<< QStringLiteral("{% for key,value in hash.items %}{{ key }}:{{ value "
"}};{% endfor %}")
<< dict
<< QStringList{QStringLiteral("one:1;"), QStringLiteral("two:2;"),
QStringLiteral("three:3;")}
<< NoError;
QTest::newRow("type-accessors-hash-unordered02")
<< QStringLiteral("{% for key in hash.keys %}{{ key }};{% endfor %}")
<< dict
<< (QStringList() << QStringLiteral("one;") << QStringLiteral("two;")
<< QStringLiteral("three;"))
<< QStringList{QStringLiteral("one;"), QStringLiteral("two;"),
QStringLiteral("three;")}
<< NoError;
QTest::newRow("type-accessors-hash-unordered03")
<< QStringLiteral(
"{% for value in hash.values %}{{ value }};{% endfor %}")
<< dict
<< (QStringList() << QStringLiteral("1;") << QStringLiteral("2;")
<< QStringLiteral("3;"))
<< QStringList{QStringLiteral("1;"), QStringLiteral("2;"),
QStringLiteral("3;")}
<< NoError;
}

Expand Down
2 changes: 1 addition & 1 deletion templates/tests/testcachingloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private Q_SLOTS:
void TestCachingLoader::testRenderAfterError()
{
Engine engine;
engine.setPluginPaths(QStringList() << QStringLiteral(GRANTLEE_PLUGIN_PATH));
engine.setPluginPaths({QStringLiteral(GRANTLEE_PLUGIN_PATH)});

QSharedPointer<InMemoryTemplateLoader> loader(new InMemoryTemplateLoader);
loader->setTemplate(QStringLiteral("template1"),
Expand Down
6 changes: 2 additions & 4 deletions templates/tests/testdefaulttags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,7 @@ private Q_SLOTS:
void TestDefaultTags::initTestCase()
{
m_engine = new Engine(this);
m_engine->setPluginPaths(QStringList()
<< QStringLiteral(GRANTLEE_PLUGIN_PATH));
m_engine->setPluginPaths({QStringLiteral(GRANTLEE_PLUGIN_PATH)});

auto loader1 = QSharedPointer<FakeTemplateLoader>(new FakeTemplateLoader());

Expand Down Expand Up @@ -1108,8 +1107,7 @@ void TestDefaultTags::testForTag_data()
QTest::newRow("for-tag03") << QStringLiteral(
"{% for val in values %}({{ val }} sdfsdf,){% endfor %}")
<< dict << QString() << NoError;
QStringList emails;
emails << QStringLiteral("one") << QStringLiteral("two");
QStringList emails{QStringLiteral("one"), QStringLiteral("two")};
QVariantHash obj;
obj.insert(QStringLiteral("emails"), emails);
dict.insert(QStringLiteral("contact"), obj);
Expand Down
22 changes: 11 additions & 11 deletions templates/tests/testfilters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ void TestFilters::initTestCase()

auto appDirPath
= QFileInfo(QCoreApplication::applicationDirPath()).absoluteDir().path();
m_engine->setPluginPaths(
QStringList() << QStringLiteral(GRANTLEE_PLUGIN_PATH)
<< appDirPath + QStringLiteral("/tests/") // For testtags.qs
);
m_engine->setPluginPaths({
QStringLiteral(GRANTLEE_PLUGIN_PATH),
appDirPath + QStringLiteral("/tests/") // For testtags.qs
});
}

void TestFilters::cleanupTestCase() { delete m_engine; }
Expand Down Expand Up @@ -1295,9 +1295,9 @@ void TestFilters::testListFilters_data()
dict.clear();

QVariantList mapList;
const auto cities = QStringList()
<< QStringLiteral("London") << QStringLiteral("Berlin")
<< QStringLiteral("Paris") << QStringLiteral("Dublin");
const auto cities
= QStringList{QStringLiteral("London"), QStringLiteral("Berlin"),
QStringLiteral("Paris"), QStringLiteral("Dublin")};
Q_FOREACH (const QString &city, cities) {
QVariantHash map;
map.insert(QStringLiteral("city"), city);
Expand Down Expand Up @@ -1329,12 +1329,12 @@ void TestFilters::testListFilters_data()
QVariantList listList;

const auto countries
= QStringList() << QStringLiteral("England") << QStringLiteral("Germany")
<< QStringLiteral("France") << QStringLiteral("Ireland");
= QStringList{QStringLiteral("England"), QStringLiteral("Germany"),
QStringLiteral("France"), QStringLiteral("Ireland")};

const auto languages
= QStringList() << QStringLiteral("English") << QStringLiteral("German")
<< QStringLiteral("French") << QStringLiteral("Irish");
= QStringList{QStringLiteral("English"), QStringLiteral("German"),
QStringLiteral("French"), QStringLiteral("Irish")};

for (auto i = 0; i < cities.size(); ++i) {
listList << QVariant(QVariantList()
Expand Down
12 changes: 5 additions & 7 deletions templates/tests/testgenericcontainers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,16 +190,14 @@ template <> QString getAssociativeTemplate<QObject *>()

template <typename T> QStringList getResults()
{
return QStringList() << QStringLiteral("3;3;") << QStringLiteral("9,")
<< QStringLiteral("7,") << QStringLiteral("5,");
return {QStringLiteral("3;3;"), QStringLiteral("9,"), QStringLiteral("7,"),
QStringLiteral("5,")};
}

template <> QStringList getResults<QDateTime>()
{
return QStringList() << QStringLiteral("3;3;")
<< QStringLiteral("Jan. 1, 1970,")
<< QStringLiteral("Jan. 2, 1970,")
<< QStringLiteral("Jan. 3, 1970,");
return {QStringLiteral("3;3;"), QStringLiteral("Jan. 1, 1970,"),
QStringLiteral("Jan. 2, 1970,"), QStringLiteral("Jan. 3, 1970,")};
}

template <typename Container, typename T = typename Container::value_type>
Expand Down Expand Up @@ -251,7 +249,7 @@ void testContainer(const QString &stringTemplate,
{
Grantlee::Engine engine;

engine.setPluginPaths(QStringList() << QStringLiteral(GRANTLEE_PLUGIN_PATH));
engine.setPluginPaths({QStringLiteral(GRANTLEE_PLUGIN_PATH)});

Grantlee::Context c;
c.insert(QStringLiteral("container"), containerVariant);
Expand Down
Loading

0 comments on commit 73bd221

Please sign in to comment.