Stefan 691de11211 fix(Wallet) network selection and unify network implementations
Major changes:

- Don't allow empty network selection. End up using the nim model
  directly instead because of individual row changes issues
  encountered with nim models
- Made the clone model a generic implementation to be used in other
places where we need to clone a model: ReceiveModal,
AddEditSavedAddressPopup
- Use cloned model as alternative to NetworksExtraStoreProxy in
  ReceiveModal
- Added tristate support to our generic checkbox control
- UX improvements as per design
- Fix save address tests naming and zero address issue
- Various fixes

Notes:
- Failed to make NetworkSelectPopup follow ground-truth: show partially
  checked as user intention until the network is selected in the
  source model. Got stuck on nim models not being stable models and
  report wrong entry change when reset. Tried sorting and only updating
  changes without reset but it didn't work.
- Moved grouped property SingleSelectionInfo to its own file from
  an inline component after finding out that it fails to load on Linux
  with error "Cannot assign to property of unknown type: "*".".
  It works on MacOS as expected

Closes: #10119
2023-04-20 19:34:24 +02:00

55 lines
1.8 KiB
QML

import QtQuick 2.15
/// Helper item to clone a model and alter its data without affecting the original model
/// \beware this is not a proxy model. It clones the initial state
/// and every time the instance changes and doesn't adapt when the data
/// in the source model \c allNetworksModel changes
/// \beware use it with small models and in temporary views (e.g. popups)
/// \note requires `rowData` to be implemented in the model
/// \note tried to use SortFilterProxyModel with but it complicates implementation too much
ListModel {
id: root
required property var sourceModel
/// Roles to clone
required property var roles
/// Roles to override or add of the form { role: "roleName", transform: function(modelData) { return newValue } }
property var rolesOverride: []
Component.onCompleted: cloneModel(sourceModel)
onSourceModelChanged: cloneModel(sourceModel)
function rowData(index, roleName) {
return get(index)[roleName]
}
function findIndexForRole(roleName, value) {
for (let i = 0; i < count; i++) {
if(get(i)[roleName] === value) {
return i
}
}
return -1
}
function cloneModel(model) {
clear()
if (!model) {
console.warn("Missing valid data model to clone. The CloneModel is useless")
return
}
for (let i = 0; i < model.count; i++) {
const clonedItem = new Object()
for (var propName of roles) {
clonedItem[propName] = model.rowData(i, propName)
}
for (var newProp of rolesOverride) {
clonedItem[newProp.role] = newProp.transform(clonedItem)
}
append(clonedItem)
}
}
}