Refactor and clean up spaces
This commit is contained in:
@@ -42,16 +42,6 @@ Kirigami.ScrollablePage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Connections {
|
|
||||||
target: SpaceHierarchyCache
|
|
||||||
function onSpaceHierarchyChanged() {
|
|
||||||
if (spaceList.activeSpaceId !== '') {
|
|
||||||
sortFilterRoomListModel.activeSpaceRooms = SpaceHierarchyCache.getRoomListForSpace(spaceList.activeSpaceId, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
header: QQC2.Control {
|
header: QQC2.Control {
|
||||||
contentItem: QQC2.RoundButton {
|
contentItem: QQC2.RoundButton {
|
||||||
id: homeButton
|
id: homeButton
|
||||||
@@ -62,7 +52,7 @@ Kirigami.ScrollablePage {
|
|||||||
display: QQC2.AbstractButton.IconOnly
|
display: QQC2.AbstractButton.IconOnly
|
||||||
|
|
||||||
onClicked: {
|
onClicked: {
|
||||||
sortFilterRoomListModel.activeSpaceRooms = [];
|
sortFilterRoomListModel.activeSpaceId = "";
|
||||||
spaceList.activeSpaceId = '';
|
spaceList.activeSpaceId = '';
|
||||||
listView.positionViewAtIndex(0, ListView.Beginning);
|
listView.positionViewAtIndex(0, ListView.Beginning);
|
||||||
}
|
}
|
||||||
@@ -82,13 +72,10 @@ Kirigami.ScrollablePage {
|
|||||||
implicitHeight: ListView.view.headerItem.implicitHeight
|
implicitHeight: ListView.view.headerItem.implicitHeight
|
||||||
|
|
||||||
contentItem: Kirigami.Avatar {
|
contentItem: Kirigami.Avatar {
|
||||||
id: del
|
|
||||||
|
|
||||||
actions.main: Kirigami.Action {
|
actions.main: Kirigami.Action {
|
||||||
id: enterSpaceAction
|
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
spaceList.activeSpaceId = id;
|
spaceList.activeSpaceId = id;
|
||||||
sortFilterRoomListModel.activeSpaceRooms = SpaceHierarchyCache.getRoomListForSpace(id, true);
|
sortFilterRoomListModel.activeSpaceId = id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -178,7 +178,6 @@ int main(int argc, char *argv[])
|
|||||||
Login *login = new Login();
|
Login *login = new Login();
|
||||||
ChatBoxHelper chatBoxHelper;
|
ChatBoxHelper chatBoxHelper;
|
||||||
UrlHelper urlHelper;
|
UrlHelper urlHelper;
|
||||||
SpaceHierarchyCache spaceHierarchyCache;
|
|
||||||
|
|
||||||
#ifdef HAVE_COLORSCHEME
|
#ifdef HAVE_COLORSCHEME
|
||||||
ColorSchemer colorScheme;
|
ColorSchemer colorScheme;
|
||||||
@@ -199,7 +198,7 @@ int main(int argc, char *argv[])
|
|||||||
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "EmojiModel", new EmojiModel(&app));
|
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "EmojiModel", new EmojiModel(&app));
|
||||||
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "CommandModel", new CommandModel(&app));
|
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "CommandModel", new CommandModel(&app));
|
||||||
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "AccountRegistry", &Quotient::AccountRegistry::instance());
|
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "AccountRegistry", &Quotient::AccountRegistry::instance());
|
||||||
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "SpaceHierarchyCache", &spaceHierarchyCache);
|
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "SpaceHierarchyCache", &SpaceHierarchyCache::instance());
|
||||||
qmlRegisterType<ActionsHandler>("org.kde.neochat", 1, 0, "ActionsHandler");
|
qmlRegisterType<ActionsHandler>("org.kde.neochat", 1, 0, "ActionsHandler");
|
||||||
qmlRegisterType<ChatBoxHelper>("org.kde.neochat", 1, 0, "ChatBoxHelper");
|
qmlRegisterType<ChatBoxHelper>("org.kde.neochat", 1, 0, "ChatBoxHelper");
|
||||||
qmlRegisterType<ChatDocumentHandler>("org.kde.neochat", 1, 0, "ChatDocumentHandler");
|
qmlRegisterType<ChatDocumentHandler>("org.kde.neochat", 1, 0, "ChatDocumentHandler");
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "sortfilterroomlistmodel.h"
|
#include "sortfilterroomlistmodel.h"
|
||||||
|
|
||||||
#include "roomlistmodel.h"
|
#include "roomlistmodel.h"
|
||||||
|
#include "spacehierarchycache.h"
|
||||||
|
|
||||||
SortFilterRoomListModel::SortFilterRoomListModel(QObject *parent)
|
SortFilterRoomListModel::SortFilterRoomListModel(QObject *parent)
|
||||||
: QSortFilterProxyModel(parent)
|
: QSortFilterProxyModel(parent)
|
||||||
@@ -81,18 +82,23 @@ bool SortFilterRoomListModel::filterAcceptsRow(int source_row, const QModelIndex
|
|||||||
&& 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::IsSpaceRole).toBool() == false;
|
&& sourceModel()->data(sourceModel()->index(source_row, 0), RoomListModel::IsSpaceRole).toBool() == false;
|
||||||
|
|
||||||
if (m_activeSpaceRooms.empty())
|
if (m_activeSpaceId.isEmpty()) {
|
||||||
return acceptRoom;
|
return acceptRoom;
|
||||||
else
|
} else {
|
||||||
return std::find(m_activeSpaceRooms.begin(),
|
const auto &rooms = SpaceHierarchyCache::instance().getRoomListForSpace(m_activeSpaceId, false);
|
||||||
m_activeSpaceRooms.end(),
|
return std::find(rooms.begin(), rooms.end(), sourceModel()->data(sourceModel()->index(source_row, 0), RoomListModel::IdRole).toString()) != rooms.end()
|
||||||
sourceModel()->data(sourceModel()->index(source_row, 0), RoomListModel::IdRole).toString())
|
|
||||||
!= m_activeSpaceRooms.end()
|
|
||||||
&& acceptRoom;
|
&& acceptRoom;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SortFilterRoomListModel::setActiveSpaceRooms(QVector<QString> activeSpaceRooms)
|
QString SortFilterRoomListModel::activeSpaceId() const
|
||||||
{
|
{
|
||||||
this->m_activeSpaceRooms = activeSpaceRooms;
|
return m_activeSpaceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SortFilterRoomListModel::setActiveSpaceId(const QString &spaceId)
|
||||||
|
{
|
||||||
|
m_activeSpaceId = spaceId;
|
||||||
|
Q_EMIT activeSpaceIdChanged();
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ class SortFilterRoomListModel : public QSortFilterProxyModel
|
|||||||
|
|
||||||
Q_PROPERTY(RoomSortOrder roomSortOrder READ roomSortOrder WRITE setRoomSortOrder NOTIFY roomSortOrderChanged)
|
Q_PROPERTY(RoomSortOrder roomSortOrder READ roomSortOrder WRITE setRoomSortOrder NOTIFY roomSortOrderChanged)
|
||||||
Q_PROPERTY(QString filterText READ filterText READ filterText WRITE setFilterText NOTIFY filterTextChanged)
|
Q_PROPERTY(QString filterText READ filterText READ filterText WRITE setFilterText NOTIFY filterTextChanged)
|
||||||
Q_PROPERTY(QVector<QString> activeSpaceRooms WRITE setActiveSpaceRooms)
|
Q_PROPERTY(QString activeSpaceId READ activeSpaceId WRITE setActiveSpaceId NOTIFY activeSpaceIdChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum RoomSortOrder {
|
enum RoomSortOrder {
|
||||||
@@ -31,7 +31,8 @@ public:
|
|||||||
|
|
||||||
[[nodiscard]] bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const override;
|
[[nodiscard]] bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const override;
|
||||||
|
|
||||||
Q_INVOKABLE void setActiveSpaceRooms(QVector<QString> activeSpaceRooms);
|
QString activeSpaceId() const;
|
||||||
|
void setActiveSpaceId(const QString &spaceId);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
[[nodiscard]] bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
|
[[nodiscard]] bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
|
||||||
@@ -39,9 +40,10 @@ protected:
|
|||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void roomSortOrderChanged();
|
void roomSortOrderChanged();
|
||||||
void filterTextChanged();
|
void filterTextChanged();
|
||||||
|
void activeSpaceIdChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
RoomSortOrder m_sortOrder = Categories;
|
RoomSortOrder m_sortOrder = Categories;
|
||||||
QString m_filterText;
|
QString m_filterText;
|
||||||
QVector<QString> m_activeSpaceRooms;
|
QString m_activeSpaceId;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ void SpaceHierarchyCache::populateSpaceHierarchy(const QString &spaceId)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector<QString> SpaceHierarchyCache::getRoomListForSpace(const QString &spaceId, bool updateCache)
|
QVector<QString> &SpaceHierarchyCache::getRoomListForSpace(const QString &spaceId, bool updateCache)
|
||||||
{
|
{
|
||||||
if (updateCache) {
|
if (updateCache) {
|
||||||
populateSpaceHierarchy(spaceId);
|
populateSpaceHierarchy(spaceId);
|
||||||
|
|||||||
@@ -13,14 +13,20 @@ class SpaceHierarchyCache : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit SpaceHierarchyCache(QObject *parent = nullptr);
|
static SpaceHierarchyCache &instance()
|
||||||
|
{
|
||||||
|
static SpaceHierarchyCache _instance;
|
||||||
|
return _instance;
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] Q_INVOKABLE QVector<QString> getRoomListForSpace(const QString &spaceId, bool updateCache);
|
[[nodiscard]] QVector<QString> &getRoomListForSpace(const QString &spaceId, bool updateCache);
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void spaceHierarchyChanged();
|
void spaceHierarchyChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
explicit SpaceHierarchyCache(QObject *parent = nullptr);
|
||||||
|
|
||||||
QVector<QString> m_activeSpaceRooms;
|
QVector<QString> m_activeSpaceRooms;
|
||||||
QHash<QString, QVector<QString>> m_spaceHierarchy;
|
QHash<QString, QVector<QString>> m_spaceHierarchy;
|
||||||
void cacheSpaceHierarchy();
|
void cacheSpaceHierarchy();
|
||||||
|
|||||||
Reference in New Issue
Block a user