From 72c060639d844196d5c5eeaf521f8e052f02406c Mon Sep 17 00:00:00 2001 From: Skycoder42 Date: Tue, 24 Jul 2018 23:08:12 +0200 Subject: [PATCH] update to use xsd enums --- src/mvvmcore/settingsentry.h | 120 +++++++++--------- .../settingsgenerator/generatortest.xml | 5 +- .../cppsettingsgenerator.cpp | 35 +++-- .../qmlsettingsgenerator.cpp | 77 +++++++---- .../settingsgenerator/qmlsettingsgenerator.h | 26 ++-- tools/settingsgenerator/qpmx.json | 2 +- .../settingsgenerator/qsettingsgenerator.xsd | 22 +++- 7 files changed, 173 insertions(+), 114 deletions(-) diff --git a/src/mvvmcore/settingsentry.h b/src/mvvmcore/settingsentry.h index 61c3829..b0b4269 100644 --- a/src/mvvmcore/settingsentry.h +++ b/src/mvvmcore/settingsentry.h @@ -39,11 +39,23 @@ private: QVariant _default; }; -template -class SettingsEntry> +template <> +class SettingsEntry { Q_DISABLE_COPY(SettingsEntry) +public: + inline SettingsEntry() = default; + + // internal + inline void setup(const QString &, ISettingsAccessor *, const QVariant & = {}) {} +}; + +template +class SettingsListEntry +{ + Q_DISABLE_COPY(SettingsListEntry) + public: class ListElement { @@ -60,10 +72,10 @@ public: inline operator TType() const && { return _self->getAt(_index); } private: - friend class SettingsEntry>; - inline ListElement(SettingsEntry> *self, int index) : _self{self}, _index{index} {} + friend class SettingsListEntry; + inline ListElement(SettingsListEntry *self, int index) : _self{self}, _index{index} {} - SettingsEntry> *_self; + SettingsListEntry *_self; int _index; }; @@ -95,15 +107,15 @@ public: private: template - friend class SettingsEntry>::iterator_base; + friend class SettingsListEntry::iterator_base; - inline iterator_value(SettingsEntry> *self, int index) : _self{self}, _index{index} {} + inline iterator_value(SettingsListEntry *self, int index) : _self{self}, _index{index} {} inline iterator_value(const iterator_value &other) = default; inline iterator_value &operator=(const iterator_value &other) = default; inline iterator_value(iterator_value &&other) noexcept = default; inline iterator_value &operator=(iterator_value &&other) noexcept = default; - SettingsEntry> *_self; + SettingsListEntry *_self; int _index; }; @@ -150,9 +162,9 @@ public: inline value_type operator[](difference_type delta) const { return iterator_value{_value._self, _value._index + delta}; } private: - friend class SettingsEntry>; + friend class SettingsListEntry; - inline iterator_base(SettingsEntry> *self, int index) : _value{self, index} {} + inline iterator_base(SettingsListEntry *self, int index) : _value{self, index} {} inline iterator_base(iterator_value value) : _value{std::move(value)} {} iterator_value _value; }; @@ -160,7 +172,7 @@ public: using iterator = iterator_base; using const_iterator = iterator_base; - SettingsEntry() = default; + SettingsListEntry() = default; bool isSet() const; QString key() const; @@ -169,7 +181,7 @@ public: void set(const QList &value); void reset(bool reInit = true); - SettingsEntry> &operator=(const QList &value); + SettingsListEntry &operator=(const QList &value); operator QList() const; int size() const; @@ -182,8 +194,8 @@ public: ListElement operator[](int index); const ListElement operator[](int index) const; - SettingsEntry> &operator+=(const TType &value); - SettingsEntry> &operator+=(const QList &values); + SettingsListEntry &operator+=(const TType &value); + SettingsListEntry &operator+=(const QList &values); iterator begin(); iterator end(); @@ -210,18 +222,6 @@ private: QList _init; }; -template <> -class SettingsEntry -{ - Q_DISABLE_COPY(SettingsEntry) - -public: - inline SettingsEntry() = default; - - // internal - inline void setup(const QString &, ISettingsAccessor *, const QVariant & = {}) {} -}; - // ------------- Generic Implementation ------------- template @@ -312,19 +312,19 @@ void SettingsEntry::setup(QString key, ISettingsAccessor *accessor, QVariant // ------------- Generic Implementation ListEntry ------------- template -bool SettingsEntry>::isSet() const +bool SettingsListEntry::isSet() const { return _accessor->contains(_key + QStringLiteral("/size")); } template -QString SettingsEntry>::key() const +QString SettingsListEntry::key() const { return _key; } template -QList SettingsEntry>::get() const +QList SettingsListEntry::get() const { auto mSize = size(); QList resList; @@ -335,14 +335,14 @@ QList SettingsEntry>::get() const } template -void SettingsEntry>::set(const QList &value) +void SettingsListEntry::set(const QList &value) { reset(false); push(value); } template -void SettingsEntry>::reset(bool reInit) +void SettingsListEntry::reset(bool reInit) { _accessor->remove(_key); if(reInit && !_init.isEmpty()) @@ -350,44 +350,44 @@ void SettingsEntry>::reset(bool reInit) } template -SettingsEntry> &SettingsEntry>::operator=(const QList &value) +SettingsListEntry &SettingsListEntry::operator=(const QList &value) { set(value); return *this; } template -SettingsEntry>::operator QList() const +SettingsListEntry::operator QList() const { return get(); } template -int SettingsEntry>::size() const +int SettingsListEntry::size() const { return _accessor->load(_key + QStringLiteral("/size"), 0).toInt(); } template -TType SettingsEntry>::getAt(int index) const +TType SettingsListEntry::getAt(int index) const { return _accessor->load(_key + QStringLiteral("/%1/value").arg(index), _default).template value(); } template -void SettingsEntry>::setAt(int index, const TType &value) +void SettingsListEntry::setAt(int index, const TType &value) { _accessor->save(_key + QStringLiteral("/%1/value").arg(index), QVariant::fromValue(value)); } template -void SettingsEntry>::push(const TType &value) +void SettingsListEntry::push(const TType &value) { push(QList{value}); } template -void SettingsEntry>::push(const QList &values) +void SettingsListEntry::push(const QList &values) { auto cIndex = size(); for(const auto &value : values) @@ -396,7 +396,7 @@ void SettingsEntry>::push(const QList &values) } template -TType QtMvvm::SettingsEntry>::pop() +TType QtMvvm::SettingsListEntry::pop() { auto res = getAt(size() - 1); chop(1); @@ -404,7 +404,7 @@ TType QtMvvm::SettingsEntry>::pop() } template -void QtMvvm::SettingsEntry>::chop(int count) +void QtMvvm::SettingsListEntry::chop(int count) { auto cSize = size(); auto nSize = qMax(size() - count, 0); @@ -414,76 +414,76 @@ void QtMvvm::SettingsEntry>::chop(int count) } template -const typename SettingsEntry>::ListElement SettingsEntry>::operator[](int index) const +const typename SettingsListEntry::ListElement SettingsListEntry::operator[](int index) const { return ListElement{this, index}; } template -typename SettingsEntry>::ListElement SettingsEntry>::operator[](int index) +typename SettingsListEntry::ListElement SettingsListEntry::operator[](int index) { return ListElement{this, index}; } template -SettingsEntry> &SettingsEntry>::operator+=(const TType &value) +SettingsListEntry &SettingsListEntry::operator+=(const TType &value) { push(value); return *this; } template -SettingsEntry> &SettingsEntry>::operator+=(const QList &values) +SettingsListEntry &SettingsListEntry::operator+=(const QList &values) { push(values); return *this; } template -typename SettingsEntry>::iterator SettingsEntry>::begin() +typename SettingsListEntry::iterator SettingsListEntry::begin() { return iterator{this, 0}; } template -typename SettingsEntry>::iterator QtMvvm::SettingsEntry>::end() +typename SettingsListEntry::iterator QtMvvm::SettingsListEntry::end() { return iterator{this, size()}; } template -typename SettingsEntry>::const_iterator SettingsEntry>::begin() const +typename SettingsListEntry::const_iterator SettingsListEntry::begin() const { return constBegin(); } template -typename SettingsEntry>::const_iterator SettingsEntry>::end() const +typename SettingsListEntry::const_iterator SettingsListEntry::end() const { return constEnd(); } template -typename SettingsEntry>::const_iterator SettingsEntry>::constBegin() const +typename SettingsListEntry::const_iterator SettingsListEntry::constBegin() const { - return const_iterator{const_cast>*>(this), 0}; + return const_iterator{const_cast*>(this), 0}; } template -typename SettingsEntry>::const_iterator SettingsEntry>::constEnd() const +typename SettingsListEntry::const_iterator SettingsListEntry::constEnd() const { - return const_iterator{const_cast>*>(this), size()}; + return const_iterator{const_cast*>(this), size()}; } template -void SettingsEntry>::addChangeCallback(const std::function)> &callback) +void SettingsListEntry::addChangeCallback(const std::function)> &callback) { addChangeCallback(_accessor, callback); } template -void SettingsEntry>::addChangeCallback(QObject *scope, const std::function)> &callback) +void SettingsListEntry::addChangeCallback(QObject *scope, const std::function)> &callback) { QObject::connect(_accessor, &ISettingsAccessor::entryChanged, scope, [this, callback](const QString &key, const QVariant &) { @@ -498,13 +498,13 @@ void SettingsEntry>::addChangeCallback(QObject *scope, const std::f } template -void SettingsEntry>::addChangeCallback(const std::function &callback) +void SettingsListEntry::addChangeCallback(const std::function &callback) { addChangeCallback(_accessor, callback); } template -void SettingsEntry>::addChangeCallback(QObject *scope, const std::function &callback) +void SettingsListEntry::addChangeCallback(QObject *scope, const std::function &callback) { QRegularExpression mKey {QStringLiteral("^%1\\/\\d+\\/value$").arg(QRegularExpression::escape(_key))}; mKey.optimize(); @@ -524,13 +524,13 @@ void SettingsEntry>::addChangeCallback(QObject *scope, const std::f } template -void SettingsEntry>::addSizeChangeCallback(const std::function &callback) +void SettingsListEntry::addSizeChangeCallback(const std::function &callback) { addSizeChangeCallback(_accessor, callback); } template -void SettingsEntry>::addSizeChangeCallback(QObject *scope, const std::function &callback) +void SettingsListEntry::addSizeChangeCallback(QObject *scope, const std::function &callback) { QString mKey = _key + QStringLiteral("/size"); auto mInit = _init; @@ -547,7 +547,7 @@ void SettingsEntry>::addSizeChangeCallback(QObject *scope, const st } template -void SettingsEntry>::setup(QString key, ISettingsAccessor *accessor, QVariant defaultValue) +void SettingsListEntry::setup(QString key, ISettingsAccessor *accessor, QVariant defaultValue) { Q_ASSERT_X(accessor, Q_FUNC_INFO, "You must set a valid accessor before initializing the settings!"); _key = std::move(key); @@ -556,7 +556,7 @@ void SettingsEntry>::setup(QString key, ISettingsAccessor *accessor } template -void QtMvvm::SettingsEntry >::setupInit(QList init) +void QtMvvm::SettingsListEntry::setupInit(QList init) { _init = std::move(init); if(!isSet()) diff --git a/tests/auto/mvvmcore/settingsgenerator/generatortest.xml b/tests/auto/mvvmcore/settingsgenerator/generatortest.xml index d00b1da..53779ef 100644 --- a/tests/auto/mvvmcore/settingsgenerator/generatortest.xml +++ b/tests/auto/mvvmcore/settingsgenerator/generatortest.xml @@ -1,12 +1,13 @@ + baseKey="tests" + scope="DestroyOnAppQuit"> QtCore/QDateTime QtCore/QUrl testbackend.h - + Test Backend 42 diff --git a/tools/settingsgenerator/cppsettingsgenerator.cpp b/tools/settingsgenerator/cppsettingsgenerator.cpp index 218dbc7..ba78080 100644 --- a/tools/settingsgenerator/cppsettingsgenerator.cpp +++ b/tools/settingsgenerator/cppsettingsgenerator.cpp @@ -110,14 +110,14 @@ void CppSettingsGenerator::writeEntryDeclaration(const EntryType &entry, const Q void CppSettingsGenerator::writeListEntryDeclaration(const SettingsGeneratorBase::ListEntryType &entry, const QHash &typeMappings, int intendent) { if(entry.contentNodes.isEmpty()) - _hdr << TABS << "QtMvvm::SettingsEntry> " << entry.key << ";\n"; + _hdr << TABS << "QtMvvm::SettingsListEntry<" << typeMappings.value(entry.type, entry.type) << "> " << entry.key << ";\n"; else { - const QString mType = QStringLiteral("QList<") + typeMappings.value(entry.type, entry.type) + QLatin1Char('>'); - _hdr << TABS << "struct : QtMvvm::SettingsEntry<" << mType << "> { //" << entry.key << "\n"; + const QString mType = typeMappings.value(entry.type, entry.type); + _hdr << TABS << "struct : QtMvvm::SettingsListEntry<" << mType << "> { //" << entry.key << "\n"; writeNodeElementDeclarations(entry, typeMappings, intendent + 1); - _hdr << TABS << "\tinline auto &operator=(const " << mType << " &__value) { SettingsEntry<" << mType << ">::operator=(__value); return *this; }\n"; - _hdr << TABS << "\tinline auto &operator+=(const " << typeMappings.value(entry.type, entry.type) << " &__value) { SettingsEntry<" << mType << ">::operator+=(__value); return *this; }\n"; - _hdr << TABS << "\tinline auto &operator+=(const " << mType << " &__value) { SettingsEntry<" << mType << ">::operator+=(__value); return *this; }\n"; + _hdr << TABS << "\tinline auto &operator=(const QList<" << mType << "> &__value) { SettingsListEntry<" << mType << ">::operator=(__value); return *this; }\n"; + _hdr << TABS << "\tinline auto &operator+=(const QList<" << mType << "> &__value) { SettingsListEntry<" << mType << ">::operator+=(__value); return *this; }\n"; + _hdr << TABS << "\tinline auto &operator+=(const " << mType << " &__value) { SettingsListEntry<" << mType << ">::operator+=(__value); return *this; }\n"; _hdr << TABS << "} " << entry.key << ";\n"; } } @@ -131,14 +131,31 @@ void CppSettingsGenerator::writeSource(const SettingsType &settings) _src << "#include \n"; _src << "\n"; - auto backend = settings.backend.value_or(BackendType{QStringLiteral("QtMvvm::QSettingsAccessor"), {}, {}}); + auto backend = settings.backend.value_or(BackendType{QStringLiteral("QtMvvm::QSettingsAccessor"), {}}); _src << "namespace {\n\n" << "void __generated_settings_setup()\n" << "{\n" << "\tQtMvvm::ServiceRegistry::instance()->registerObject<" << settings.name.value() << ">("; - if(backend.scope) - _src << "QtMvvm::ServiceRegistry::" << backend.scope.value(); + if(settings.scope) { + switch(settings.scope.value()) { + case SettingsGeneratorBase::DestroyOnAppQuit: + _src << "QtMvvm::ServiceRegistry::DestroyOnAppQuit"; + break; + case SettingsGeneratorBase::DestroyOnAppDestroy: + _src << "QtMvvm::ServiceRegistry::DestroyOnAppDestroy"; + break; + case SettingsGeneratorBase::DestroyOnRegistryDestroy: + _src << "QtMvvm::ServiceRegistry::DestroyOnRegistryDestroy"; + break; + case SettingsGeneratorBase::DestroyNever: + _src << "QtMvvm::ServiceRegistry::DestroyNever"; + break; + default: + Q_UNREACHABLE(); + break; + } + } _src << ");\n" << "}\n\n" << "}\n" diff --git a/tools/settingsgenerator/qmlsettingsgenerator.cpp b/tools/settingsgenerator/qmlsettingsgenerator.cpp index b11ecb5..d7548af 100644 --- a/tools/settingsgenerator/qmlsettingsgenerator.cpp +++ b/tools/settingsgenerator/qmlsettingsgenerator.cpp @@ -64,7 +64,7 @@ void QmlSettingsGenerator::writeHeader(const SettingsType &settings, const QStri auto keyList = settings.baseKey ? QStringList{settings.baseKey.value()} : QStringList{}; int offset; QList childOffsets; - std::tie(offset, childOffsets) = writeNodeContentClassesDeclarations(settings, keyList); + std::tie(offset, childOffsets) = writeNodeContentClasses(settings, keyList); // create the class _hdr << "class " << _name << " : public QObject\n" @@ -74,7 +74,7 @@ void QmlSettingsGenerator::writeHeader(const SettingsType &settings, const QStri QList> childConstructs; QList listEntries; - writeNodeClassPropertiesDeclarations(settings, keyList, childOffsets, listEntries, childConstructs); + writeProperties(settings, keyList, childOffsets, listEntries, childConstructs); _hdr << "\t" << _cppName << " *_settings;\n\n" << "public:\n" @@ -89,8 +89,11 @@ void QmlSettingsGenerator::writeHeader(const SettingsType &settings, const QStri << "\t\t" << _name << "{" << _cppName << "::instance(), parent}\n" << "\t{}\n\n" << "\tQtMvvm::ISettingsAccessor *accessor() const { return _settings->accessor(); }\n" - << "\t" << _cppName << " *settings() const { return _settings; }\n" - << "};\n\n" + << "\t" << _cppName << " *settings() const { return _settings; }\n\n" + << "\t" << (settings.prefix ? settings.prefix.value() + QLatin1Char(' ') : QString{}) << "static void registerQmlTypes(const char *uri, int major, int minor);\n"; + if(settings.qml) + _hdr << "\t" << (settings.prefix ? settings.prefix.value() + QLatin1Char(' ') : QString{}) << "static void registerQmlTypes();\n"; + _hdr << "};\n\n" << "#endif //" << incGuard << '\n'; } @@ -104,7 +107,7 @@ void QmlSettingsGenerator::writeListTypeBaseClass() << "\ttemplate \n" << "\tstruct ListData {\n" << "\t\tstatic_assert(std::is_base_of<" << _name << "_ListType, TList>::value, \"TList must extend " << _name << "_ListType\");\n" - << "\t\tQtMvvm::SettingsEntry> &entry;\n" + << "\t\tQtMvvm::SettingsListEntry &entry;\n" << "\t\tQList elements;\n" << "\t};\n\n" << "\t" << _name << "_ListType(QObject *parent) : \n" @@ -168,36 +171,36 @@ void QmlSettingsGenerator::writeListTypeBaseClass() << "\t}\n\n" << "private:\n" - << "\tQtMvvm::SettingsEntry> *_entry = nullptr;\n" + << "\tQtMvvm::SettingsListEntry *_entry = nullptr;\n" << "\tint _index = -1;\n" << "\tT _buffer{};\n" << "};\n\n"; } -std::tuple> QmlSettingsGenerator::writeNodeContentClassesDeclarations(const NodeContentGroup &node, const QStringList &keyList, int offset) +std::tuple> QmlSettingsGenerator::writeNodeContentClasses(const NodeContentGroup &node, const QStringList &keyList, int offset) { QList offsetList; for(const auto &cNode : node.contentNodes) { if(nonstd::holds_alternative(cNode)) { - offset = writeNodeClassDeclaration(nonstd::get(cNode), keyList, offset); + offset = writeNodeClass(nonstd::get(cNode), keyList, offset); offsetList.append(offset - 1); } else if(nonstd::holds_alternative(cNode)) { if(!nonstd::get(cNode).contentNodes.isEmpty()) { - offset = writeNodeClassDeclaration(nonstd::get(cNode), keyList, offset); + offset = writeNodeClass(nonstd::get(cNode), keyList, offset); offsetList.append(offset - 1); } else offsetList.append(-1); } else if(nonstd::holds_alternative(cNode)) { - offset = writeListEntryListClass(nonstd::get(cNode), offset); + offset = writeListEntryElementClass(nonstd::get(cNode), keyList, offset); offsetList.append(offset - 1); //double offset!!! if(!nonstd::get(cNode).contentNodes.isEmpty()) { - offset = writeNodeClassDeclaration(nonstd::get(cNode), keyList, offset); + offset = writeNodeClass(nonstd::get(cNode), keyList, offset); offsetList.append(offset - 1); } else offsetList.append(-1); } else if(nonstd::holds_alternative(cNode)) { QList subList; - std::tie(offset, subList) = writeNodeContentClassesDeclarations(nonstd::get(cNode), keyList, offset); + std::tie(offset, subList) = writeNodeContentClasses(nonstd::get(cNode), keyList, offset); offsetList.append(subList); } else Q_UNREACHABLE(); @@ -205,19 +208,19 @@ std::tuple> QmlSettingsGenerator::writeNodeContentClassesDeclara return std::make_tuple(offset, offsetList); } -int QmlSettingsGenerator::writeNodeClassDeclaration(const NodeType &node, QStringList keyList, int offset) +int QmlSettingsGenerator::writeNodeClass(const NodeType &node, QStringList keyList, int offset) { keyList.append(node.key); QList childOffsets; - std::tie(offset, childOffsets) = writeNodeContentClassesDeclarations(node, keyList, offset); + std::tie(offset, childOffsets) = writeNodeContentClasses(node, keyList, offset); - _hdr << "class " << _name << "_" << offset << " : public QObject // " << node.key << "\n" + _hdr << "class " << _name << "_" << offset << " : public QObject // " << keyList.join(QLatin1Char('/')) << "\n" << "{\n" << "\tQ_OBJECT\n\n"; QList> childConstructs; QList listEntries; - writeNodeClassPropertiesDeclarations(node, keyList, childOffsets, listEntries, childConstructs); + writeProperties(node, keyList, childOffsets, listEntries, childConstructs); _hdr << "\t" << _cppName << " *_settings;\n\n" << "public:\n" @@ -233,10 +236,11 @@ int QmlSettingsGenerator::writeNodeClassDeclaration(const NodeType &node, QStrin return ++offset; } -int QmlSettingsGenerator::writeListEntryListClass(const ListEntryType &entry, int offset) +int QmlSettingsGenerator::writeListEntryElementClass(const ListEntryType &entry, QStringList keyList, int offset) { + keyList.append(entry.key); const auto &mType = _typeMappings.value(entry.type, entry.type); - _hdr << "class " << _name << "_" << offset << " : public " << _name << "_ListType<" << mType << "> // " << entry.key << "\n" + _hdr << "class " << _name << "_" << offset << " : public " << _name << "_ListType<" << mType << "> // " << keyList.join(QLatin1Char('/')) << " (list-element)\n" << "{\n" << "\tQ_OBJECT\n\n" << "\tQ_PROPERTY(" << mType << " value READ value WRITE setValue NOTIFY valueChanged)\n\n" @@ -251,25 +255,25 @@ int QmlSettingsGenerator::writeListEntryListClass(const ListEntryType &entry, in return ++offset; } -void QmlSettingsGenerator::writeNodeClassPropertiesDeclarations(const NodeContentGroup &node, const QStringList &keyList, QList &childOffsets, QList &listEntries, QList> &childConstructs) +void QmlSettingsGenerator::writeProperties(const NodeContentGroup &node, const QStringList &keyList, QList &childOffsets, QList &listEntries, QList> &childConstructs) { for(const auto &cNode : node.contentNodes) { if(nonstd::holds_alternative(cNode)) - writeNodePropertyDeclaration(nonstd::get(cNode), childOffsets.takeFirst(), childConstructs); + writeNodeProperty(nonstd::get(cNode), childOffsets.takeFirst(), childConstructs); else if(nonstd::holds_alternative(cNode)) - writeEntryPropertyDeclaration(nonstd::get(cNode), keyList, childOffsets.takeFirst(), childConstructs); + writeEntryProperty(nonstd::get(cNode), keyList, childOffsets.takeFirst(), childConstructs); else if(nonstd::holds_alternative(cNode)) { auto lIndex = childOffsets.takeFirst(); //done seperately because of undefine param call order - writeListEntryPropertyDeclaration(nonstd::get(cNode), keyList, lIndex, childOffsets.takeFirst(), childConstructs); + writeListEntryProperty(nonstd::get(cNode), keyList, lIndex, childOffsets.takeFirst(), childConstructs); listEntries.append(lIndex); } else if(nonstd::holds_alternative(cNode)) - writeNodeClassPropertiesDeclarations(nonstd::get(cNode), keyList, childOffsets, listEntries, childConstructs); + writeProperties(nonstd::get(cNode), keyList, childOffsets, listEntries, childConstructs); else Q_UNREACHABLE(); } } -void QmlSettingsGenerator::writeNodePropertyDeclaration(const NodeType &entry, int classIndex, QList> &childConstructs, const QString &overwriteName) +void QmlSettingsGenerator::writeNodeProperty(const NodeType &entry, int classIndex, QList> &childConstructs, const QString &overwriteName) { const auto &mName = overwriteName.isNull() ? entry.key : overwriteName; _hdr << "\tQ_PROPERTY(" << _name << "_" << classIndex << "* " << mName @@ -278,7 +282,7 @@ void QmlSettingsGenerator::writeNodePropertyDeclaration(const NodeType &entry, i childConstructs.append({mName, classIndex}); } -void QmlSettingsGenerator::writeEntryPropertyDeclaration(const EntryType &entry, QStringList keyList, int classIndex, QList> &childConstructs) +void QmlSettingsGenerator::writeEntryProperty(const EntryType &entry, QStringList keyList, int classIndex, QList> &childConstructs) { keyList.append(entry.key); const auto &mType = _typeMappings.value(entry.type, entry.type); @@ -296,10 +300,10 @@ void QmlSettingsGenerator::writeEntryPropertyDeclaration(const EntryType &entry, } if(!entry.contentNodes.isEmpty()) - writeNodePropertyDeclaration(entry, classIndex, childConstructs, entry.qmlGroupKey.value_or(entry.key + QStringLiteral("Group"))); + writeNodeProperty(entry, classIndex, childConstructs, entry.qmlGroupKey.value_or(entry.key + QStringLiteral("Group"))); } -void QmlSettingsGenerator::writeListEntryPropertyDeclaration(const ListEntryType &entry, QStringList keyList, int listIndex, int classIndex, QList> &childConstructs) +void QmlSettingsGenerator::writeListEntryProperty(const ListEntryType &entry, QStringList keyList, int listIndex, int classIndex, QList> &childConstructs) { keyList.append(entry.key); _hdr << "\tQ_PROPERTY(QQmlListProperty<" << _name << "_" << listIndex << "> " << entry.key @@ -318,7 +322,7 @@ void QmlSettingsGenerator::writeListEntryPropertyDeclaration(const ListEntryType childConstructs.append({entry.key, -1}); if(!entry.contentNodes.isEmpty()) - writeNodePropertyDeclaration(entry, classIndex, childConstructs, entry.qmlGroupKey.value_or(entry.key + QStringLiteral("Group"))); + writeNodeProperty(entry, classIndex, childConstructs, entry.qmlGroupKey.value_or(entry.key + QStringLiteral("Group"))); } void QmlSettingsGenerator::writeMemberInits(const QStringList &keyList, const QList> &childConstructs) @@ -372,4 +376,21 @@ void QmlSettingsGenerator::writeListEntryPropertySignalConnect(const SettingsGen void QmlSettingsGenerator::writeSource(const SettingsType &settings) { _src << "#include \"" << _hdrFile.fileName() << "\"\n\n"; + + writeQmlRegistration(settings); + + if(settings.qml) { + const auto &qml = settings.qml.value(); + _src << "\nvoid " << _name << "::registerQmlTypes()\n" + << "{\n" + << "\tregisterQmlTypes(\"" << qml.uri << "\", " << qml.major << ", " << qml.minor << ");\n" + << "}\n"; + } +} + +void QmlSettingsGenerator::writeQmlRegistration(const SettingsType &settings) +{ + _src << "\nvoid " << _name << "::registerQmlTypes(const char *uri, int major, int minor)\n" + << "{\n" + << "}\n"; } diff --git a/tools/settingsgenerator/qmlsettingsgenerator.h b/tools/settingsgenerator/qmlsettingsgenerator.h index 4eb9495..cf4af0e 100644 --- a/tools/settingsgenerator/qmlsettingsgenerator.h +++ b/tools/settingsgenerator/qmlsettingsgenerator.h @@ -28,18 +28,18 @@ private: void writeListTypeBaseClass(); - std::tuple> writeNodeContentClassesDeclarations(const NodeContentGroup &node, const QStringList &keyList, int offset = 0); - int writeNodeClassDeclaration(const NodeType &node, QStringList keyList, int offset); - int writeListEntryListClass(const ListEntryType &entry, int offset); - - void writeNodeClassPropertiesDeclarations(const NodeContentGroup &node, - const QStringList &keyList, - QList &childOffsets, - QList &listEntries, - QList> &childConstructs); - void writeNodePropertyDeclaration(const NodeType &entry, int classIndex, QList> &childConstructs, const QString &overwriteName = {}); - void writeEntryPropertyDeclaration(const EntryType &entry, QStringList keyList, int classIndex, QList> &childConstructs); - void writeListEntryPropertyDeclaration(const ListEntryType &entry, QStringList keyList, int listIndex, int classIndex, QList> &childConstructs); + std::tuple> writeNodeContentClasses(const NodeContentGroup &node, const QStringList &keyList, int offset = 0); + int writeNodeClass(const NodeType &node, QStringList keyList, int offset); + int writeListEntryElementClass(const ListEntryType &entry, QStringList keyList, int offset); + + void writeProperties(const NodeContentGroup &node, + const QStringList &keyList, + QList &childOffsets, + QList &listEntries, + QList> &childConstructs); + void writeNodeProperty(const NodeType &entry, int classIndex, QList> &childConstructs, const QString &overwriteName = {}); + void writeEntryProperty(const EntryType &entry, QStringList keyList, int classIndex, QList> &childConstructs); + void writeListEntryProperty(const ListEntryType &entry, QStringList keyList, int listIndex, int classIndex, QList> &childConstructs); void writeMemberInits(const QStringList &keyList, const QList> &childConstructs); void writeEntryPropertySignalConnects(const NodeContentGroup &node, const QStringList &keyList, int classIndex, QList &listEntries); @@ -47,6 +47,8 @@ private: void writeListEntryPropertySignalConnect(const ListEntryType &entry, QStringList keyList, QList &listEntries); void writeSource(const SettingsType &settings); + + void writeQmlRegistration(const SettingsType &settings); }; #endif // QMLSETTINGSGENERATOR_H diff --git a/tools/settingsgenerator/qpmx.json b/tools/settingsgenerator/qpmx.json index 3de11e6..e17c9d4 100644 --- a/tools/settingsgenerator/qpmx.json +++ b/tools/settingsgenerator/qpmx.json @@ -3,7 +3,7 @@ { "package": "de.skycoder42.qxmlcodegen", "provider": "qpm", - "version": "1.1.7" + "version": "1.2.0" } ], "license": { diff --git a/tools/settingsgenerator/qsettingsgenerator.xsd b/tools/settingsgenerator/qsettingsgenerator.xsd index d0ce70c..5ba393d 100644 --- a/tools/settingsgenerator/qsettingsgenerator.xsd +++ b/tools/settingsgenerator/qsettingsgenerator.xsd @@ -10,6 +10,24 @@ + + + + + + + + + + + + + + + + + + @@ -23,7 +41,7 @@ - + @@ -62,7 +80,6 @@ - @@ -117,6 +134,7 @@ +