Browse Source

fix listedit

pull/2/head
Skycoder42 7 years ago
parent
commit
12c64039f5
  1. 1
      examples/mvvmcore/SampleCore/samplecoreapp.cpp
  2. 2
      src/imports/mvvmquick/ListSection.qml
  3. 4
      src/imports/mvvmquick/SectionListView.qml
  4. 8
      src/imports/mvvmquick/SettingsView.qml
  5. 1
      src/imports/mvvmquick/plugins.qmltypes
  6. 19
      src/imports/mvvmquick/settingsentrymodel.cpp
  7. 4
      src/imports/mvvmquick/settingsuibuilder.cpp
  8. 2
      src/imports/mvvmquick/settingsuibuilder.h
  9. 2
      src/mvvmquick/BoolDelegate.qml
  10. 71
      src/mvvmquick/ListEdit.qml
  11. 4
      src/mvvmquick/MsgDelegate.qml

1
examples/mvvmcore/SampleCore/samplecoreapp.cpp

@ -9,6 +9,7 @@ SampleCoreApp::SampleCoreApp(QObject *parent) :
CoreApp(parent), CoreApp(parent),
_showDrawer(false) _showDrawer(false)
{ {
QCoreApplication::setApplicationName(QStringLiteral("QtMvvmSample"));
QCoreApplication::setApplicationVersion(QStringLiteral(QTMVVMCORE_VERSION_STR)); QCoreApplication::setApplicationVersion(QStringLiteral(QTMVVMCORE_VERSION_STR));
QCoreApplication::setOrganizationName(QStringLiteral("Skycoder42")); QCoreApplication::setOrganizationName(QStringLiteral("Skycoder42"));
} }

2
src/imports/mvvmquick/ListSection.qml

@ -1,5 +1,7 @@
import QtQuick 2.10 import QtQuick 2.10
import QtQuick.Controls 2.3 import QtQuick.Controls 2.3
import QtQuick.Controls.Material 2.3
import QtQuick.Controls.Universal 2.3
import de.skycoder42.QtMvvm.Quick 1.0 import de.skycoder42.QtMvvm.Quick 1.0
Label { Label {

4
src/imports/mvvmquick/SectionListView.qml

@ -21,8 +21,8 @@ ListView {
onLoaded: { onLoaded: {
if(loaderDelegate.item && typeof loaderDelegate.item.showInput !== "undefined") { if(loaderDelegate.item && typeof loaderDelegate.item.showInput !== "undefined") {
loaderDelegate.item.showInput.connect(function(key, title, type, props){ loaderDelegate.item.showInput.connect(function(key, title, type, defaultValue, props){
builder.showDialog(key, title, type, props); builder.showDialog(key, title, type, defaultValue, props);
}); });
} }
} }

8
src/imports/mvvmquick/SettingsView.qml

@ -8,9 +8,10 @@ import de.skycoder42.QtMvvm.Quick 1.0
Page { Page {
id: _settingsView id: _settingsView
property SettingsViewModel viewModel: null property SettingsViewModel viewModel: null
property bool fullClose: false
function closeAction() { function closeAction() {
return _settingsStack.closeAction(); return !fullClose && _settingsStack.closeAction();
} }
header: ToolBar { header: ToolBar {
@ -219,6 +220,9 @@ Page {
model: model model: model
}, Qt.Asynchronous) }, Qt.Asynchronous)
onCloseSettings: QuickPresenter.popView() onCloseSettings: {
_settingsView.fullClose = true;
QuickPresenter.popView();
}
} }
} }

1
src/imports/mvvmquick/plugins.qmltypes

@ -143,6 +143,7 @@ Module {
Parameter { name: "key"; type: "string" } Parameter { name: "key"; type: "string" }
Parameter { name: "title"; type: "string" } Parameter { name: "title"; type: "string" }
Parameter { name: "type"; type: "string" } Parameter { name: "type"; type: "string" }
Parameter { name: "defaultValue"; type: "QVariant" }
Parameter { name: "properties"; type: "QVariantMap" } Parameter { name: "properties"; type: "QVariantMap" }
} }
Method { name: "restoreDefaults" } Method { name: "restoreDefaults" }

19
src/imports/mvvmquick/settingsentrymodel.cpp

@ -47,26 +47,27 @@ QVariant SettingsEntryModel::data(const QModelIndex &index, int role) const
if (!index.isValid()) if (!index.isValid())
return QVariant(); return QVariant();
auto entry = _entries.value(index.row());
switch (role) { switch (role) {
case Qt::DisplayRole: case Qt::DisplayRole:
case TitleRole: case TitleRole:
return _entries.value(index.row()).title; return entry.title;
case KeyRole: case KeyRole:
return _entries.value(index.row()).key; return entry.key;
case TypeRole: case TypeRole:
return QString::fromUtf8(_entries.value(index.row()).type); return QString::fromUtf8(entry.type);
case ToolTipRole: case ToolTipRole:
return _entries.value(index.row()).tooltip; return entry.tooltip;
case DelegateUrlRole: case DelegateUrlRole:
return _entries.value(index.row()).delegateUrl; return entry.delegateUrl;
case SettingsValueRole: case SettingsValueRole:
return _viewModel->loadValue(_entries.value(index.row()).key); return _viewModel->loadValue(entry.key, entry.defaultValue);
case PropertiesRole: case PropertiesRole:
return _entries.value(index.row()).properties; return entry.properties;
case GroupRole: case GroupRole:
return _entries.value(index.row()).group.title; return entry.group.title;
case SearchKeysRole: case SearchKeysRole:
return _entries.value(index.row()).searchKeys; return entry.searchKeys;
default: default:
return QVariant(); return QVariant();
} }

