chore(StatusListPicker): enable picker to work with incompatible models

This commit is contained in:
Patryk Osmaczko 2022-07-28 18:51:35 +02:00 committed by Michał Cieślak
parent 5e40f2e4d4
commit 444981723c
3 changed files with 48 additions and 15 deletions

View File

@ -74,6 +74,8 @@ Item {
*/
property var inputList: ListModel { }
readonly property StatusListPickerProxies proxy: StatusListPickerProxies {}
/*!
\qmlproperty string StatusListPicker::searchText
This property holds the search text the searcher input displays by default.
@ -160,7 +162,7 @@ Item {
// NOTE: ValueFilter would crash if source model does not contain given role
// FIXME: use ValueFilter when its fixed
filters: ExpressionFilter {
expression: model.selected
expression: root.proxy.selected(model)
}
}
@ -179,7 +181,7 @@ Item {
var item = selectedItems.get(i)
if(res != "")
res += ", "
res += formatSymbolShortNameText(item.symbol, item.shortName)
res += formatSymbolShortNameText(root.proxy.symbol(item), root.proxy.shortName(item))
}
return res
}
@ -200,8 +202,8 @@ Item {
Connections {
target: itemsSelectorHelper
function onSelectItem(key, checked) {
if (model.key === key) model.selected = checked
else if (!root.multiSelection && checked) model.selected = false
if (root.proxy.key(model) === key) root.proxy.setSelected(model, checked)
else if (!root.multiSelection && checked) root.proxy.setSelected(model, false)
}
}
}
@ -261,8 +263,8 @@ Item {
filters: ExpressionFilter {
expression: {
root.searchText // ensure expression is reevaluated when searchText changes
return model.name.toLowerCase().includes(root.searchText.toLowerCase()) ||
model.shortName.toLowerCase().includes(root.searchText.toLowerCase())
return root.proxy.name(model).toLowerCase().includes(root.searchText.toLowerCase()) ||
root.proxy.shortName(model).toLowerCase().includes(root.searchText.toLowerCase())
}
}
}
@ -302,24 +304,24 @@ Item {
height: content.itemHeight
color: mouseArea.containsMouse ? Theme.palette.baseColor4 : "transparent"
image: StatusImageSettings {
source: model.imageSource ? model.imageSource : ""
source: root.proxy.imageSource(model) ? root.proxy.imageSource(model) : ""
width: 15
height: 15
isIdenticon: false
}
name: model.name
shortName: model.shortName
name: root.proxy.name(model)
shortName: root.proxy.shortName(model)
selectorType: root.multiSelection ? StatusItemPicker.SelectorType.CheckBox : StatusItemPicker.SelectorType.RadioButton
selected: model.selected
selected: root.proxy.selected(model)
radioGroup: radioBtnGroup
onCheckedChanged: {
if (checked !== model.selected) {
itemsSelectorHelper.selectItem(model.key, checked)
if (checked !== root.proxy.selected(model)) {
itemsSelectorHelper.selectItem(root.proxy.key(model), checked)
}
// Used to notify selected property changes in the specific item picker.
itemPickerChanged(model.key, checked)
itemPickerChanged(root.proxy.key(model), checked)
}
MouseArea {

View File

@ -0,0 +1,30 @@
import QtQuick 2.14
/*!
Enables StatusListPicker to work with incompatible models.
\qml
StatusListPicker {
id: currencyPicker
inputList: ListModel {
ListElement { incompatibleA: 0 ... incomatibleZ: false }
ListElement { incompatibleA: 1 ... incomatibleZ: false }
ListElement { incompatibleA: 2 ... incomatibleZ: false }
}
proxy { // StatusListPickerProxies
key: (model) => model.incompatibleA
...
selected: (model) => model.incompatibleZ
}
}
\endqml
*/
QtObject {
property var key: (model) => model.key
property var name: (model) => model.name
property var shortName: (model) => model.shortName
property var symbol: (model) => model.symbol
property var imageSource: (model) => model.imageSource
property var category: (model) => model.category
property var selected: (model) => model.selected
property var setSelected: (model, val) => model.selected = val
}

View File

@ -174,5 +174,6 @@
<file>StatusQ/Popups/StatusSpellcheckingMenuItems.qml</file>
<file>StatusQ/Popups/StatusStackModal.qml</file>
<file>StatusQ/qmldir</file>
<file>StatusQ/Components/StatusListPickerProxies.qml</file>
</qresource>
</RCC>