Don't show inactive rooms in the list
This commit is contained in:
@@ -21,9 +21,6 @@ Kirigami.ScrollablePage {
|
||||
|
||||
property var roomListModel
|
||||
property var enteredRoom
|
||||
property var searchText: ""
|
||||
|
||||
onSearchTextChanged: sortFilterRoomListModel.setFilterText(searchText)
|
||||
|
||||
signal enterRoom(var room)
|
||||
signal leaveRoom(var room)
|
||||
@@ -35,7 +32,7 @@ Kirigami.ScrollablePage {
|
||||
Layout.bottomMargin: Kirigami.Units.smallSpacing
|
||||
Layout.fillHeight: true
|
||||
Layout.fillWidth: true
|
||||
onTextChanged: page.searchText = text
|
||||
onTextChanged: sortFilterRoomListModel.filterText = text
|
||||
}
|
||||
|
||||
ListView {
|
||||
|
||||
@@ -11,9 +11,11 @@
|
||||
SortFilterRoomListModel::SortFilterRoomListModel(QObject *parent)
|
||||
: QSortFilterProxyModel(parent)
|
||||
{
|
||||
setFilterRole(RoomListModel::NameRole);
|
||||
setFilterCaseSensitivity(Qt::CaseInsensitive);
|
||||
sort(0);
|
||||
invalidateFilter();
|
||||
connect(this, &SortFilterRoomListModel::filterTextChanged, this, [this]() {
|
||||
invalidateFilter();
|
||||
});
|
||||
}
|
||||
|
||||
void SortFilterRoomListModel::setRoomSortOrder(SortFilterRoomListModel::RoomSortOrder sortOrder)
|
||||
@@ -42,5 +44,18 @@ bool SortFilterRoomListModel::lessThan(const QModelIndex &source_left, const QMo
|
||||
|
||||
void SortFilterRoomListModel::setFilterText(const QString &text)
|
||||
{
|
||||
setFilterFixedString(text);
|
||||
m_filterText = text;
|
||||
Q_EMIT filterTextChanged();
|
||||
}
|
||||
|
||||
QString SortFilterRoomListModel::filterText() const
|
||||
{
|
||||
return m_filterText;
|
||||
}
|
||||
|
||||
|
||||
bool SortFilterRoomListModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const
|
||||
{
|
||||
Q_UNUSED(source_parent);
|
||||
return sourceModel()->data(sourceModel()->index(source_row, 0), RoomListModel::NameRole).toString().contains(m_filterText, Qt::CaseInsensitive) && sourceModel()->data(sourceModel()->index(source_row, 0)).toString() != "upgraded";
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ class SortFilterRoomListModel : public QSortFilterProxyModel
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(RoomSortOrder roomSortOrder READ roomSortOrder WRITE setRoomSortOrder NOTIFY roomSortOrderChanged)
|
||||
Q_PROPERTY(QString filterText READ filterText READ filterText WRITE setFilterText NOTIFY filterTextChanged)
|
||||
|
||||
public:
|
||||
enum RoomSortOrder {
|
||||
@@ -27,13 +28,19 @@ public:
|
||||
void setRoomSortOrder(RoomSortOrder sortOrder);
|
||||
RoomSortOrder roomSortOrder() const;
|
||||
|
||||
Q_INVOKABLE void setFilterText(const QString &text);
|
||||
void setFilterText(const QString &text);
|
||||
QString filterText() const;
|
||||
|
||||
bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const override;
|
||||
|
||||
protected:
|
||||
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
|
||||
|
||||
Q_SIGNALS:
|
||||
void roomSortOrderChanged();
|
||||
void filterTextChanged();
|
||||
|
||||
private:
|
||||
RoomSortOrder m_sortOrder;
|
||||
QString m_filterText;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user