4
src/imports/mvvmquick/settingsuibuilder.cpp

@ -61,7 +61,7 @@ void SettingsUiBuilder::loadSection(const SettingsElements::Section &section)
emit presentSection(_entryFilterModel); emit presentSection(_entryFilterModel);
} }
void SettingsUiBuilder::showDialog(const QString &key, const QString &title, const QString &type, const QVariantMap &properties) void SettingsUiBuilder::showDialog(const QString &key, const QString &title, const QString &type, const QVariant &defaultValue, const QVariantMap &properties)
{ {
if(type == QStringLiteral("action")) if(type == QStringLiteral("action"))
_viewModel->callAction(key, properties.value(QStringLiteral("args")).toMap()); _viewModel->callAction(key, properties.value(QStringLiteral("args")).toMap());
@ -69,7 +69,7 @@ void SettingsUiBuilder::showDialog(const QString &key, const QString &title, con
getInput(title + tr(":"), QString(), qUtf8Printable(type), this, [this, key](QVariant value) { getInput(title + tr(":"), QString(), qUtf8Printable(type), this, [this, key](QVariant value) {
if(value.isValid()) if(value.isValid())
_viewModel->saveValue(key, value); _viewModel->saveValue(key, value);
}, _viewModel->loadValue(key), properties); }, _viewModel->loadValue(key, defaultValue), properties);
} }
} }

2
src/imports/mvvmquick/settingsuibuilder.h

@ -33,7 +33,7 @@ public:
public Q_SLOTS: public Q_SLOTS:
void loadSection(const QtMvvm::SettingsElements::Section &section); void loadSection(const QtMvvm::SettingsElements::Section &section);
void showDialog(const QString &key, const QString &title, const QString &type, const QVariantMap &properties); void showDialog(const QString &key, const QString &title, const QString &type, const QVariant &defaultValue, const QVariantMap &properties);
void restoreDefaults(); void restoreDefaults();
void setFilterText(QString filterText); void setFilterText(QString filterText);

2
src/mvvmquick/BoolDelegate.qml

@ -7,7 +7,7 @@ CheckDelegate {
text: title text: title
Component.onCompleted: checked = settingsValue; Component.onCompleted: checked = settingsValue; //TODO buggy, use binding?
onCheckedChanged: settingsValue = checked; onCheckedChanged: settingsValue = checked;
contentItem: GridLayout { contentItem: GridLayout {

71
src/mvvmquick/ListEdit.qml

@ -3,33 +3,58 @@ import QtQuick.Controls 2.3
ComboBox { ComboBox {
id: _edit id: _edit
property alias inputValue: _edit.currentValue property var inputValue
property alias listElements: _edit.model property alias listElements: _edit.model
property var currentValue: _valueHelper ? _valueHelper.value : null readonly property bool isExtended: Boolean(model[0] && model[0].name)
textRole: "name" property bool _skipNext: false
property var _valueHelper: { return {}; }
Component.onCompleted: { textRole: isExtended ? "name" : ""
Object.defineProperty(
_valueHelper, onInputValueChanged: {
"value", if(_skipNext) {
{ _skipNext = false;
get: function () { return;
var value = _edit.model[_edit.currentIndex].value; } else
if(typeof value !== "undefined") _skipNext = true;
return value;
else var found = false;
return _edit.displayText; var i;
}, if(isExtended) {
set: function (value) { for(i = 0; i < model.length; i++) {
var index = find(value); //TODO find VALUE, not text... somehow via the model? if(model[i].value == inputValue) {
if(index !== -1) currentIndex = i;
currentIndex = index; found = true;
else if(editable) break;
editText = value; }
}
} else {
for(i = 0; i < model.length; i++) {
if(model[i] == inputValue) {
currentIndex = i;
found = true;
break;
} }
} }
); }
if(!found)
editText = inputValue;
}
onEditTextChanged: {
if(_skipNext) {
_skipNext = false;
return;
} else
_skipNext = true;
if(isExtended) {
var value = model[currentIndex].value;
if(typeof value !== "undefined")
inputValue = value;
else
inputValue = editText;
} else
inputValue = editText
} }
} }

4
src/mvvmquick/MsgDelegate.qml

@ -7,7 +7,7 @@ ItemDelegate {
text: title text: title
signal showInput(string key, string title, string type, var properties); signal showInput(string key, string title, string type, var defaultValue, var properties);
contentItem: ColumnLayout { contentItem: ColumnLayout {
Label { Label {
@ -27,5 +27,5 @@ ItemDelegate {
} }
} }
onClicked: showInput(key, title, type, properties) onClicked: showInput(key, title, type, settingsValue, properties)
} }

Loading…
Cancel
Save