Browse Source

fixed reset and font edits

pull/2/head
Skycoder42 7 years ago
parent
commit
8fad373233
  1. 8
      examples/mvvmcore/SampleCore/settings.xml
  2. 25
      src/imports/mvvmquick/settingsuibuilder.cpp
  3. 2
      src/imports/mvvmquick/settingsuibuilder.h
  4. 15
      src/mvvmquick/FontEdit.qml
  5. 5
      src/mvvmwidgets/fontcombobox.cpp

8
examples/mvvmcore/SampleCore/settings.xml

@ -99,5 +99,13 @@
<Element type="string">Text 2</Element> <Element type="string">Text 2</Element>
</Property> </Property>
</Entry> </Entry>
<Entry key="prop9"
type="url"
title="Enter a &amp;website">
<Property key="placeholderText" type="string">https://example.org/test</Property>
</Entry>
<Entry key="prop10"
type="QFont"
title="Choose a &amp;font" />
</Category> </Category>
</SettingsConfig> </SettingsConfig>

25
src/imports/mvvmquick/settingsuibuilder.cpp

@ -22,7 +22,8 @@ SettingsUiBuilder::SettingsUiBuilder(QObject *parent) :
_sectionFilterModel(new MultiFilterProxyModel(this)), _sectionFilterModel(new MultiFilterProxyModel(this)),
_sectionModel(new SettingsSectionModel(this)), _sectionModel(new SettingsSectionModel(this)),
_entryFilterModel(new MultiFilterProxyModel(this)), _entryFilterModel(new MultiFilterProxyModel(this)),
_entryModel(new SettingsEntryModel(this)) _entryModel(new SettingsEntryModel(this)),
_currentSetup()
{ {
_sectionFilterModel->setSourceModel(_sectionModel); _sectionFilterModel->setSourceModel(_sectionModel);
_sectionFilterModel->addFilterRoles(SettingsSectionModel::FilterRoles); _sectionFilterModel->addFilterRoles(SettingsSectionModel::FilterRoles);
@ -82,6 +83,14 @@ void SettingsUiBuilder::restoreDefaults()
connect(result, &MessageResult::dialogDone, this, [this](MessageConfig::StandardButton btn) { connect(result, &MessageResult::dialogDone, this, [this](MessageConfig::StandardButton btn) {
if(btn != MessageConfig::Yes) if(btn != MessageConfig::Yes)
return; 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(); emit closeSettings();
}, Qt::QueuedConnection); }, Qt::QueuedConnection);
} }
@ -107,19 +116,19 @@ void SettingsUiBuilder::startBuildUi()
if(!_buildView || !_viewModel) if(!_buildView || !_viewModel)
return; return;
auto setup = _viewModel->loadSetup(QStringLiteral("quick")); _currentSetup = _viewModel->loadSetup(QStringLiteral("quick"));
//search/restore properties //search/restore properties
_allowSearch = setup.allowSearch; _allowSearch = _currentSetup.allowSearch;
emit allowSearchChanged(_allowSearch); emit allowSearchChanged(_allowSearch);
_allowRestore = setup.allowRestore; _allowRestore = _currentSetup.allowRestore;
emit allowRestoreChanged(_allowRestore); emit allowRestoreChanged(_allowRestore);
if(setup.categories.size() == 1 && if(_currentSetup.categories.size() == 1 &&
setup.categories.first().sections.size() == 1) _currentSetup.categories.first().sections.size() == 1)
loadSection(setup.categories.first().sections.first()); loadSection(_currentSetup.categories.first().sections.first());
else { else {
_sectionModel->setup(setup); _sectionModel->setup(_currentSetup);
emit presentOverview(_sectionFilterModel, _sectionModel->hasSections()); emit presentOverview(_sectionFilterModel, _sectionModel->hasSections());
} }
} }

2
src/imports/mvvmquick/settingsuibuilder.h

@ -64,6 +64,8 @@ private:
SettingsSectionModel *_sectionModel; SettingsSectionModel *_sectionModel;
MultiFilterProxyModel *_entryFilterModel; MultiFilterProxyModel *_entryFilterModel;
SettingsEntryModel *_entryModel; SettingsEntryModel *_entryModel;
SettingsElements::Setup _currentSetup;
}; };
} }

15
src/mvvmquick/FontEdit.qml

@ -1,10 +1,21 @@
import QtQuick 2.10 import QtQuick 2.10
import QtQuick.Controls 2.3 import QtQuick.Controls 2.3
ComboBox { Item {
id: _edit id: _edit
property alias inputValue: _edit.currentText implicitWidth: _listEdit.implicitWidth
implicitHeight: _listEdit.implicitHeight
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() model: Qt.fontFamilies()
editable: false editable: false
} }
}

5
src/mvvmwidgets/fontcombobox.cpp

@ -4,6 +4,7 @@ using namespace QtMvvm;
FontComboBox::FontComboBox(QWidget *parent) : FontComboBox::FontComboBox(QWidget *parent) :
QFontComboBox(parent) QFontComboBox(parent)
{ {
connect(this, &FontComboBox::currentFontChangedImp, connect(this, &FontComboBox::currentFontChanged,
this, &FontComboBox::currentFontChanged); this, &FontComboBox::currentFontChangedImp);
setCurrentFont(font());
} }

Loading…
Cancel
Save