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. 19
      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>
</Property>
</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>
</SettingsConfig>

25
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());
}
}

2
src/imports/mvvmquick/settingsuibuilder.h

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

19
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
}
}

5
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());
}

Loading…
Cancel
Save