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),
_showDrawer(false)
{
QCoreApplication::setApplicationName(QStringLiteral("QtMvvmSample"));
QCoreApplication::setApplicationVersion(QStringLiteral(QTMVVMCORE_VERSION_STR));
QCoreApplication::setOrganizationName(QStringLiteral("Skycoder42"));
}

2
src/imports/mvvmquick/ListSection.qml

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

4
src/imports/mvvmquick/SectionListView.qml

@ -21,8 +21,8 @@ ListView {
onLoaded: {
if(loaderDelegate.item && typeof loaderDelegate.item.showInput !== "undefined") {
loaderDelegate.item.showInput.connect(function(key, title, type, props){
builder.showDialog(key, title, type, props);
loaderDelegate.item.showInput.connect(function(key, title, type, defaultValue, 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 {
id: _settingsView
property SettingsViewModel viewModel: null
property bool fullClose: false
function closeAction() {
return _settingsStack.closeAction();
return !fullClose && _settingsStack.closeAction();
}
header: ToolBar {
@ -219,6 +220,9 @@ Page {
model: model
}, 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: "title"; type: "string" }
Parameter { name: "type"; type: "string" }
Parameter { name: "defaultValue"; type: "QVariant" }
Parameter { name: "properties"; type: "QVariantMap" }
}
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())
return QVariant();
auto entry = _entries.value(index.row());
switch (role) {
case Qt::DisplayRole:
case TitleRole:
return _entries.value(index.row()).title;
return entry.title;
case KeyRole:
return _entries.value(index.row()).key;
return entry.key;
case TypeRole:
return QString::fromUtf8(_entries.value(index.row()).type);
return QString::fromUtf8(entry.type);
case ToolTipRole:
return _entries.value(index.row()).tooltip;
return entry.tooltip;
case DelegateUrlRole:
return _entries.value(index.row()).delegateUrl;
return entry.delegateUrl;
case SettingsValueRole:
return _viewModel->loadValue(_entries.value(index.row()).key);
return _viewModel->loadValue(entry.key, entry.defaultValue);
case PropertiesRole:
return _entries.value(index.row()).properties;
return entry.properties;
case GroupRole:
return _entries.value(index.row()).group.title;
return entry.group.title;
case SearchKeysRole:
return _entries.value(index.row()).searchKeys;
return entry.searchKeys;
default:
return QVariant();
}

4
src/imports/mvvmquick/settingsuibuilder.cpp

@ -61,7 +61,7 @@ void SettingsUiBuilder::loadSection(const SettingsElements::Section &section)
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"))
_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) {
if(value.isValid())
_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:
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 setFilterText(QString filterText);

2
src/mvvmquick/BoolDelegate.qml

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

71
src/mvvmquick/ListEdit.qml

@ -3,33 +3,58 @@ import QtQuick.Controls 2.3
ComboBox {
id: _edit
property alias inputValue: _edit.currentValue
property var inputValue
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 var _valueHelper: { return {}; }
property bool _skipNext: false
Component.onCompleted: {
Object.defineProperty(
_valueHelper,
"value",
{
get: function () {
var value = _edit.model[_edit.currentIndex].value;
if(typeof value !== "undefined")
return value;
else
return _edit.displayText;
},
set: function (value) {
var index = find(value); //TODO find VALUE, not text... somehow via the model?
if(index !== -1)
currentIndex = index;
else if(editable)
editText = value;
textRole: isExtended ? "name" : ""
onInputValueChanged: {
if(_skipNext) {
_skipNext = false;
return;
} else
_skipNext = true;
var found = false;
var i;
if(isExtended) {
for(i = 0; i < model.length; i++) {
if(model[i].value == inputValue) {
currentIndex = i;
found = true;
break;
}
}
} 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
signal showInput(string key, string title, string type, var properties);
signal showInput(string key, string title, string type, var defaultValue, var properties);
contentItem: ColumnLayout {
Label {
@ -27,5 +27,5 @@ ItemDelegate {
}
}
onClicked: showInput(key, title, type, properties)
onClicked: showInput(key, title, type, settingsValue, properties)
}

Loading…
Cancel
Save