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 0000000..bfc79dd Binary files /dev/null and b/tests/auto/qml/qmlsettingsgenerator/tst_qmlsettingsgenerator.qmlc differ diff --git a/tools/settingsgenerator/main.cpp b/tools/settingsgenerator/main.cpp index 26a1b2d..37ec030 100644 --- a/tools/settingsgenerator/main.cpp +++ b/tools/settingsgenerator/main.cpp @@ -21,10 +21,15 @@ int main(int argc, char *argv[]) parser.addHelpOption(); parser.addOption({ - {QStringLiteral("t"), QStringLiteral("tr"), QStringLiteral("translate")}, + {QStringLiteral("tr"), QStringLiteral("translate")}, QStringLiteral("Translate the given settings file. The output will be" "a dummy cpp file, writte to --impl.") }); + parser.addOption({ + QStringLiteral("qml"), + QStringLiteral("Generate the QML-bindings for the given settings xml " + "instead of the default cpp bindings.") + }); parser.addOption({ QStringLiteral("in"), QStringLiteral("The input XML 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);