From e2e8efc74fff2a49f8484658b957479a81c470bf Mon Sep 17 00:00:00 2001 From: Skycoder42 Date: Fri, 23 Feb 2018 01:18:42 +0100 Subject: [PATCH] implemented settings core code except the translator feature --- .../mvvmcore/SampleCore/drawerviewmodel.cpp | 5 ++ .../mvvmcore/SampleCore/sampleviewmodel.cpp | 6 ++ .../mvvmcore/SampleCore/sampleviewmodel.h | 2 + .../mvvmquick/SampleQuick/SampleQuick.pro | 2 +- .../SampleWidgets/SampleWidgets.pro | 2 +- src/mvvmcore/translations/qtmvvmcore_de.ts | 2 +- .../translations/qtmvvmcore_template.ts | 2 +- src/mvvmsettingscore/mvvmsettingscore.pro | 4 +- .../qtmvvmsettingscore_global.cpp | 1 + src/mvvmsettingscore/settingssetup.h | 11 +++- src/mvvmsettingscore/settingssetuploader.cpp | 52 +++++++++++---- src/mvvmsettingscore/settingssetuploader_p.h | 37 ++++++----- src/mvvmsettingscore/settingsviewmodel.cpp | 65 ++++++++++++++++--- src/mvvmsettingscore/settingsviewmodel.h | 24 +++++-- src/mvvmsettingscore/settingsviewmodel_p.h | 7 +- .../translations/qtmvvsettingsmcore_de.ts | 30 +++++++++ .../qtmvvsettingsmcore_template.ts | 30 +++++++++ .../translations/qtmvvmwidgets_de.ts | 4 +- .../translations/qtmvvmwidgets_template.ts | 4 +- sync.profile | 5 +- 20 files changed, 234 insertions(+), 61 deletions(-) create mode 100644 src/mvvmsettingscore/translations/qtmvvsettingsmcore_de.ts create mode 100644 src/mvvmsettingscore/translations/qtmvvsettingsmcore_template.ts diff --git a/examples/mvvmcore/SampleCore/drawerviewmodel.cpp b/examples/mvvmcore/SampleCore/drawerviewmodel.cpp index 72dfed7..acd386c 100644 --- a/examples/mvvmcore/SampleCore/drawerviewmodel.cpp +++ b/examples/mvvmcore/SampleCore/drawerviewmodel.cpp @@ -1,4 +1,5 @@ #include "drawerviewmodel.h" +#include #include "sampleviewmodel.h" #include "tabviewmodel.h" @@ -9,6 +10,7 @@ DrawerViewModel::DrawerViewModel(QObject *parent) : { _navModel->appendRow(new QStandardItem(tr("Main Sample"))); _navModel->appendRow(new QStandardItem(tr("Tab Sample"))); + _navModel->appendRow(new QStandardItem(tr("Settings"))); } DrawerViewModel::~DrawerViewModel() @@ -30,6 +32,9 @@ void DrawerViewModel::open(int index) case 1: show(); break; + case 2: + show(); + break; default: break; } diff --git a/examples/mvvmcore/SampleCore/sampleviewmodel.cpp b/examples/mvvmcore/SampleCore/sampleviewmodel.cpp index 937bd1b..5508062 100644 --- a/examples/mvvmcore/SampleCore/sampleviewmodel.cpp +++ b/examples/mvvmcore/SampleCore/sampleviewmodel.cpp @@ -1,6 +1,7 @@ #include "sampleviewmodel.h" #include #include +#include #include "resultviewmodel.h" #include "tabviewmodel.h" @@ -70,6 +71,11 @@ void SampleViewModel::showTabs() show(); } +void SampleViewModel::showSettings() +{ + show(); +} + void SampleViewModel::getInput() { QtMvvm::getInput(tr("Random input"), diff --git a/examples/mvvmcore/SampleCore/sampleviewmodel.h b/examples/mvvmcore/SampleCore/sampleviewmodel.h index d2f6ddc..3a4293c 100644 --- a/examples/mvvmcore/SampleCore/sampleviewmodel.h +++ b/examples/mvvmcore/SampleCore/sampleviewmodel.h @@ -33,6 +33,8 @@ public Q_SLOTS: void setActive(bool active); void showTabs(); + void showSettings(); + void getInput(); void getFiles(); void getResult(); diff --git a/examples/mvvmquick/SampleQuick/SampleQuick.pro b/examples/mvvmquick/SampleQuick/SampleQuick.pro index b145764..7774f24 100644 --- a/examples/mvvmquick/SampleQuick/SampleQuick.pro +++ b/examples/mvvmquick/SampleQuick/SampleQuick.pro @@ -1,6 +1,6 @@ TEMPLATE = app -QT += core gui qml quick mvvmquick widgets +QT += core gui qml quick mvvmquick widgets mvvmsettingscore TARGET = SampleQuick diff --git a/examples/mvvmwidgets/SampleWidgets/SampleWidgets.pro b/examples/mvvmwidgets/SampleWidgets/SampleWidgets.pro index 6aa522e..043826b 100644 --- a/examples/mvvmwidgets/SampleWidgets/SampleWidgets.pro +++ b/examples/mvvmwidgets/SampleWidgets/SampleWidgets.pro @@ -1,6 +1,6 @@ TEMPLATE = app -QT += core gui widgets mvvmwidgets +QT += core gui widgets mvvmwidgets mvvmsettingscore TARGET = SampleWidgets diff --git a/src/mvvmcore/translations/qtmvvmcore_de.ts b/src/mvvmcore/translations/qtmvvmcore_de.ts index 4a00af8..0091134 100644 --- a/src/mvvmcore/translations/qtmvvmcore_de.ts +++ b/src/mvvmcore/translations/qtmvvmcore_de.ts @@ -4,7 +4,7 @@ MessageConfig - + %1 — Version %2 diff --git a/src/mvvmcore/translations/qtmvvmcore_template.ts b/src/mvvmcore/translations/qtmvvmcore_template.ts index d8499d7..2cfa47a 100644 --- a/src/mvvmcore/translations/qtmvvmcore_template.ts +++ b/src/mvvmcore/translations/qtmvvmcore_template.ts @@ -4,7 +4,7 @@ MessageConfig - + %1 — Version %2 diff --git a/src/mvvmsettingscore/mvvmsettingscore.pro b/src/mvvmsettingscore/mvvmsettingscore.pro index 531931d..45d4a8e 100644 --- a/src/mvvmsettingscore/mvvmsettingscore.pro +++ b/src/mvvmsettingscore/mvvmsettingscore.pro @@ -6,12 +6,12 @@ HEADERS += qtmvvmsettingscore_global.h \ settingsviewmodel.h \ settingssetup.h \ settingssetuploader_p.h \ - settingsviewmodel_p.h + settingsviewmodel_p.h SOURCES += \ settingsviewmodel.cpp \ settingssetuploader.cpp \ - qtmvvmsettingscore_global.cpp + qtmvvmsettingscore_global.cpp TRANSLATIONS += \ translations/qtmvvsettingsmcore_de.ts \ diff --git a/src/mvvmsettingscore/qtmvvmsettingscore_global.cpp b/src/mvvmsettingscore/qtmvvmsettingscore_global.cpp index 1a9b7e0..d6e2663 100644 --- a/src/mvvmsettingscore/qtmvvmsettingscore_global.cpp +++ b/src/mvvmsettingscore/qtmvvmsettingscore_global.cpp @@ -11,6 +11,7 @@ namespace { void qtMvvmSettingsCoreStartup() { + QtMvvm::registerInterfaceConverter(); try { ServiceRegistry::instance()->registerInterface(true); } catch(ServiceExistsException &e) { diff --git a/src/mvvmsettingscore/settingssetup.h b/src/mvvmsettingscore/settingssetup.h index 890babd..dc46d03 100644 --- a/src/mvvmsettingscore/settingssetup.h +++ b/src/mvvmsettingscore/settingssetup.h @@ -6,11 +6,14 @@ #include #include #include +#include #include "QtMvvmSettingsCore/qtmvvmsettingscore_global.h" namespace QtMvvm { +namespace SettingsElements { + struct SettingsEntry { QString key; @@ -28,6 +31,7 @@ struct SettingsEntry struct SettingsGroup { QString title; + QString tooltip; QList entries; @@ -67,17 +71,22 @@ struct SettingsSetup QList categories; }; +} + +class SettingsLoaderException : public QException {}; + class ISettingsSetupLoader { public: virtual inline ~ISettingsSetupLoader() = default; - virtual SettingsSetup loadSetup(const QString &platform, const QFileSelector *selector, const QString &filePath) const = 0; + virtual SettingsElements::SettingsSetup loadSetup(const QString &filePath, const QString &frontend, const QFileSelector *selector) const = 0; }; } #define QtMvvm_ISettingsSetupLoaderIid "de.skycoder42.qtmvvm.settings.core.ISettingsSetupLoader" Q_DECLARE_INTERFACE(QtMvvm::ISettingsSetupLoader, QtMvvm_ISettingsSetupLoaderIid) +Q_DECLARE_METATYPE(QtMvvm::ISettingsSetupLoader*) #endif // QTMVVM_SETTINGSSETUP_H diff --git a/src/mvvmsettingscore/settingssetuploader.cpp b/src/mvvmsettingscore/settingssetuploader.cpp index c6d3d3e..c836795 100644 --- a/src/mvvmsettingscore/settingssetuploader.cpp +++ b/src/mvvmsettingscore/settingssetuploader.cpp @@ -1,5 +1,7 @@ #include "settingssetuploader_p.h" +#include using namespace QtMvvm; +using namespace QtMvvm::SettingsElements; #define throwXmlError(...) throw SettingsXmlException(__VA_ARGS__) #define throwAttrib(reader, attrib) throwXmlError(reader, "Attribute \"" attrib "\" is required, but was not set!") @@ -11,6 +13,8 @@ using namespace QtMvvm; #define stringValue(key) attributes().value(QStringLiteral(key)).toString() #define boolValue(key) attributes().value(QStringLiteral(key)) == QStringLiteral("true") +#define trctx(x) QCoreApplication::translate("qtmvvm_settings_xml", qUtf8Printable(x)) + QUrl SettingsSetupLoader::defaultIcon(QStringLiteral("qrc:/qtmvvm/icons/settings.svg")); SettingsSetupLoader::SettingsSetupLoader(QObject *parent) : @@ -18,7 +22,7 @@ SettingsSetupLoader::SettingsSetupLoader(QObject *parent) : _cache() {} -SettingsSetup SettingsSetupLoader::loadSetup(const QString &platform, const QFileSelector *selector, const QString &filePath) const +SettingsSetup SettingsSetupLoader::loadSetup(const QString &filePath, const QString &frontend, const QFileSelector *selector) const { SettingsSetup setup; if(!_cache.contains(filePath)) { @@ -49,10 +53,23 @@ SettingsSetup SettingsSetupLoader::loadSetup(const QString &platform, const QFil } else setup = *(_cache.object(filePath)); - //todo platform/selector + clearSetup(setup, frontend, selector->allSelectors()); + return setup; +} +bool SettingsSetupLoader::event(QEvent *event) +{ + //reset the loaded cache on language changes + switch(event->type()) { + case QEvent::LanguageChange: + case QEvent::LocaleChange: + _cache.clear(); + break; + default: + break; + } - return setup; + return QObject::event(event); } SettingsCategory SettingsSetupLoader::readCategory(QXmlStreamReader &reader) const @@ -64,11 +81,11 @@ SettingsCategory SettingsSetupLoader::readCategory(QXmlStreamReader &reader) con auto category = createDefaultCategory(); if(reader.hasValue("title")) - category.title = reader.stringValue("title"); + category.title = trctx(reader.stringValue("title")); if(reader.hasValue("icon")) category.icon = reader.stringValue("icon"); if(reader.hasValue("tooltip")) - category.tooltip = reader.stringValue("tooltip"); + category.tooltip = trctx(reader.stringValue("tooltip")); category.frontends = reader.stringValue("frontends"); category.selectors = reader.stringValue("selectors"); @@ -109,11 +126,11 @@ SettingsSection SettingsSetupLoader::readSection(QXmlStreamReader &reader) const auto section = createDefaultSection(); if(reader.hasValue("title")) - section.title = reader.stringValue("title"); + section.title = trctx(reader.stringValue("title")); if(reader.hasValue("icon")) section.icon = reader.stringValue("icon"); if(reader.hasValue("tooltip")) - section.tooltip = reader.stringValue("tooltip"); + section.tooltip = trctx(reader.stringValue("tooltip")); section.frontends = reader.stringValue("frontends"); section.selectors = reader.stringValue("selectors"); @@ -154,7 +171,9 @@ SettingsGroup SettingsSetupLoader::readGroup(QXmlStreamReader &reader) const SettingsGroup group; if(reader.hasValue("title")) - group.title = reader.stringValue("title"); + group.title = trctx(reader.stringValue("title")); + if(reader.hasValue("tooltip")) + group.tooltip = trctx(reader.stringValue("tooltip")); group.frontends = reader.stringValue("frontends"); group.selectors = reader.stringValue("selectors"); @@ -200,15 +219,15 @@ SettingsEntry SettingsSetupLoader::readEntry(QXmlStreamReader &reader) const entry.type = reader.stringValue("type").toLatin1(); if(!reader.hasValue("title")) throwAttrib(reader, "title"); - entry.title = reader.stringValue("title"); - entry.tooltip = reader.stringValue("tooltip"); - entry.defaultValue = reader.stringValue("default"); + entry.title = trctx(reader.stringValue("title")); + entry.tooltip = trctx(reader.stringValue("tooltip")); + entry.defaultValue = trctx(reader.stringValue("default")); entry.frontends = reader.stringValue("frontends"); entry.selectors = reader.stringValue("selectors"); while(reader.readNextStartElement()) { if(reader.name() == QStringLiteral("SearchKey")) - entry.searchKeys.append(reader.readElementText()); + entry.searchKeys.append(trctx(reader.readElementText())); else if(reader.name() == QStringLiteral("Property")) { auto prop = readProperty(reader); entry.properties.insert(std::get<0>(prop), std::get<1>(prop)); @@ -279,7 +298,11 @@ QVariant SettingsSetupLoader::readElement(QXmlStreamReader &reader) const auto typeId = QMetaType::type(qUtf8Printable(type)); if(typeId == QMetaType::UnknownType) throwXmlError(reader, "Unknown type: " + type.toUtf8()); - QVariant mVariant = reader.readElementText(); + QVariant mVariant; + if(reader.boolValue("tr")) + mVariant = trctx(reader.readElementText()); + else + mVariant = reader.readElementText(); if(!mVariant.convert(typeId)) throwXmlError(reader, "Failed to convert element data to type: " + type.toUtf8()); @@ -358,6 +381,7 @@ bool SettingsSetupLoader::isUsable(const T &configElement, const QString &fronte SettingsXmlException::SettingsXmlException(const QXmlStreamReader &reader) : + SettingsLoaderException(), _what(QStringLiteral("XML Error at %1:%2. Error: %3") .arg(reader.lineNumber()) .arg(reader.columnNumber()) @@ -374,6 +398,7 @@ SettingsXmlException::SettingsXmlException(QXmlStreamReader &reader, const QByte {} SettingsXmlException::SettingsXmlException(const QFile &fileError) : + SettingsLoaderException(), _what(QStringLiteral("Failed to open file \"%1\" with error: %2") .arg(fileError.fileName()) .arg(fileError.errorString()) @@ -381,6 +406,7 @@ SettingsXmlException::SettingsXmlException(const QFile &fileError) : {} SettingsXmlException::SettingsXmlException(const SettingsXmlException * const other) : + SettingsLoaderException(), _what(other->_what) {} diff --git a/src/mvvmsettingscore/settingssetuploader_p.h b/src/mvvmsettingscore/settingssetuploader_p.h index da127e6..315f634 100644 --- a/src/mvvmsettingscore/settingssetuploader_p.h +++ b/src/mvvmsettingscore/settingssetuploader_p.h @@ -7,7 +7,6 @@ #include #include #include -#include #include #include "qtmvvmsettingscore_global.h" @@ -21,43 +20,45 @@ class SettingsSetupLoader : public QObject, public ISettingsSetupLoader Q_INTERFACES(QtMvvm::ISettingsSetupLoader) public: - SettingsSetupLoader(QObject *parent = nullptr); + Q_INVOKABLE SettingsSetupLoader(QObject *parent = nullptr); - SettingsSetup loadSetup(const QString &platform, const QFileSelector *selector, const QString &filePath) const override; + SettingsElements::SettingsSetup loadSetup(const QString &filePath, const QString &frontend, const QFileSelector *selector) const final; + + bool event(QEvent *event) override; private: static QUrl defaultIcon; - mutable QCache _cache; + mutable QCache _cache; //functions to read the settings XML - SettingsCategory readCategory(QXmlStreamReader &reader) const; - SettingsCategory readDefaultCategory(QXmlStreamReader &reader) const; + SettingsElements::SettingsCategory readCategory(QXmlStreamReader &reader) const; + SettingsElements::SettingsCategory readDefaultCategory(QXmlStreamReader &reader) const; - SettingsSection readSection(QXmlStreamReader &reader) const; - SettingsSection readDefaultSection(QXmlStreamReader &reader) const; + SettingsElements::SettingsSection readSection(QXmlStreamReader &reader) const; + SettingsElements::SettingsSection readDefaultSection(QXmlStreamReader &reader) const; - SettingsGroup readGroup(QXmlStreamReader &reader) const; - SettingsGroup readDefaultGroup(QXmlStreamReader &reader) const; + SettingsElements::SettingsGroup readGroup(QXmlStreamReader &reader) const; + SettingsElements::SettingsGroup readDefaultGroup(QXmlStreamReader &reader) const; - SettingsEntry readEntry(QXmlStreamReader &reader) const; + SettingsElements::SettingsEntry readEntry(QXmlStreamReader &reader) const; - SettingsCategory createDefaultCategory() const; - SettingsSection createDefaultSection() const; + SettingsElements::SettingsCategory createDefaultCategory() const; + SettingsElements::SettingsSection createDefaultSection() const; std::tuple readProperty(QXmlStreamReader &reader) const; QVariant readElement(QXmlStreamReader &reader) const; //Functions to filter the elements - void clearSetup(SettingsSetup &setup, const QString &frontend, const QStringList &selectors) const; - void clearCategory(SettingsCategory &category, const QString &frontend, const QStringList &selectors) const; - void clearSection(SettingsSection §ion, const QString &frontend, const QStringList &selectors) const; - void clearGroup(SettingsGroup &group, const QString &frontend, const QStringList &selectors) const; + void clearSetup(SettingsElements::SettingsSetup &setup, const QString &frontend, const QStringList &selectors) const; + void clearCategory(SettingsElements::SettingsCategory &category, const QString &frontend, const QStringList &selectors) const; + void clearSection(SettingsElements::SettingsSection §ion, const QString &frontend, const QStringList &selectors) const; + void clearGroup(SettingsElements::SettingsGroup &group, const QString &frontend, const QStringList &selectors) const; template bool isUsable(const T &configElement, const QString &frontend, const QStringList &selectors) const; }; -class SettingsXmlException : public QException +class SettingsXmlException : public SettingsLoaderException { public: SettingsXmlException(const QXmlStreamReader &reader); diff --git a/src/mvvmsettingscore/settingsviewmodel.cpp b/src/mvvmsettingscore/settingsviewmodel.cpp index 4ef516e..16c186a 100644 --- a/src/mvvmsettingscore/settingsviewmodel.cpp +++ b/src/mvvmsettingscore/settingsviewmodel.cpp @@ -7,6 +7,9 @@ using namespace QtMvvm; +const QString SettingsViewModel::paramSettings(QStringLiteral("settings")); +const QString SettingsViewModel::paramSetupFile(QStringLiteral("setupFile")); + SettingsViewModel::SettingsViewModel(QObject *parent) : ViewModel(parent), d(new SettingsViewModelPrivate()) @@ -14,24 +17,59 @@ SettingsViewModel::SettingsViewModel(QObject *parent) : SettingsViewModel::~SettingsViewModel() {} -void SettingsViewModel::showSettings(ViewModel *parent) +QVariantHash SettingsViewModel::showParams(QSettings *settings, const QString &setupFile) { - showSettings(nullptr, {}, parent); + return { + {paramSettings, QVariant::fromValue(settings)}, + {paramSetupFile, setupFile} + }; } -void SettingsViewModel::showSettings(QSettings *settings, const QString &setupFile, ViewModel *parent) +bool SettingsViewModel::canRestoreDefaults() const { - + return true; } -bool SettingsViewModel::canRestoreDefaults() const +MessageConfig SettingsViewModel::restoreConfig() const { - return true; + MessageConfig config; + config.setType(MessageConfig::TypeMessageBox); + config.setSubType(MessageConfig::SubTypeWarning); + config.setTitle(tr("Restore Defaults?")); + config.setText(tr("All custom changes will be deleted and the defaults restored. This cannot be undone!")); + config.setButtons(MessageConfig::Yes | MessageConfig::No); + return config; } ISettingsSetupLoader *SettingsViewModel::settingsSetupLoader() const { - return d->settingsSetupLoader; + return d->setupLoader; +} + +SettingsElements::SettingsSetup SettingsViewModel::loadSetup(const QString &frontend) const +{ + QFileSelector selector; + return d->setupLoader->loadSetup(d->setupFile, frontend, &selector); +} + +QSettings *SettingsViewModel::settings() const +{ + return d->settings; +} + +QVariant SettingsViewModel::loadValue(const QString &key, const QVariant &defaultValue) const +{ + return d->settings->value(key, defaultValue); +} + +void SettingsViewModel::saveValue(const QString &key, const QVariant &value) +{ + d->settings->setValue(key, value); +} + +void SettingsViewModel::resetValue(const QString &key) +{ + d->settings->remove(key); } void SettingsViewModel::callAction(const QString &entryId) @@ -41,14 +79,21 @@ void SettingsViewModel::callAction(const QString &entryId) void SettingsViewModel::setSettingsSetupLoader(ISettingsSetupLoader *settingsSetupLoader) { - if (d->settingsSetupLoader == settingsSetupLoader) + if (d->setupLoader == settingsSetupLoader) return; - d->settingsSetupLoader = settingsSetupLoader; - emit settingsSetupLoaderChanged(d->settingsSetupLoader); + d->setupLoader = settingsSetupLoader; + emit settingsSetupLoaderChanged(d->setupLoader); } void SettingsViewModel::onInit(const QVariantHash ¶ms) { + Q_ASSERT_X(d->setupLoader, Q_FUNC_INFO, "settingsSetupLoader must not be null"); + d->settings = params.value(paramSettings).value(); + if(!d->settings) + d->settings = new QSettings(this); + d->setupFile = params.value(paramSetupFile).toString(); + if(d->setupFile.isEmpty()) + d->setupFile = QStringLiteral(":/etc/settings.xml"); } diff --git a/src/mvvmsettingscore/settingsviewmodel.h b/src/mvvmsettingscore/settingsviewmodel.h index 28e7b9d..78a8e65 100644 --- a/src/mvvmsettingscore/settingsviewmodel.h +++ b/src/mvvmsettingscore/settingsviewmodel.h @@ -5,32 +5,44 @@ #include #include +#include #include "QtMvvmSettingsCore/qtmvvmsettingscore_global.h" -#include "QtMvvmSettingsCore/settingssetuploader.h" +#include "QtMvvmSettingsCore/settingssetup.h" namespace QtMvvm { class SettingsViewModelPrivate; -class SettingsViewModel : public ViewModel +class Q_MVVMSETTINGSCORE_EXPORT SettingsViewModel : public ViewModel //TODO create qml binding { Q_OBJECT Q_PROPERTY(bool canRestoreDefaults READ canRestoreDefaults CONSTANT) + Q_PROPERTY(QtMvvm::MessageConfig restoreConfig READ restoreConfig CONSTANT) Q_PROPERTY(QtMvvm::ISettingsSetupLoader* settingsSetupLoader READ settingsSetupLoader WRITE setSettingsSetupLoader NOTIFY settingsSetupLoaderChanged) QTMVVM_INJECT(QtMvvm::ISettingsSetupLoader*, settingsSetupLoader) public: + static const QString paramSettings; + static const QString paramSetupFile; + + static QVariantHash showParams(QSettings *settings = nullptr, const QString &setupFile = {}); + Q_INVOKABLE explicit SettingsViewModel(QObject *parent = nullptr); ~SettingsViewModel(); - static void showSettings(ViewModel *parent); - static void showSettings(QSettings *settings = nullptr, const QString &setupFile = {}, ViewModel *parent = nullptr); - virtual bool canRestoreDefaults() const; + virtual QtMvvm::MessageConfig restoreConfig() const; + + ISettingsSetupLoader* settingsSetupLoader() const; + SettingsElements::SettingsSetup loadSetup(const QString &frontend) const; + + QSettings *settings() const; - QtMvvm::ISettingsSetupLoader* settingsSetupLoader() const; + Q_INVOKABLE virtual QVariant loadValue(const QString &key, const QVariant &defaultValue = {}) const; + Q_INVOKABLE virtual void saveValue(const QString &key, const QVariant &value); + Q_INVOKABLE virtual void resetValue(const QString &key); public Q_SLOTS: virtual void callAction(const QString &entryId); diff --git a/src/mvvmsettingscore/settingsviewmodel_p.h b/src/mvvmsettingscore/settingsviewmodel_p.h index 997f8fa..1ce28e6 100644 --- a/src/mvvmsettingscore/settingsviewmodel_p.h +++ b/src/mvvmsettingscore/settingsviewmodel_p.h @@ -9,7 +9,12 @@ namespace QtMvvm { class SettingsViewModelPrivate { public: - ISettingsSetupLoader *settingsSetupLoader = nullptr; + ISettingsSetupLoader *setupLoader = nullptr; + + QSettings *settings = nullptr; + QString setupFile; + + SettingsElements::SettingsSetup currentSetup; }; } diff --git a/src/mvvmsettingscore/translations/qtmvvsettingsmcore_de.ts b/src/mvvmsettingscore/translations/qtmvvsettingsmcore_de.ts new file mode 100644 index 0000000..a5c63e4 --- /dev/null +++ b/src/mvvmsettingscore/translations/qtmvvsettingsmcore_de.ts @@ -0,0 +1,30 @@ + + + + + QtMvvm::SettingsSetupLoader + + + General Settings + + + + + General + + + + + QtMvvm::SettingsViewModel + + + Restore Defaults? + + + + + All custom changes will be deleted and the defaults restored. <i>This cannot be undone!</i> + + + + diff --git a/src/mvvmsettingscore/translations/qtmvvsettingsmcore_template.ts b/src/mvvmsettingscore/translations/qtmvvsettingsmcore_template.ts new file mode 100644 index 0000000..c1a534f --- /dev/null +++ b/src/mvvmsettingscore/translations/qtmvvsettingsmcore_template.ts @@ -0,0 +1,30 @@ + + + + + QtMvvm::SettingsSetupLoader + + + General Settings + + + + + General + + + + + QtMvvm::SettingsViewModel + + + Restore Defaults? + + + + + All custom changes will be deleted and the defaults restored. <i>This cannot be undone!</i> + + + + diff --git a/src/mvvmwidgets/translations/qtmvvmwidgets_de.ts b/src/mvvmwidgets/translations/qtmvvmwidgets_de.ts index 52168fc..de529ef 100644 --- a/src/mvvmwidgets/translations/qtmvvmwidgets_de.ts +++ b/src/mvvmwidgets/translations/qtmvvmwidgets_de.ts @@ -4,12 +4,12 @@ QtMvvm::WidgetsPresenter - + About - + About &Qt diff --git a/src/mvvmwidgets/translations/qtmvvmwidgets_template.ts b/src/mvvmwidgets/translations/qtmvvmwidgets_template.ts index 5a49548..05ca5f3 100644 --- a/src/mvvmwidgets/translations/qtmvvmwidgets_template.ts +++ b/src/mvvmwidgets/translations/qtmvvmwidgets_template.ts @@ -4,12 +4,12 @@ QtMvvm::WidgetsPresenter - + About - + About &Qt diff --git a/sync.profile b/sync.profile index eefc99d..cc095dd 100644 --- a/sync.profile +++ b/sync.profile @@ -6,8 +6,9 @@ ); # Force generation of camel case headers for classes inside QtDataSync namespaces -$publicclassregexp = "QtMvvm::(?!__helpertypes).+"; +$publicclassregexp = "QtMvvm::(?!__helpertypes|SettingsElements).+"; %classnames = ( - "message.h" => "Messages" + "message.h" => "Messages", + "settingssetup.h" => "SettingsElements" );