status-desktop/ui/app/AppLayouts/Communities/views/ChannelsSelectionModel.qml
Alex Jbanca 942482fe99 performance(ChannelsSelectionModel): Use LeftJoinModel for ChannelsSelectionModel.qml
Motivation:
ChannelsSelectionModel.qml is freezing the app when used with a live channel that's being edited because on each channel change the selection model is re-created.

The fix for this is to use the LeftJoinModel to unify the channels selection (a light model containing only keys) and the full channels model containing the channels data. On top of this, the SortFilterProxyModel is added to decorate the model with the roles expected in the UI. Another improvement is by replacing the ExpressionRole with the FastExpressionRole.
2024-01-19 15:07:19 +02:00

63 lines
1.7 KiB
QML

import QtQml 2.15
import SortFilterProxyModel 0.2
import StatusQ.Core.Utils 0.1
import StatusQ.Core.Theme 0.1
import StatusQ 0.1
import utils 1.0
SortFilterProxyModel {
id: root
property var selectedChannels
property var allChannels
sourceModel: LeftJoinModel {
readonly property var channelsModelAlignedKey: SortFilterProxyModel {
sourceModel: root.allChannels
proxyRoles: [
FastExpressionRole {
name: "key"
expression: model.itemId ?? ""
expectedRoles: ["itemId"]
}
]
}
leftModel: root.selectedChannels
rightModel: channelsModelAlignedKey
joinRole: "key"
}
proxyRoles: [
FastExpressionRole {
name: "text"
expression: "#" + model.name
expectedRoles: ["name"]
},
FastExpressionRole {
name: "imageSource"
expression: model.icon
expectedRoles: ["icon"]
},
FastExpressionRole {
function getColor(color, colorId) {
return !!color ? color
: Theme.palette.userCustomizationColors[colorId]
}
name: "color"
expression: getColor(model.color, model.colorId)
expectedRoles: ["color", "colorId"]
},
FastExpressionRole {
name: "operator"
// Direct call for singleton enum is not handled properly by SortFilterProxyModel.
readonly property int none: OperatorsUtils.Operators.None
expression: none
expectedRoles: []
}
]
}