From dc878289c01011c59615746655b4e78d4bc90b91 Mon Sep 17 00:00:00 2001 From: Ahmad Samir Date: Wed, 3 Feb 2021 15:28:38 +0200 Subject: Minor code optimisations - Use a global var for a QString that's used many times - Break up long-all-cap variable names, it makes it harder to read (and I've fixed one typo in one of those ALLCAPS) - Fix some clazy warnings, make global QString objects in unit tests static (so that the compiler doesn't create symbols for them, it doesn't matter in a unit test but KF code acts as a reference sometimes that others copy from, tip from dfaure) - Add TODO note about changing kconfig_compiler to generate C++ code that uses multi-arg QString::arg(QString, QString, QString) instead of QString::arg().arg() - More const; more QString::at() instead of operator[] where appropriate - Use a ternary where it makes the code more readable (and uses less lines :)) NO_CHANGELOG --- autotests/kconfigguitest.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'autotests/kconfigguitest.cpp') diff --git a/autotests/kconfigguitest.cpp b/autotests/kconfigguitest.cpp index 87168a7f..2744d272 100644 --- a/autotests/kconfigguitest.cpp +++ b/autotests/kconfigguitest.cpp @@ -18,9 +18,9 @@ QTEST_MAIN(KConfigTest) // clazy:excludeall=non-pod-global-static -const QColor COLORENTRY1(QLatin1String{"steelblue"}); -const QColor COLORENTRY2(235, 235, 100, 125); -const QColor COLORENTRY3(234, 234, 127); +static const QColor s_color_entry1(QLatin1String{"steelblue"}); +static const QColor s_color_entry2(235, 235, 100, 125); +static const QColor s_color_entry3(234, 234, 127); static QFont fontEntry() { @@ -38,8 +38,8 @@ void KConfigTest::initTestCase() KConfig sc(QStringLiteral("kconfigtest")); KConfigGroup cg(&sc, "ComplexTypes"); - cg.writeEntry("colorEntry1", COLORENTRY1); - cg.writeEntry("colorEntry2", COLORENTRY2); + cg.writeEntry("colorEntry1", s_color_entry1); + cg.writeEntry("colorEntry2", s_color_entry2); cg.writeEntry("colorEntry3", (QList() << 234 << 234 << 127)); cg.writeEntry("colorEntry4", (QList() << 235 << 235 << 100 << 125)); cg.writeEntry("fontEntry", fontEntry()); @@ -78,11 +78,11 @@ void KConfigTest::testComplex() KConfigGroup sc3(&sc2, "ComplexTypes"); QCOMPARE(QVariant(sc3.readEntry("colorEntry1", QColor(Qt::black))).toString(), - QVariant(COLORENTRY1).toString()); - QCOMPARE(sc3.readEntry("colorEntry1", QColor()), COLORENTRY1); - QCOMPARE(sc3.readEntry("colorEntry2", QColor()), COLORENTRY2); - QCOMPARE(sc3.readEntry("colorEntry3", QColor()), COLORENTRY3); - QCOMPARE(sc3.readEntry("colorEntry4", QColor()), COLORENTRY2); + QVariant(s_color_entry1).toString()); + QCOMPARE(sc3.readEntry("colorEntry1", QColor()), s_color_entry1); + QCOMPARE(sc3.readEntry("colorEntry2", QColor()), s_color_entry2); + QCOMPARE(sc3.readEntry("colorEntry3", QColor()), s_color_entry3); + QCOMPARE(sc3.readEntry("colorEntry4", QColor()), s_color_entry2); QCOMPARE(sc3.readEntry("defaultColorTest", QColor("black")), QColor("black")); if (m_fontFromStringBug) { QEXPECT_FAIL("", "QFont fromString bug from Qt 5.8.0", Continue); -- cgit v1.2.1