Repair room filter, performance improvements
Chnaging delegate heights is a terrible idea that leads to graphic bugs. Handle filtering (both room and accounts) and collapsing from a function that sets the JsonListModel source.
This commit is contained in:
@@ -1,16 +1,54 @@
|
||||
import QtQuick 2.12
|
||||
import QtQuick.Layouts 1.12
|
||||
import "../Base"
|
||||
import "../utils.js" as Utils
|
||||
|
||||
HListView {
|
||||
id: accountRoomList
|
||||
|
||||
// property bool forceExpand: paneToolBar.roomFilter && roomList.model.count
|
||||
property bool forceExpand: false
|
||||
|
||||
readonly property var originSource: window.sidePaneModelSource
|
||||
readonly property var collapseAccounts: window.uiState.collapseAccounts
|
||||
readonly property string filter: paneToolBar.roomFilter
|
||||
|
||||
onOriginSourceChanged: Qt.callLater(filterSource)
|
||||
onFilterChanged: Qt.callLater(filterSource)
|
||||
onCollapseAccountsChanged: Qt.callLater(filterSource)
|
||||
|
||||
|
||||
function filterSource() {
|
||||
let show = []
|
||||
|
||||
for (let i = 0; i < window.sidePaneModelSource.length; i++) {
|
||||
let item = window.sidePaneModelSource[i]
|
||||
|
||||
if (item.type == "Account" ||
|
||||
(filter ?
|
||||
Utils.filterMatches(filter, item.data.filter_string) :
|
||||
! window.uiState.collapseAccounts[item.user_id]))
|
||||
{
|
||||
if (filter && show.length && item.type == "Account" &&
|
||||
show[show.length - 1].type == "Account" &&
|
||||
! Utils.filterMatches(filter, item.data.filter_string)) {
|
||||
// If current and previous items are both accounts,
|
||||
// that means the previous account had no matching rooms.
|
||||
show.pop()
|
||||
}
|
||||
|
||||
show.push(item)
|
||||
}
|
||||
}
|
||||
|
||||
// If last item is an account, that account had no matching rooms.
|
||||
if (show.length && show[show.length - 1].type == "Account") show.pop()
|
||||
|
||||
model.source = show
|
||||
}
|
||||
|
||||
|
||||
model: HListModel {
|
||||
keyField: "id"
|
||||
source: window.sidePaneModelSource
|
||||
source: originSource
|
||||
}
|
||||
|
||||
delegate: Loader {
|
||||
|
@@ -4,17 +4,22 @@ import "../Base"
|
||||
|
||||
HInteractiveRectangle {
|
||||
id: accountDelegate
|
||||
height: row.height
|
||||
color: theme.sidePane.account.background
|
||||
checked: isCurrent
|
||||
height: row.height
|
||||
|
||||
|
||||
checked: accountDelegate.isCurrent
|
||||
readonly property bool isCurrent:
|
||||
window.uiState.page == "Pages/EditAccount/EditAccount.qml" &&
|
||||
window.uiState.pageProperties.userId == model.data.user_id
|
||||
|
||||
readonly property bool forceExpand:
|
||||
Boolean(accountRoomList.filter)
|
||||
|
||||
readonly property bool collapsed:
|
||||
! accountRoomList.forceExpand &&
|
||||
window.uiState.collapseAccounts[model.data.user_id] || false
|
||||
! forceExpand &&
|
||||
accountRoomList.collapseAccounts[model.data.user_id] || false
|
||||
|
||||
|
||||
function toggleCollapse() {
|
||||
window.uiState.collapseAccounts[model.data.user_id] = ! collapsed
|
||||
@@ -27,6 +32,7 @@ HInteractiveRectangle {
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
TapHandler { onTapped: accountDelegate.activate() }
|
||||
|
||||
HRowLayout {
|
||||
@@ -74,7 +80,7 @@ HInteractiveRectangle {
|
||||
|
||||
visible: opacity > 0
|
||||
opacity:
|
||||
accountRoomList.forceExpand ? 0 :
|
||||
accountDelegate.forceExpand ? 0 :
|
||||
collapsed ? theme.sidePane.account.collapsedOpacity + 0.2 :
|
||||
1
|
||||
Behavior on opacity { HNumberAnimation {} }
|
||||
|
@@ -6,29 +6,30 @@ import "../utils.js" as Utils
|
||||
HInteractiveRectangle {
|
||||
id: roomDelegate
|
||||
color: theme.sidePane.room.background
|
||||
|
||||
readonly property bool collapsed:
|
||||
! accountRoomList.forceExpand &&
|
||||
window.uiState.collapseAccounts[model.user_id] || false
|
||||
|
||||
visible: height > 0
|
||||
height: collapsed ? 0 : rowLayout.height
|
||||
Behavior on height { HNumberAnimation {} }
|
||||
|
||||
height: rowLayout.height
|
||||
opacity: model.data.left ? theme.sidePane.room.leftRoomOpacity : 1
|
||||
checked: isCurrent
|
||||
|
||||
|
||||
Behavior on opacity { HNumberAnimation {} }
|
||||
|
||||
checked: isCurrent
|
||||
|
||||
readonly property bool forceExpand:
|
||||
Boolean(accountRoomList.filter)
|
||||
|
||||
readonly property bool isCurrent:
|
||||
window.uiState.page == "Chat/Chat.qml" &&
|
||||
window.uiState.pageProperties.userId == model.user_id &&
|
||||
window.uiState.pageProperties.roomId == model.data.room_id
|
||||
|
||||
|
||||
function activate() {
|
||||
pageStack.showRoom(model.user_id, model.data.room_id)
|
||||
print(model.user_id, model.data.room_id)
|
||||
}
|
||||
|
||||
|
||||
TapHandler { onTapped: activate() }
|
||||
|
||||
HRowLayout {
|
||||
|
@@ -89,11 +89,13 @@ function filterMatches(filter, text) {
|
||||
|
||||
|
||||
function filterModelSource(source, filter_text, property="filter_string") {
|
||||
if (! filter_text) { return source }
|
||||
|
||||
if (! filter_text) return source
|
||||
let results = []
|
||||
for (let item of source) {
|
||||
if (filterMatches(filter_text, item[property])) { results.push(item) }
|
||||
|
||||
for (let i = 0; i < source.length; i++) {
|
||||
if (filterMatches(filter_text, source[i][property])) {
|
||||
results.push(item)
|
||||
}
|
||||
}
|
||||
return results
|
||||
}
|
||||
|
Reference in New Issue
Block a user