From 8fad373233e44b9f89d89d568e37df2703ca5207 Mon Sep 17 00:00:00 2001 From: Skycoder42 Date: Tue, 27 Feb 2018 15:10:52 +0100 Subject: [PATCH] fixed reset and font edits --- examples/mvvmcore/SampleCore/settings.xml | 8 +++++++ src/imports/mvvmquick/settingsuibuilder.cpp | 25 ++++++++++++++------- src/imports/mvvmquick/settingsuibuilder.h | 2 ++ src/mvvmquick/FontEdit.qml | 19 ++++++++++++---- src/mvvmwidgets/fontcombobox.cpp | 5 +++-- 5 files changed, 45 insertions(+), 14 deletions(-) diff --git a/examples/mvvmcore/SampleCore/settings.xml b/examples/mvvmcore/SampleCore/settings.xml index 02dbc86..9c530f2 100644 --- a/examples/mvvmcore/SampleCore/settings.xml +++ b/examples/mvvmcore/SampleCore/settings.xml @@ -99,5 +99,13 @@ Text 2 + + https://example.org/test + + diff --git a/src/imports/mvvmquick/settingsuibuilder.cpp b/src/imports/mvvmquick/settingsuibuilder.cpp index f0073aa..ede4da8 100644 --- a/src/imports/mvvmquick/settingsuibuilder.cpp +++ b/src/imports/mvvmquick/settingsuibuilder.cpp @@ -22,7 +22,8 @@ SettingsUiBuilder::SettingsUiBuilder(QObject *parent) : _sectionFilterModel(new MultiFilterProxyModel(this)), _sectionModel(new SettingsSectionModel(this)), _entryFilterModel(new MultiFilterProxyModel(this)), - _entryModel(new SettingsEntryModel(this)) + _entryModel(new SettingsEntryModel(this)), + _currentSetup() { _sectionFilterModel->setSourceModel(_sectionModel); _sectionFilterModel->addFilterRoles(SettingsSectionModel::FilterRoles); @@ -82,6 +83,14 @@ void SettingsUiBuilder::restoreDefaults() connect(result, &MessageResult::dialogDone, this, [this](MessageConfig::StandardButton btn) { if(btn != MessageConfig::Yes) return; + for(auto category : qAsConst(_currentSetup.categories)) { + for(auto section : category.sections) { + for(auto group : section.groups) { + for(auto entry : group.entries) + _viewModel->resetValue(entry.key); + } + } + } emit closeSettings(); }, Qt::QueuedConnection); } @@ -107,19 +116,19 @@ void SettingsUiBuilder::startBuildUi() if(!_buildView || !_viewModel) return; - auto setup = _viewModel->loadSetup(QStringLiteral("quick")); + _currentSetup = _viewModel->loadSetup(QStringLiteral("quick")); //search/restore properties - _allowSearch = setup.allowSearch; + _allowSearch = _currentSetup.allowSearch; emit allowSearchChanged(_allowSearch); - _allowRestore = setup.allowRestore; + _allowRestore = _currentSetup.allowRestore; emit allowRestoreChanged(_allowRestore); - if(setup.categories.size() == 1 && - setup.categories.first().sections.size() == 1) - loadSection(setup.categories.first().sections.first()); + if(_currentSetup.categories.size() == 1 && + _currentSetup.categories.first().sections.size() == 1) + loadSection(_currentSetup.categories.first().sections.first()); else { - _sectionModel->setup(setup); + _sectionModel->setup(_currentSetup); emit presentOverview(_sectionFilterModel, _sectionModel->hasSections()); } } diff --git a/src/imports/mvvmquick/settingsuibuilder.h b/src/imports/mvvmquick/settingsuibuilder.h index 9c8c9df..f21c69d 100644 --- a/src/imports/mvvmquick/settingsuibuilder.h +++ b/src/imports/mvvmquick/settingsuibuilder.h @@ -64,6 +64,8 @@ private: SettingsSectionModel *_sectionModel; MultiFilterProxyModel *_entryFilterModel; SettingsEntryModel *_entryModel; + + SettingsElements::Setup _currentSetup; }; } diff --git a/src/mvvmquick/FontEdit.qml b/src/mvvmquick/FontEdit.qml index 9cccfe0..01781f8 100644 --- a/src/mvvmquick/FontEdit.qml +++ b/src/mvvmquick/FontEdit.qml @@ -1,10 +1,21 @@ import QtQuick 2.10 import QtQuick.Controls 2.3 -ComboBox { +Item { id: _edit - property alias inputValue: _edit.currentText + implicitWidth: _listEdit.implicitWidth + implicitHeight: _listEdit.implicitHeight - model: Qt.fontFamilies() - editable: false + property font inputValue: _listEdit.font + + ListEdit { + id: _listEdit + anchors.fill: parent + + inputValue: _edit.inputValue.family + onInputValueChanged: _edit.inputValue = Qt.font({family: inputValue}) + + model: Qt.fontFamilies() + editable: false + } } diff --git a/src/mvvmwidgets/fontcombobox.cpp b/src/mvvmwidgets/fontcombobox.cpp index 03437a3..2d53ed1 100644 --- a/src/mvvmwidgets/fontcombobox.cpp +++ b/src/mvvmwidgets/fontcombobox.cpp @@ -4,6 +4,7 @@ using namespace QtMvvm; FontComboBox::FontComboBox(QWidget *parent) : QFontComboBox(parent) { - connect(this, &FontComboBox::currentFontChangedImp, - this, &FontComboBox::currentFontChanged); + connect(this, &FontComboBox::currentFontChanged, + this, &FontComboBox::currentFontChangedImp); + setCurrentFont(font()); }