feat: SortFilterProxyModel
This commit is contained in:
parent
3b7b346c1b
commit
fd4e0de3f3
|
@ -6,6 +6,7 @@ import QtQuick.Layouts 1.13
|
|||
import QtQml.Models 2.13
|
||||
import QtGraphicalEffects 1.13
|
||||
import QtQuick.Dialogs 1.3
|
||||
import SortFilterProxyModel 0.2
|
||||
import "../../../../shared"
|
||||
import "../../../../shared/status"
|
||||
import "../../../../imports"
|
||||
|
@ -276,26 +277,9 @@ ScrollView {
|
|||
}
|
||||
|
||||
|
||||
model: messageListDelegate
|
||||
model: messageProxyModel
|
||||
section.property: "sectionIdentifier"
|
||||
section.criteria: ViewSection.FullString
|
||||
}
|
||||
|
||||
MessageDialog {
|
||||
id: sendingMsgFailedPopup
|
||||
standardButtons: StandardButton.Ok
|
||||
//% "Failed to send message."
|
||||
text: qsTrId("failed-to-send-message-")
|
||||
icon: StandardIcon.Critical
|
||||
}
|
||||
|
||||
DelegateModelGeneralized {
|
||||
id: messageListDelegate
|
||||
lessThan: [
|
||||
function(left, right) { return left.clock > right.clock }
|
||||
]
|
||||
|
||||
model: messageList
|
||||
|
||||
delegate: Message {
|
||||
id: msgDelegate
|
||||
|
@ -327,24 +311,35 @@ ScrollView {
|
|||
pinnedBy: model.pinnedBy
|
||||
gapFrom: model.gapFrom
|
||||
gapTo: model.gapTo
|
||||
prevMessageIndex: {
|
||||
// This is used in order to have access to the previous message and determine the timestamp
|
||||
// we can't rely on the index because the sequence of messages is not ordered on the nim side
|
||||
if (msgDelegate.DelegateModel.itemsIndex < messageListDelegate.items.count - 1) {
|
||||
return messageListDelegate.items.get(msgDelegate.DelegateModel.itemsIndex + 1).model.index
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
nextMessageIndex: {
|
||||
if (msgDelegate.DelegateModel.itemsIndex <= 1) {
|
||||
return -1
|
||||
}
|
||||
return messageListDelegate.items.get(msgDelegate.DelegateModel.itemsIndex - 1).model.index
|
||||
}
|
||||
|
||||
// This is used in order to have access to the previous message and determine the timestamp
|
||||
// we can't rely on the index because the sequence of messages is not ordered on the nim side
|
||||
prevMessageIndex: msgDelegate.DelegateModel.itemsIndex < messageProxyModel.count - 1 ? msgDelegate.DelegateModel.itemsIndex + 1 : -1;
|
||||
prevMsgTimestamp: prevMessageIndex > -1 ? messageProxyModel.get(prevMessageIndex).timestamp : ""
|
||||
nextMessageIndex: msgDelegate.DelegateModel.itemsIndex <= 1 ? -1 : msgDelegate.DelegateModel.itemsIndex - 1;
|
||||
nextMsgTimestamp: nextMessageIndex > -1 ? messageProxyModel.get(nextMessageIndex).timestamp : ""
|
||||
scrollToBottom: chatLogView.scrollToBottom
|
||||
timeout: model.timeout
|
||||
}
|
||||
}
|
||||
|
||||
MessageDialog {
|
||||
id: sendingMsgFailedPopup
|
||||
standardButtons: StandardButton.Ok
|
||||
//% "Failed to send message."
|
||||
text: qsTrId("failed-to-send-message-")
|
||||
icon: StandardIcon.Critical
|
||||
}
|
||||
|
||||
SortFilterProxyModel {
|
||||
id: messageProxyModel
|
||||
sourceModel: messageList
|
||||
sorters: ExpressionSorter {
|
||||
expression: {
|
||||
return modelLeft.clock > modelRight.clock;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*##^##
|
||||
|
|
|
@ -66,8 +66,8 @@ Item {
|
|||
property string authorCurrentMsg: "authorCurrentMsg"
|
||||
property string authorPrevMsg: "authorPrevMsg"
|
||||
|
||||
property string prevMsgTimestamp: chatsModel.messageList.getMessageData(prevMessageIndex, "timestamp")
|
||||
property string nextMsgTimestamp: chatsModel.messageList.getMessageData(nextMessageIndex, "timestamp")
|
||||
property string prevMsgTimestamp: ""
|
||||
property string nextMsgTimestamp: ""
|
||||
|
||||
property bool shouldRepeatHeader: ((parseInt(timestamp, 10) - parseInt(prevMsgTimestamp, 10)) / 60 / 1000) > Constants.repeatHeaderInterval
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ import QtQuick.Controls 2.3
|
|||
import QtQuick.Layouts 1.3
|
||||
import QtQml.Models 2.3
|
||||
import QtGraphicalEffects 1.13
|
||||
import SortFilterProxyModel 0.2
|
||||
import "../../../../imports"
|
||||
import "../../../../shared"
|
||||
import "../../../../shared/status"
|
||||
|
@ -106,7 +107,7 @@ ModalPopup {
|
|||
|
||||
ListView {
|
||||
anchors.fill: parent
|
||||
model: communitiesDelegateModel
|
||||
model: communitiesProxyModel
|
||||
spacing: 4
|
||||
clip: true
|
||||
id: communitiesList
|
||||
|
@ -125,27 +126,8 @@ ModalPopup {
|
|||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
DelegateModelGeneralized {
|
||||
id: communitiesDelegateModel
|
||||
lessThan: [
|
||||
function(left, right) {
|
||||
return left.name.toLowerCase() < right.name.toLowerCase()
|
||||
}
|
||||
]
|
||||
|
||||
model: chatsModel.communities.list
|
||||
delegate: Item {
|
||||
// TODO add the search for the name and category once they exist
|
||||
visible: {
|
||||
if (!searchBox.text) {
|
||||
return true
|
||||
}
|
||||
const lowerCaseSearchStr = searchBox.text.toLowerCase()
|
||||
return name.toLowerCase().includes(lowerCaseSearchStr) || description.toLowerCase().includes(lowerCaseSearchStr)
|
||||
}
|
||||
height: visible ? communityImage.height + Style.current.padding : 0
|
||||
height: communityImage.height + Style.current.padding
|
||||
width: parent.width
|
||||
|
||||
Loader {
|
||||
|
@ -220,6 +202,28 @@ ModalPopup {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
SortFilterProxyModel {
|
||||
id: communitiesProxyModel
|
||||
sourceModel: chatsModel.communities.list
|
||||
sorters: StringSorter {
|
||||
roleName: "name"
|
||||
caseSensitivity: Qt.CaseInsensitive
|
||||
}
|
||||
filters: AnyOf {
|
||||
// TODO add the search for the category once it exist
|
||||
RegExpFilter {
|
||||
roleName: "name"
|
||||
pattern: searchBox.text
|
||||
caseSensitivity: Qt.CaseInsensitive
|
||||
}
|
||||
RegExpFilter {
|
||||
roleName: "description"
|
||||
pattern: searchBox.text
|
||||
caseSensitivity: Qt.CaseInsensitive
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
footer: StatusButton {
|
||||
|
|
|
@ -24,7 +24,6 @@ Item {
|
|||
}
|
||||
|
||||
property string filterCategory: ""
|
||||
property string searchStr: ""
|
||||
property bool isCompact: appSettings.useCompactMode
|
||||
property int contentType: 1
|
||||
property bool muted: false
|
||||
|
@ -43,7 +42,7 @@ Item {
|
|||
property string profileImage: realChatType === Constants.chatTypeOneToOne ? appMain.getProfileImage(chatId) || "" : ""
|
||||
|
||||
// Hide the box if it is filtered out
|
||||
property bool isVisible: categoryId === filterCategory && (searchStr === "" || name.includes(searchStr))
|
||||
property bool isVisible: categoryId === filterCategory
|
||||
|
||||
id: wrapper
|
||||
anchors.right: parent.right
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import QtQuick 2.13
|
||||
import QtQuick.Controls 2.13
|
||||
import QtQuick.Layouts 1.13
|
||||
import SortFilterProxyModel 0.2
|
||||
import "../../../../shared"
|
||||
import "../../../../imports"
|
||||
import "../components"
|
||||
|
@ -19,6 +20,18 @@ Item {
|
|||
id: timer
|
||||
}
|
||||
|
||||
SortFilterProxyModel {
|
||||
id: channelProxyModel
|
||||
sourceModel: channelListContent.channelModel
|
||||
filters: [
|
||||
RegExpFilter {
|
||||
roleName: "name"
|
||||
pattern: channelListContent.searchStr
|
||||
caseSensitivity: Qt.CaseInsensitive
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
ListView {
|
||||
id: chatGroupsListView
|
||||
spacing: 0
|
||||
|
@ -28,7 +41,7 @@ Item {
|
|||
anchors.right: parent.right
|
||||
anchors.left: parent.left
|
||||
interactive: false
|
||||
model: channelListContent.channelModel
|
||||
model: channelProxyModel
|
||||
delegate: Channel {
|
||||
name: model.name
|
||||
muted: model.muted
|
||||
|
@ -39,7 +52,6 @@ Item {
|
|||
unviewedMessagesCount: model.unviewedMessagesCount
|
||||
hasMentions: model.hasMentions
|
||||
contentType: model.contentType
|
||||
searchStr: channelListContent.searchStr
|
||||
categoryId: model.categoryId
|
||||
filterCategory: channelListContent.categoryId
|
||||
chatId: model.id
|
||||
|
|
|
@ -3,6 +3,7 @@ import QtQuick.Controls 2.13
|
|||
import QtGraphicalEffects 1.13
|
||||
import QtQml.Models 2.13
|
||||
import QtQuick.Layouts 1.13
|
||||
import SortFilterProxyModel 0.2
|
||||
import "../../../imports"
|
||||
import "../../../shared"
|
||||
import "../../../shared/status"
|
||||
|
@ -110,18 +111,9 @@ ScrollView {
|
|||
flickDeceleration: 10000
|
||||
interactive: false
|
||||
|
||||
model: messageListDelegate
|
||||
model: messageProxyModel
|
||||
section.property: "sectionIdentifier"
|
||||
section.criteria: ViewSection.FullString
|
||||
}
|
||||
|
||||
DelegateModelGeneralized {
|
||||
id: messageListDelegate
|
||||
lessThan: [
|
||||
function(left, right) { return left.clock > right.clock }
|
||||
]
|
||||
|
||||
model: chatsModel.messageList
|
||||
|
||||
delegate: Message {
|
||||
id: msgDelegate
|
||||
|
@ -145,16 +137,26 @@ ScrollView {
|
|||
messageId: model.messageId
|
||||
emojiReactions: model.emojiReactions
|
||||
isStatusUpdate: true
|
||||
prevMessageIndex: {
|
||||
// This is used in order to have access to the previous message and determine the timestamp
|
||||
// we can't rely on the index because the sequence of messages is not ordered on the nim side
|
||||
if(msgDelegate.DelegateModel.itemsIndex > 0){
|
||||
return messageListDelegate.items.get(msgDelegate.DelegateModel.itemsIndex - 1).model.index
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
// This is used in order to have access to the previous message and determine the timestamp
|
||||
// we can't rely on the index because the sequence of messages is not ordered on the nim side
|
||||
prevMessageIndex: msgDelegate.DelegateModel.itemsIndex < messageProxyModel.count - 1 ? msgDelegate.DelegateModel.itemsIndex + 1 : -1;
|
||||
prevMsgTimestamp: prevMessageIndex > -1 ? messageProxyModel.get(prevMessageIndex).timestamp : ""
|
||||
nextMessageIndex: msgDelegate.DelegateModel.itemsIndex <= 1 ? -1 : msgDelegate.DelegateModel.itemsIndex - 1;
|
||||
nextMsgTimestamp: nextMessageIndex > -1 ? messageProxyModel.get(nextMessageIndex).timestamp : ""
|
||||
|
||||
timeout: model.timeout
|
||||
}
|
||||
}
|
||||
|
||||
SortFilterProxyModel {
|
||||
id: messageProxyModel
|
||||
sourceModel: chatsModel.messageList
|
||||
sorters: ExpressionSorter {
|
||||
expression: {
|
||||
return modelLeft.clock > modelRight.clock;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import QtQuick 2.13
|
||||
import QtQuick.Controls 2.13
|
||||
import QtQuick.Layouts 1.13
|
||||
import SortFilterProxyModel 0.2
|
||||
import "../imports"
|
||||
import "./status"
|
||||
// TODO move Contact into shared to get rid of that import
|
||||
|
@ -24,6 +25,13 @@ Item {
|
|||
}
|
||||
|
||||
height: Math.min(contactListView.contentHeight, (expanded ? 320 : 192))
|
||||
|
||||
SortFilterProxyModel {
|
||||
id: contactListProxyModel
|
||||
sourceModel: profileModel.contacts.list
|
||||
sorters: StringSorter { roleName: "name" }
|
||||
}
|
||||
|
||||
ScrollView {
|
||||
anchors.fill: parent
|
||||
|
||||
|
@ -35,7 +43,7 @@ Item {
|
|||
spacing: 0
|
||||
clip: true
|
||||
id: contactListView
|
||||
model: profileModel.contacts.list
|
||||
model: contactListProxyModel
|
||||
delegate: Contact {
|
||||
showCheckbox: root.showCheckbox
|
||||
isChecked: root.pubKeys.indexOf(model.pubKey) > -1
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit eaa394d711f757b859030349aeaf41a10e1bad2b
|
||||
Subproject commit 46ede2811b082d9478d21c679fec275147810bd1
|
Loading…
Reference in New Issue