Browse Source

prepare env/tests for qml bindings

pull/2/head
Skycoder42 6 years ago
parent
commit
830b9ce7cb
No known key found for this signature in database GPG Key ID: 8E01AD9EF0578D2B
  1. 15
      mkspecs/features/qsettingsgenerator.prf
  2. 2
      src/mvvmcore/mvvmcore.pro
  3. 3
      tests/auto/auto.pro
  4. 4
      tests/auto/qml/qml.pro
  5. 73
      tests/auto/qml/qmlsettingsgenerator/.gitignore
  6. 19
      tests/auto/qml/qmlsettingsgenerator/qmlsettingsgenerator.pro
  7. 4
      tests/auto/qml/qmlsettingsgenerator/tst_qmlsettingsgenerator.cpp
  8. 11
      tests/auto/qml/qmlsettingsgenerator/tst_qmlsettingsgenerator.qml
  9. BIN
      tests/auto/qml/qmlsettingsgenerator/tst_qmlsettingsgenerator.qmlc
  10. 12
      tools/settingsgenerator/main.cpp
  11. 13
      tools/settingsgenerator/settingsgenerator.cpp
  12. 3
      tools/settingsgenerator/settingsgenerator.h

15
mkspecs/features/qsettingsgenerator.prf

@ -9,7 +9,7 @@ debug_and_release {
QSETTINGSGENERATOR_DIR = $$QSETTINGSGENERATOR_DIR$$SUFFIX 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.input = SETTINGS_DEFINITIONS
qsettingsgenerator_c.variable_out = QSETTINGSGENERATOR_HEADERS 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)} 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 qsettingsgenerator_c.depends += $$QMAKE_QSETTINGSGENERATOR_EXE
QMAKE_EXTRA_COMPILERS += qsettingsgenerator_c 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.input = QSETTINGSGENERATOR_HEADERS
qsettingsgenerator_m.variable_out = GENERATED_SOURCES qsettingsgenerator_m.variable_out = GENERATED_SOURCES
qsettingsgenerator_m.commands = ${QMAKE_FUNC_mocCmdBase} ${QMAKE_FILE_IN} -o ${QMAKE_FILE_OUT} 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 qsettingsgenerator_m.dependency_type = TYPE_C
QMAKE_EXTRA_COMPILERS += qsettingsgenerator_m 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.input = QSETTINGSGENERATOR_HEADERS
qsettingsgenerator_s.variable_out = GENERATED_SOURCES qsettingsgenerator_s.variable_out = GENERATED_SOURCES
qsettingsgenerator_s.commands = $$escape_expand(\\n) # force creation of rule qsettingsgenerator_s.commands = $$escape_expand(\\n) # force creation of rule

2
src/mvvmcore/mvvmcore.pro

@ -39,7 +39,7 @@ SOURCES += \
settingsviewmodel.cpp \ settingsviewmodel.cpp \
isettingsaccessor.cpp \ isettingsaccessor.cpp \
qsettingsaccessor.cpp \ qsettingsaccessor.cpp \
settingsentry.cpp settingsentry.cpp
TRANSLATIONS += \ TRANSLATIONS += \
translations/qtmvvmcore_de.ts \ translations/qtmvvmcore_de.ts \

3
tests/auto/auto.pro

@ -1,3 +1,4 @@
TEMPLATE = subdirs TEMPLATE = subdirs
SUBDIRS += cmake mvvmcore SUBDIRS += cmake mvvmcore \
qml

4
tests/auto/qml/qml.pro

@ -0,0 +1,4 @@
TEMPLATE = subdirs
SUBDIRS += \
qmlsettingsgenerator

73
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

19
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

4
tests/auto/qml/qmlsettingsgenerator/tst_qmlsettingsgenerator.cpp

@ -0,0 +1,4 @@
#include <QtCore>
#include <QtQuickTest/quicktest.h>
QUICK_TEST_MAIN(qmlsettingsgenerator)

11
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"
}
}

BIN
tests/auto/qml/qmlsettingsgenerator/tst_qmlsettingsgenerator.qmlc

Binary file not shown.

12
tools/settingsgenerator/main.cpp

