chore(InDropdown): Adapt to flattened model for channels

Closes: #9591
This commit is contained in:
Michał Cieślak 2023-02-27 12:38:05 +01:00 committed by Michał
parent bb2e03bd88
commit 702d355e89
3 changed files with 122 additions and 63 deletions

View File

@ -2,66 +2,84 @@ import QtQuick 2.14
ListModel {
ListElement {
itemId: 0
itemId: "1"
isCategory: false
categoryId: ""
name: "welcome"
isCategory: false
emoji: ""
color: ""
colorId: 1
icon: ""
}
ListElement {
itemId: 1
itemId: "2"
isCategory: false
categoryId: ""
name: "announcements"
isCategory: false
emoji: ""
color: ""
colorId: 1
icon: ""
}
ListElement {
name: "Discussion"
itemId: "0"
isCategory: true
subItems: [
ListElement {
itemId: 2
name: "general"
icon: ""
emoji: "👋"
},
ListElement {
itemId: 3
name: "help"
icon: ""
color: ""
colorId: 1
emoji: "⚽"
}
]
categoryId: "1"
name: "discussion"
emoji: ""
color: ""
colorId: 1
}
ListElement {
name: "Support"
isCategory: true
subItems: [
ListElement {
itemId: 4
name: "faq"
icon: ""
color: ""
colorId: 5
},
ListElement {
itemId: 5
name: "report-scam"
icon: ""
color: ""
colorId: 4
}
]
itemId: "3"
isCategory: false
categoryId: "1"
name: "general"
emoji: "👋"
color: ""
colorId: 1
}
ListElement {
name: "Empty"
itemId: "4"
isCategory: false
categoryId: "1"
name: "help"
emoji: "⚽"
color: ""
colorId: 1
}
ListElement {
itemId: "0"
isCategory: true
subItems: []
categoryId: "2"
name: "support"
emoji: ""
color: ""
colorId: 1
}
ListElement {
itemId: "5"
isCategory: false
categoryId: "2"
name: "faq"
emoji: ""
color: ""
colorId: 5
}
ListElement {
itemId: "6"
isCategory: false
categoryId: "2"
name: "report-scam"
emoji: ""
color: ""
colorId: 4
}
ListElement {
itemId: "0"
isCategory: true
categoryId: "3"
name: "faq"
emoji: ""
color: ""
colorId: 5
}
}

View File

@ -20,7 +20,7 @@ StatusListItem {
asset.isLetterIdenticon: true
asset.letterSize: 12
asset.isImage: model.icon.includes("data")
asset.isImage: asset.name.includes("data")
asset.width: 32
asset.height: 32

View File

@ -188,22 +188,44 @@ StatusDropdown {
sourceModel: root.model
filters: AnyOf {
ValueFilter {
roleName: "categoryId"
value: ""
}
ValueFilter {
roleName: "isCategory"
value: true
}
}
sorters: [
RoleSorter { roleName: "isCategory" },
RoleSorter { roleName: "position" }
RoleSorter {
roleName: "categoryPosition"
priority: 2 // Higher number === higher priority
},
RoleSorter {
roleName: "position"
priority: 1
}
]
}
ColumnLayout {
id: column
Layout.fillWidth: true
spacing: 0
readonly property var topModel: model
readonly property alias checkBox: loader.item
property int checkedCount: 0
readonly property bool isCategory: model.isCategory
readonly property string categoryId: model.categoryId
Layout.fillWidth: true
spacing: 0
visible: {
if (!model.isCategory)
if (!isCategory)
return d.search(model.name, searcher.text)
|| checkBox.checked
@ -224,8 +246,8 @@ StatusDropdown {
Layout.fillWidth: true
Layout.preferredHeight: d.itemStandardHeight
Layout.topMargin: model.isCategory ? d.defaultVMargin : 0
sourceComponent: model.isCategory
Layout.topMargin: isCategory ? d.defaultVMargin : 0
sourceComponent: isCategory
? communityCategoryDelegate
: communityDelegate
@ -236,7 +258,6 @@ StatusDropdown {
const checkBox = loader.item.checkBox
checkBox.checked = false
checkBox.onToggled()
}
}
@ -248,7 +269,7 @@ StatusDropdown {
title: "#" + model.name
asset.name: model.icon
asset.name: model.icon ?? ""
asset.emoji: d.resolveEmoji(model.emoji)
asset.color: d.resolveColor(model.color,
model.colorId)
@ -283,7 +304,7 @@ StatusDropdown {
title: model.name
checkState: {
if (checkedCount === model.subItems.count)
if (checkedCount === subItems.count)
return Qt.Checked
else if (checkedCount === 0)
return Qt.Unchecked
@ -301,12 +322,31 @@ StatusDropdown {
}
}
SortFilterProxyModel {
id: subItems
sourceModel: isCategory ? root.model : null
filters: AllOf {
ValueFilter {
roleName: "categoryId"
value: column.categoryId
}
ValueFilter {
roleName: "isCategory"
value: false
}
}
sorters: RoleSorter {
roleName: "position"
}
}
Repeater {
id: subItemsRepeater
model: SortFilterProxyModel {
sourceModel: topModel.isCategory ? topModel.subItems : null
sorters: RoleSorter { roleName: "position" }
}
model: subItems
function setAll(checkState) {
const subItemsCount = count
@ -319,15 +359,16 @@ StatusDropdown {
CommunityListItem {
id: communitySubItem
readonly property bool show:
d.search(model.name, searcher.text) || checked
Layout.fillWidth: true
readonly property bool show: d.search(model.name, searcher.text)
|| checked
visible: show
title: "#" + model.name
asset.name: model.icon
asset.name: model.icon ?? ""
asset.emoji: d.resolveEmoji(model.emoji)
asset.color: d.resolveColor(model.color,
model.colorId)