Improve spaces support

This commit is contained in:
Tobias Fella
2023-05-09 08:11:47 +00:00
parent 30c7d86045
commit 11343e6bdf
10 changed files with 490 additions and 134 deletions

View File

@@ -7,6 +7,7 @@
#include "neochatconfig.h"
#include "neochatroom.h"
#include "roommanager.h"
#include "spacehierarchycache.h"
#include "user.h"
#include <QDebug>
@@ -65,6 +66,9 @@ RoomListModel::RoomListModel(QObject *parent)
qGuiApp->setBadgeNumber(m_notificationCount);
#endif // QT_VERSION_CHECK(6, 6, 0)
});
connect(&SpaceHierarchyCache::instance(), &SpaceHierarchyCache::spaceHierarchyChanged, this, [this]() {
Q_EMIT dataChanged(index(0, 0), index(rowCount(), 0), {IsChildSpaceRole});
});
}
RoomListModel::~RoomListModel() = default;
@@ -412,6 +416,9 @@ QVariant RoomListModel::data(const QModelIndex &index, int role) const
if (role == IsSpaceRole) {
return room->isSpace();
}
if (role == IsChildSpaceRole) {
return SpaceHierarchyCache::instance().isChildSpace(room->id());
}
return QVariant();
}
@@ -447,6 +454,7 @@ QHash<int, QByteArray> RoomListModel::roleNames() const
roles[SubtitleTextRole] = "subtitleText";
roles[IsSpaceRole] = "isSpace";
roles[IdRole] = "id";
roles[IsChildSpaceRole] = "isChildSpace";
return roles;
}

View File

@@ -76,6 +76,7 @@ public:
AvatarImageRole, /**< The room avatar as an image. */
IdRole, /**< The room matrix ID. */
IsSpaceRole, /**< Whether the room is a space. */
IsChildSpaceRole, /**< Whether this space is a child of a different space. */
};
Q_ENUM(EventRoles)

View File

@@ -11,13 +11,24 @@ SortFilterSpaceListModel::SortFilterSpaceListModel(QObject *parent)
setSortRole(RoomListModel::IdRole);
sort(0);
invalidateFilter();
connect(this, &QAbstractProxyModel::sourceModelChanged, this, [this]() {
connect(sourceModel(), &QAbstractListModel::dataChanged, this, [this](const QModelIndex &, const QModelIndex &, QVector<int> roles) {
if (roles.contains(RoomListModel::IsChildSpaceRole)) {
invalidate();
}
countChanged();
});
invalidate();
Q_EMIT countChanged();
});
}
bool SortFilterSpaceListModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
{
Q_UNUSED(source_parent);
return sourceModel()->data(sourceModel()->index(source_row, 0), RoomListModel::IsSpaceRole).toBool()
&& sourceModel()->data(sourceModel()->index(source_row, 0), RoomListModel::JoinStateRole).toString() != "upgraded";
&& sourceModel()->data(sourceModel()->index(source_row, 0), RoomListModel::JoinStateRole).toString() != "upgraded"
&& !sourceModel()->data(sourceModel()->index(source_row, 0), RoomListModel::IsChildSpaceRole).toBool();
}
bool SortFilterSpaceListModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const

View File

@@ -16,10 +16,17 @@
class SortFilterSpaceListModel : public QSortFilterProxyModel
{
Q_OBJECT
/**
* @brief The number of spaces in the model.
*/
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
public:
explicit SortFilterSpaceListModel(QObject *parent = nullptr);
Q_SIGNALS:
void countChanged();
protected:
/**
* @brief Returns true if the value of source_left is less than source_right.