From 830b9ce7cb9c3365f94b37663abbd66c16a71be0 Mon Sep 17 00:00:00 2001 From: Skycoder42 Date: Sat, 21 Jul 2018 22:19:01 +0200 Subject: [PATCH] prepare env/tests for qml bindings --- mkspecs/features/qsettingsgenerator.prf | 15 +++- src/mvvmcore/mvvmcore.pro | 2 +- tests/auto/auto.pro | 3 +- tests/auto/qml/qml.pro | 4 + .../auto/qml/qmlsettingsgenerator/.gitignore | 73 ++++++++++++++++++ .../qmlsettingsgenerator.pro | 19 +++++ .../tst_qmlsettingsgenerator.cpp | 4 + .../tst_qmlsettingsgenerator.qml | 11 +++ .../tst_qmlsettingsgenerator.qmlc | Bin 0 -> 892 bytes tools/settingsgenerator/main.cpp | 12 ++- tools/settingsgenerator/settingsgenerator.cpp | 13 +++- tools/settingsgenerator/settingsgenerator.h | 3 +- 12 files changed, 147 insertions(+), 12 deletions(-) create mode 100644 tests/auto/qml/qml.pro create mode 100644 tests/auto/qml/qmlsettingsgenerator/.gitignore create mode 100644 tests/auto/qml/qmlsettingsgenerator/qmlsettingsgenerator.pro create mode 100644 tests/auto/qml/qmlsettingsgenerator/tst_qmlsettingsgenerator.cpp create mode 100644 tests/auto/qml/qmlsettingsgenerator/tst_qmlsettingsgenerator.qml create mode 100644 tests/auto/qml/qmlsettingsgenerator/tst_qmlsettingsgenerator.qmlc diff --git a/mkspecs/features/qsettingsgenerator.prf b/mkspecs/features/qsettingsgenerator.prf index 22a85e2..2b3344e 100644 --- a/mkspecs/features/qsettingsgenerator.prf +++ b/mkspecs/features/qsettingsgenerator.prf @@ -9,7 +9,7 @@ debug_and_release { QSETTINGSGENERATOR_DIR = $$QSETTINGSGENERATOR_DIR$$SUFFIX { - qsettingsgenerator_c.name = qsettingsgenerator ${QMAKE_FILE_IN}.h + qsettingsgenerator_c.name = qsettingsgenerator ${QMAKE_FILE_BASE}.h qsettingsgenerator_c.input = SETTINGS_DEFINITIONS qsettingsgenerator_c.variable_out = QSETTINGSGENERATOR_HEADERS qsettingsgenerator_c.commands = $$QMAKE_QSETTINGSGENERATOR --in ${QMAKE_FILE_IN} --header ${QMAKE_FILE_OUT} --impl $$QSETTINGSGENERATOR_DIR/${QMAKE_FILE_BASE}$${first(QMAKE_EXT_CPP)} @@ -18,7 +18,16 @@ QSETTINGSGENERATOR_DIR = $$QSETTINGSGENERATOR_DIR$$SUFFIX qsettingsgenerator_c.depends += $$QMAKE_QSETTINGSGENERATOR_EXE QMAKE_EXTRA_COMPILERS += qsettingsgenerator_c - qsettingsgenerator_m.name = qsettingsgenerator moc ${QMAKE_FILE_IN} + qsettingsgenerator_qml.name = qsettingsgenerator qml_${QMAKE_FILE_BASE}.h + qsettingsgenerator_qml.input = QML_SETTINGS_DEFINITIONS + qsettingsgenerator_qml.variable_out = QSETTINGSGENERATOR_HEADERS + qsettingsgenerator_qml.commands = $$QMAKE_QSETTINGSGENERATOR --qml --in ${QMAKE_FILE_IN} --header ${QMAKE_FILE_OUT} --impl $$QSETTINGSGENERATOR_DIR/qml_${QMAKE_FILE_BASE}$${first(QMAKE_EXT_CPP)} + qsettingsgenerator_qml.output = $$QSETTINGSGENERATOR_DIR/qml_${QMAKE_FILE_BASE}$${first(QMAKE_EXT_H)} + qsettingsgenerator_qml.CONFIG += target_predeps + qsettingsgenerator_qml.depends += $$QMAKE_QSETTINGSGENERATOR_EXE + QMAKE_EXTRA_COMPILERS += qsettingsgenerator_qml + + qsettingsgenerator_m.name = qsettingsgenerator ${QMAKE_FILE_BASE}.moc qsettingsgenerator_m.input = QSETTINGSGENERATOR_HEADERS qsettingsgenerator_m.variable_out = GENERATED_SOURCES qsettingsgenerator_m.commands = ${QMAKE_FUNC_mocCmdBase} ${QMAKE_FILE_IN} -o ${QMAKE_FILE_OUT} @@ -28,7 +37,7 @@ QSETTINGSGENERATOR_DIR = $$QSETTINGSGENERATOR_DIR$$SUFFIX qsettingsgenerator_m.dependency_type = TYPE_C QMAKE_EXTRA_COMPILERS += qsettingsgenerator_m - qsettingsgenerator_s.name = qsettingsgenerator src ${QMAKE_FILE_IN}.cpp + qsettingsgenerator_s.name = qsettingsgenerator ${QMAKE_FILE_BASE}.cpp qsettingsgenerator_s.input = QSETTINGSGENERATOR_HEADERS qsettingsgenerator_s.variable_out = GENERATED_SOURCES qsettingsgenerator_s.commands = $$escape_expand(\\n) # force creation of rule diff --git a/src/mvvmcore/mvvmcore.pro b/src/mvvmcore/mvvmcore.pro index 9081a35..121e906 100644 --- a/src/mvvmcore/mvvmcore.pro +++ b/src/mvvmcore/mvvmcore.pro @@ -39,7 +39,7 @@ SOURCES += \ settingsviewmodel.cpp \ isettingsaccessor.cpp \ qsettingsaccessor.cpp \ - settingsentry.cpp + settingsentry.cpp TRANSLATIONS += \ translations/qtmvvmcore_de.ts \ diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index 48b3e6b..4e1bf1a 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -1,3 +1,4 @@ TEMPLATE = subdirs -SUBDIRS += cmake mvvmcore +SUBDIRS += cmake mvvmcore \ + qml diff --git a/tests/auto/qml/qml.pro b/tests/auto/qml/qml.pro new file mode 100644 index 0000000..c5d2eb6 --- /dev/null +++ b/tests/auto/qml/qml.pro @@ -0,0 +1,4 @@ +TEMPLATE = subdirs + +SUBDIRS += \ + qmlsettingsgenerator diff --git a/tests/auto/qml/qmlsettingsgenerator/.gitignore b/tests/auto/qml/qmlsettingsgenerator/.gitignore new file mode 100644 index 0000000..fab7372 --- /dev/null +++ b/tests/auto/qml/qmlsettingsgenerator/.gitignore @@ -0,0 +1,73 @@ +# This file is used to ignore files which are generated +# ---------------------------------------------------------------------------- + +*~ +*.autosave +*.a +*.core +*.moc +*.o +*.obj +*.orig +*.rej +*.so +*.so.* +*_pch.h.cpp +*_resource.rc +*.qm +.#* +*.*# +core +!core/ +tags +.DS_Store +.directory +*.debug +Makefile* +*.prl +*.app +moc_*.cpp +ui_*.h +qrc_*.cpp +Thumbs.db +*.res +*.rc +/.qmake.cache +/.qmake.stash + +# qtcreator generated files +*.pro.user* + +# xemacs temporary files +*.flc + +# Vim temporary files +.*.swp + +# Visual Studio generated files +*.ib_pdb_index +*.idb +*.ilk +*.pdb +*.sln +*.suo +*.vcproj +*vcproj.*.*.user +*.ncb +*.sdf +*.opensdf +*.vcxproj +*vcxproj.* + +# MinGW generated files +*.Debug +*.Release + +# Python byte code +*.pyc + +# Binaries +# -------- +*.dll +*.exe + diff --git a/tests/auto/qml/qmlsettingsgenerator/qmlsettingsgenerator.pro b/tests/auto/qml/qmlsettingsgenerator/qmlsettingsgenerator.pro new file mode 100644 index 0000000..9c5d2d0 --- /dev/null +++ b/tests/auto/qml/qmlsettingsgenerator/qmlsettingsgenerator.pro @@ -0,0 +1,19 @@ +TEMPLATE = app + +QT += testlib mvvmcore qml +CONFIG += qmltestcase console +CONFIG -= app_bundle + +TARGET = tst_qmlsettingsgenerator + +SOURCES += \ + tst_qmlsettingsgenerator.cpp + +QML_SETTINGS_DEFINITIONS += \ + ../../mvvmcore/settingsgenerator/generatortest.xml + +DISTFILES += \ + tst_qmlsettingsgenerator.qml + +importFiles.path = . +DEPLOYMENT += importFiles diff --git a/tests/auto/qml/qmlsettingsgenerator/tst_qmlsettingsgenerator.cpp b/tests/auto/qml/qmlsettingsgenerator/tst_qmlsettingsgenerator.cpp new file mode 100644 index 0000000..c418ae0 --- /dev/null +++ b/tests/auto/qml/qmlsettingsgenerator/tst_qmlsettingsgenerator.cpp @@ -0,0 +1,4 @@ +#include +#include + +QUICK_TEST_MAIN(qmlsettingsgenerator) diff --git a/tests/auto/qml/qmlsettingsgenerator/tst_qmlsettingsgenerator.qml b/tests/auto/qml/qmlsettingsgenerator/tst_qmlsettingsgenerator.qml new file mode 100644 index 0000000..9a14de0 --- /dev/null +++ b/tests/auto/qml/qmlsettingsgenerator/tst_qmlsettingsgenerator.qml @@ -0,0 +1,11 @@ +import QtQuick 2.10 +import QtTest 1.1 + +Item { + id: root + + TestCase { + name: "QmlSettings" + } + +} diff --git a/tests/auto/qml/qmlsettingsgenerator/tst_qmlsettingsgenerator.qmlc b/tests/auto/qml/qmlsettingsgenerator/tst_qmlsettingsgenerator.qmlc new file mode 100644 index 0000000000000000000000000000000000000000..bfc79ddfbbce1211583cb8c918ba6fca327d04aa GIT binary patch literal 892 zcmb7ByG{Z@6ulq_3I(wuhfc!;=SOfYI|EUc{j0!w2k z4Zq+Y_z84csprh@5-W^na`w)BojWso(oa`whHWg0h%XY92kZQ`<`Wsrh^%MLR5oR0 zR#h!yWlS@jQyJXIq)6KXq+ixI@I?@l0Tswv(DCNrO{Ji#KI>vg!tMN-rKH+x}!1W}+ zB)}Q81%7~OmRiiycEJENgOb3G2u;r7cnL%j+)faj>^SxRbJ@ containing the settings definition"), @@ -58,7 +63,10 @@ int main(int argc, char *argv[]) parser.value(QStringLiteral("header")), parser.value(QStringLiteral("impl")) }; - generator.process(parser.value(QStringLiteral("in"))); + if(parser.isSet(QStringLiteral("qml"))) + generator.processQml(parser.value(QStringLiteral("in"))); + else + generator.process(parser.value(QStringLiteral("in"))); return EXIT_SUCCESS; } catch (SettingsGenerator::Exception &e) { qCritical() << e.what(); diff --git a/tools/settingsgenerator/settingsgenerator.cpp b/tools/settingsgenerator/settingsgenerator.cpp index ae73a0c..0d315d5 100644 --- a/tools/settingsgenerator/settingsgenerator.cpp +++ b/tools/settingsgenerator/settingsgenerator.cpp @@ -31,6 +31,11 @@ void SettingsGenerator::process(const QString &inPath) _srcFile.close(); } +void SettingsGenerator::processQml(const QString &inPath) +{ + +} + bool SettingsGenerator::read_type_mapping(QXmlStreamReader &reader, QHash &data, bool hasNext) { TypeMappingGroup grp; @@ -173,7 +178,7 @@ void SettingsGenerator::readEntry(QXmlStreamReader &reader, SettingsConfigBase:: EntryType nEntry; nEntry.key = entryKey; nEntry.contentNodes = std::move(eGrp->contentNodes); - eGrp = replaceNodeByEntry(cGrp, eGrp, std::move(nEntry)); + eGrp = replaceNodeByEntry(cGrp, eGrp, nEntry); Q_ASSERT(eGrp); } else throw XmlException{reader, QStringLiteral("Found duplicated entry with key: %1").arg(entry.key)}; @@ -181,7 +186,7 @@ void SettingsGenerator::readEntry(QXmlStreamReader &reader, SettingsConfigBase:: auto nEntry = static_cast(eGrp); nEntry->type = std::move(entry.type); nEntry->defaultValue = std::move(entry.defaultValue); - nEntry->tr = std::move(entry.trdefault); + nEntry->tr = entry.trdefault; } SettingsGeneratorBase::NodeContentGroup *SettingsGenerator::findContentGroup(SettingsGeneratorBase::NodeContentGroup *cGrp, const QString &key, bool *isEntry) @@ -214,7 +219,7 @@ SettingsGeneratorBase::NodeContentGroup *SettingsGenerator::findContentGroup(Set return nullptr; } -SettingsGeneratorBase::NodeContentGroup *SettingsGenerator::replaceNodeByEntry(SettingsGeneratorBase::NodeContentGroup *cGrp, NodeContentGroup *node, SettingsGeneratorBase::EntryType &&entry) +SettingsGeneratorBase::NodeContentGroup *SettingsGenerator::replaceNodeByEntry(SettingsGeneratorBase::NodeContentGroup *cGrp, NodeContentGroup *node, SettingsGeneratorBase::EntryType &entry) { for(auto &cNode : cGrp->contentNodes) { if(nonstd::holds_alternative(cNode)) { @@ -223,7 +228,7 @@ SettingsGeneratorBase::NodeContentGroup *SettingsGenerator::replaceNodeByEntry(S return &(nonstd::get(cNode)); } } else if(nonstd::holds_alternative(cNode)) { - auto res = replaceNodeByEntry(&(nonstd::get(cNode)), node, std::move(entry)); + auto res = replaceNodeByEntry(&(nonstd::get(cNode)), node, entry); if(res) return res; } diff --git a/tools/settingsgenerator/settingsgenerator.h b/tools/settingsgenerator/settingsgenerator.h index 147072d..dcd0fcc 100644 --- a/tools/settingsgenerator/settingsgenerator.h +++ b/tools/settingsgenerator/settingsgenerator.h @@ -14,6 +14,7 @@ public: const QString &srcPath); void process(const QString &inPath); + void processQml(const QString &inPath); protected: bool read_type_mapping(QXmlStreamReader &reader, QHash &data, bool hasNext) override; @@ -33,7 +34,7 @@ private: void readEntry(QXmlStreamReader &reader, SettingsConfigBase::EntryType &entry, NodeContentGroup &targetRootNode); NodeContentGroup *findContentGroup(NodeContentGroup *cGrp, const QString &key, bool *isEntry = nullptr); - NodeContentGroup *replaceNodeByEntry(NodeContentGroup *cGrp, NodeContentGroup *node, EntryType &&entry); + NodeContentGroup *replaceNodeByEntry(NodeContentGroup *cGrp, NodeContentGroup *node, EntryType &entry); void fixTrContext(NodeContentGroup &group, const QString &context);