Fix multi filtering, replace checkboxes by combobox and avoid hidding filter bar if no results.

This commit is contained in:
Julien Wadel 2021-11-18 17:18:36 +01:00
parent 79137f71c3
commit 655953675d
3 changed files with 68 additions and 55 deletions

View file

@ -101,18 +101,12 @@ bool TimelineProxyModel::filterAcceptsRow (int sourceRow, const QModelIndex &sou
return false; return false;
if( mFilterFlags > 0) { if( mFilterFlags > 0) {
if( !show && ( (mFilterFlags & TimelineFilter::SimpleChatRoom) == TimelineFilter::SimpleChatRoom)) show = !(( ( (mFilterFlags & TimelineFilter::SimpleChatRoom) == TimelineFilter::SimpleChatRoom) && isGroup)
show = !isGroup; || ( ( (mFilterFlags & TimelineFilter::SecureChatRoom) == TimelineFilter::SecureChatRoom) && !haveEncryption)
if( !show && ( (mFilterFlags & TimelineFilter::SecureChatRoom) == TimelineFilter::SecureChatRoom)) || ( ( (mFilterFlags & TimelineFilter::GroupChatRoom) == TimelineFilter::GroupChatRoom) && !isGroup)
show = haveEncryption; || ( ( (mFilterFlags & TimelineFilter::StandardChatRoom) == TimelineFilter::StandardChatRoom) && haveEncryption)
if( !show && ( (mFilterFlags & TimelineFilter::GroupChatRoom) == TimelineFilter::GroupChatRoom)) || ( ( (mFilterFlags & TimelineFilter::EphemeralChatRoom) == TimelineFilter::EphemeralChatRoom) && !isEphemeral)
show = isGroup; || ( ( (mFilterFlags & TimelineFilter::NoEphemeralChatRoom) == TimelineFilter::NoEphemeralChatRoom) && isEphemeral));
if( !show && ( (mFilterFlags & TimelineFilter::StandardChatRoom) == TimelineFilter::StandardChatRoom))
show = !haveEncryption;
if( !show && ( (mFilterFlags & TimelineFilter::EphemeralChatRoom) == TimelineFilter::EphemeralChatRoom))
show = isEphemeral;
if( !show && ( (mFilterFlags & TimelineFilter::NoEphemeralChatRoom) == TimelineFilter::NoEphemeralChatRoom))
show = !isEphemeral;
} }
if(show && mFilterText != ""){ if(show && mFilterText != ""){

View file

@ -15,17 +15,20 @@ Controls.ComboBox {
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
property var iconRole property var iconRole
property bool haveBorder: true
property bool haveMargin: true
property color backgroundColor: ComboBoxStyle.background.color.normal
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
background: Rectangle { background: Rectangle {
border { border {
color: ComboBoxStyle.background.border.color color: ComboBoxStyle.background.border.color
width: ComboBoxStyle.background.border.width width: comboBox.haveBorder ? ComboBoxStyle.background.border.width : 0
} }
color: comboBox.enabled color: comboBox.enabled
? ComboBoxStyle.background.color.normal ? comboBox.backgroundColor
: ComboBoxStyle.background.color.readOnly : ComboBoxStyle.background.color.readOnly
radius: ComboBoxStyle.background.radius radius: ComboBoxStyle.background.radius
@ -43,7 +46,7 @@ Controls.ComboBox {
RowLayout { RowLayout {
anchors { anchors {
fill: parent fill: parent
leftMargin: ComboBoxStyle.contentItem.leftMargin leftMargin: comboBox.haveMargin ? ComboBoxStyle.contentItem.leftMargin : 0
} }
spacing: ComboBoxStyle.contentItem.spacing spacing: ComboBoxStyle.contentItem.spacing

View file

@ -61,7 +61,7 @@ Rectangle {
Layout.preferredHeight: TimelineStyle.legend.height Layout.preferredHeight: TimelineStyle.legend.height
Layout.alignment: Qt.AlignTop Layout.alignment: Qt.AlignTop
color: showHistory.containsMouse?TimelineStyle.legend.backgroundColor.hovered:TimelineStyle.legend.backgroundColor.normal color: showHistory.containsMouse?TimelineStyle.legend.backgroundColor.hovered:TimelineStyle.legend.backgroundColor.normal
visible:view.count > 0 || timeline.isFilterVisible visible:view.count > 0 || timeline.isFilterVisible || timeline.model.filterFlags > 0
MouseArea{// no more showing history MouseArea{// no more showing history
id:showHistory id:showHistory
@ -160,60 +160,76 @@ Rectangle {
anchors.right:parent.right anchors.right:parent.right
spacing:-4 spacing:-4
function getFilterFlags(){ function getFilterFlags(){
return secureFilter.value | groupFilter.value | ephemeralsFilter.value; return secureFilter.model.get(secureFilter.currentIndex).value | groupFilter.model.get(groupFilter.currentIndex).value | ephemeralsFilter.model.get(ephemeralsFilter.currentIndex).value;
} }
function getNextState(checkState){ ComboBox {
if(checkState === Qt.Unchecked)
return Qt.Checked;
else if(checkState === Qt.Checked)
return Qt.PartiallyChecked;
else
return Qt.Unchecked;
}
CheckBoxText {
Layout.fillWidth: true Layout.fillWidth: true
id:secureFilter id:secureFilter
//: 'Secure rooms' : Filter item. Selecting it will show all secure rooms. currentIndex: 0
text: checkState === Qt.Checked ? qsTr('timelineFilterSecureRooms') : checkState === Qt.Unchecked textRole: "key"
model: ListModel {
ListElement {
//: 'All security levels' : Filter item. Selecting it will not do any filter on security level. //: 'All security levels' : Filter item. Selecting it will not do any filter on security level.
? qsTr('timelineFilterAllSecureLevelRooms') key: qsTr('timelineFilterAllSecureLevelRooms'); value: 0}
ListElement {
//: 'Standard rooms' : Filter item. Selecting it will show all simple rooms. //: 'Standard rooms' : Filter item. Selecting it will show all simple rooms.
: qsTr('timelineFilterStandardRooms') key: qsTr('timelineFilterStandardRooms'); value: TimelineProxyModel.StandardChatRoom}
property var value : (checkState==Qt.Checked?TimelineProxyModel.SecureChatRoom: (checkState == Qt.PartiallyChecked ?TimelineProxyModel.StandardChatRoom:0)) ListElement {
onValueChanged: timeline.model.filterFlags = filterChoices.getFilterFlags() //: 'Secure rooms' : Filter item. Selecting it will show all secure rooms.
tristate: true key: qsTr('timelineFilterSecureRooms'); value: TimelineProxyModel.SecureChatRoom}
}
haveBorder: false
haveMargin: false
backgroundColor: 'transparent'
visible: SettingsModel.secureChatEnabled && SettingsModel.standardChatEnabled visible: SettingsModel.secureChatEnabled && SettingsModel.standardChatEnabled
nextCheckState: function(){ return parent.getNextState(checkState)} onActivated: timeline.model.filterFlags = filterChoices.getFilterFlags()
} }
CheckBoxText { ComboBox {
Layout.fillWidth: true
id:groupFilter id:groupFilter
Layout.fillWidth: true currentIndex: 0
//: 'Chat groups' : Filter item. Selecting it will show all chat groups (with more than one participant). textRole: "key"
text: checkState === Qt.Checked ? qsTr('timelineFilterChatGroups') : checkState === Qt.Unchecked model: ListModel {
ListElement {
//: 'Any conversations' : Filter item. Selecting it will not do any filter on the type of conversations. //: 'Any conversations' : Filter item. Selecting it will not do any filter on the type of conversations.
? qsTr('timelineFilterAnyChatRooms') key: qsTr('timelineFilterAnyChatRooms'); value: 0}
ListElement {
//: 'Simple rooms' : Filter item. Selecting it will show all secure chat groups (with more than one participant). //: 'Simple rooms' : Filter item. Selecting it will show all secure chat groups (with more than one participant).
: qsTr('timelineFilterSimpleRooms') key: qsTr('timelineFilterSimpleRooms'); value: TimelineProxyModel.SimpleChatRoom}
property var value : (checkState==Qt.Checked?TimelineProxyModel.GroupChatRoom: (checkState == Qt.PartiallyChecked ?TimelineProxyModel.SimpleChatRoom:0)) ListElement {
onValueChanged: timeline.model.filterFlags = filterChoices.getFilterFlags() //: 'Chat groups' : Filter item. Selecting it will show all chat groups (with more than one participant).
tristate: true key: qsTr('timelineFilterChatGroups'); value: TimelineProxyModel.GroupChatRoom}
visible: SettingsModel.secureChatEnabled || SettingsModel.standardChatEnabled
nextCheckState: function(){ return parent.getNextState(checkState)}
} }
CheckBoxText {
id:ephemeralsFilter haveBorder: false
Layout.fillWidth: true haveMargin: false
//: 'Ephemerals' : Filter item. Selecting it will show all chat rooms where the ephemeral mode has been enabled. backgroundColor: 'transparent'
text: checkState === Qt.Checked ? qsTr('timelineFilterEphemerals') : checkState === Qt.Unchecked
//: 'Ephemerals on/off' : Filter item. Selecting it will not do any filter on ephemerals activation.
? qsTr('timelineFilterAnyEphemerals')
//: 'No Ephemerals' : Filter item. Selecting it will hide all chat rooms where the ephemeral mode has been enabled.
: qsTr('timelineFilterNoEphemerals')
property var value : (checkState==Qt.Checked?TimelineProxyModel.EphemeralChatRoom: (checkState == Qt.PartiallyChecked ?TimelineProxyModel.NoEphemeralChatRoom:0))
visible: SettingsModel.secureChatEnabled || SettingsModel.standardChatEnabled visible: SettingsModel.secureChatEnabled || SettingsModel.standardChatEnabled
onValueChanged: timeline.model.filterFlags = filterChoices.getFilterFlags() onActivated: timeline.model.filterFlags = filterChoices.getFilterFlags()
tristate: true }
nextCheckState: function(){ return parent.getNextState(checkState)} ComboBox {
Layout.fillWidth: true
id:ephemeralsFilter
currentIndex: 0
textRole: "key"
model: ListModel {
ListElement {
//: 'Ephemerals on/off' : Filter item. Selecting it will not do any filter on ephemerals activation.
key: qsTr('timelineFilterAnyEphemerals'); value: 0}
ListElement {
//: 'No Ephemerals' : Filter item. Selecting it will hide all chat rooms where the ephemeral mode has been enabled.
key: qsTr('timelineFilterNoEphemerals'); value: TimelineProxyModel.NoEphemeralChatRoom}
ListElement {
//: 'Ephemerals' : Filter item. Selecting it will show all chat rooms where the ephemeral mode has been enabled.
key: qsTr('timelineFilterEphemerals'); value: TimelineProxyModel.EphemeralChatRoom}
}
haveBorder: false
haveMargin: false
backgroundColor: 'transparent'
visible: SettingsModel.secureChatEnabled || SettingsModel.standardChatEnabled
onActivated: timeline.model.filterFlags = filterChoices.getFilterFlags()
} }
} }
} }