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. 3
      tests/auto/auto.pro
  3. 4
      tests/auto/qml/qml.pro
  4. 73
      tests/auto/qml/qmlsettingsgenerator/.gitignore
  5. 19
      tests/auto/qml/qmlsettingsgenerator/qmlsettingsgenerator.pro
  6. 4
      tests/auto/qml/qmlsettingsgenerator/tst_qmlsettingsgenerator.cpp
  7. 11
      tests/auto/qml/qmlsettingsgenerator/tst_qmlsettingsgenerator.qml
  8. BIN
      tests/auto/qml/qmlsettingsgenerator/tst_qmlsettingsgenerator.qmlc
  9. 10
      tools/settingsgenerator/main.cpp
  10. 13
      tools/settingsgenerator/settingsgenerator.cpp
  11. 3
      tools/settingsgenerator/settingsgenerator.h

15
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

3
tests/auto/auto.pro

@ -1,3 +1,4 @@
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.

10
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 <file> containing the settings definition"),
@ -58,6 +63,9 @@ int main(int argc, char *argv[])
parser.value(QStringLiteral("header")),
parser.value(QStringLiteral("impl"))
};
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) {

13
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<QString, QString> &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<EntryType*>(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<NodeType>(cNode)) {
@ -223,7 +228,7 @@ SettingsGeneratorBase::NodeContentGroup *SettingsGenerator::replaceNodeByEntry(S
return &(nonstd::get<EntryType>(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)
return res;
}

3
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<QString, QString> &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);

Loading…
Cancel
Save