@ -21,10 +21,15 @@ int main(int argc, char *argv[])
parser.addHelpOption(); parser.addHelpOption();
parser.addOption({ parser.addOption({
{QStringLiteral("t"), QStringLiteral("tr"), QStringLiteral("translate")}, {QStringLiteral("tr"), QStringLiteral("translate")},
QStringLiteral("Translate the given settings file. The output will be" QStringLiteral("Translate the given settings file. The output will be"
"a dummy cpp file, writte to --impl.") "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({ parser.addOption({
QStringLiteral("in"), QStringLiteral("in"),
QStringLiteral("The input XML <file> containing the settings definition"), QStringLiteral("The input XML <file> containing the settings definition"),
@ -58,7 +63,10 @@ int main(int argc, char *argv[])
parser.value(QStringLiteral("header")), parser.value(QStringLiteral("header")),
parser.value(QStringLiteral("impl")) 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; return EXIT_SUCCESS;
} catch (SettingsGenerator::Exception &e) { } catch (SettingsGenerator::Exception &e) {
qCritical() << e.what(); qCritical() << e.what();

13
tools/settingsgenerator/settingsgenerator.cpp

@ -31,6 +31,11 @@ void SettingsGenerator::process(const QString &inPath)
_srcFile.close(); _srcFile.close();
} }
void SettingsGenerator::processQml(const QString &inPath)
{
}
bool SettingsGenerator::read_type_mapping(QXmlStreamReader &reader, QHash<QString, QString> &data, bool hasNext) bool SettingsGenerator::read_type_mapping(QXmlStreamReader &reader, QHash<QString, QString> &data, bool hasNext)
{ {
TypeMappingGroup grp; TypeMappingGroup grp;
@ -173,7 +178,7 @@ void SettingsGenerator::readEntry(QXmlStreamReader &reader, SettingsConfigBase::
EntryType nEntry; EntryType nEntry;
nEntry.key = entryKey; nEntry.key = entryKey;
nEntry.contentNodes = std::move(eGrp->contentNodes); nEntry.contentNodes = std::move(eGrp->contentNodes);
eGrp = replaceNodeByEntry(cGrp, eGrp, std::move(nEntry)); eGrp = replaceNodeByEntry(cGrp, eGrp, nEntry);
Q_ASSERT(eGrp); Q_ASSERT(eGrp);
} else } else
throw XmlException{reader, QStringLiteral("Found duplicated entry with key: %1").arg(entry.key)}; 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<EntryType*>(eGrp); auto nEntry = static_cast<EntryType*>(eGrp);
nEntry->type = std::move(entry.type); nEntry->type = std::move(entry.type);
nEntry->defaultValue = std::move(entry.defaultValue); 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) SettingsGeneratorBase::NodeContentGroup *SettingsGenerator::findContentGroup(SettingsGeneratorBase::NodeContentGroup *cGrp, const QString &key, bool *isEntry)
@ -214,7 +219,7 @@ SettingsGeneratorBase::NodeContentGroup *SettingsGenerator::findContentGroup(Set
return nullptr; 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) { for(auto &cNode : cGrp->contentNodes) {
if(nonstd::holds_alternative<NodeType>(cNode)) { if(nonstd::holds_alternative<NodeType>(cNode)) {
@ -223,7 +228,7 @@ SettingsGeneratorBase::NodeContentGroup *SettingsGenerator::replaceNodeByEntry(S
return &(nonstd::get<EntryType>(cNode)); return &(nonstd::get<EntryType>(cNode));
} }
} else if(nonstd::holds_alternative<NodeContentGroup>(cNode)) { } else if(nonstd::holds_alternative<NodeContentGroup>(cNode)) {
auto res = replaceNodeByEntry(&(nonstd::get<NodeContentGroup>(cNode)), node, std::move(entry)); auto res = replaceNodeByEntry(&(nonstd::get<NodeContentGroup>(cNode)), node, entry);
if(res) if(res)
return res; return res;
} }

3
tools/settingsgenerator/settingsgenerator.h

@ -14,6 +14,7 @@ public:
const QString &srcPath); const QString &srcPath);
void process(const QString &inPath); void process(const QString &inPath);
void processQml(const QString &inPath);
protected: protected:
bool read_type_mapping(QXmlStreamReader &reader, QHash<QString, QString> &data, bool hasNext) override; bool read_type_mapping(QXmlStreamReader &reader, QHash<QString, QString> &data, bool hasNext) override;
@ -33,7 +34,7 @@ private:
void readEntry(QXmlStreamReader &reader, SettingsConfigBase::EntryType &entry, NodeContentGroup &targetRootNode); void readEntry(QXmlStreamReader &reader, SettingsConfigBase::EntryType &entry, NodeContentGroup &targetRootNode);
NodeContentGroup *findContentGroup(NodeContentGroup *cGrp, const QString &key, bool *isEntry = nullptr); 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); void fixTrContext(NodeContentGroup &group, const QString &context);

Loading…
Cancel
Save