mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-10-31 18:00:48 +03:00
61 lines
1.6 KiB
C
61 lines
1.6 KiB
C
|
// SPDX-FileCopyrightText: 2021 Nheko Contributors
|
||
|
//
|
||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||
|
|
||
|
#pragma once
|
||
|
|
||
|
#include <QAbstractListModel>
|
||
|
#include <QHash>
|
||
|
#include <QString>
|
||
|
#include <QStringList>
|
||
|
|
||
|
#include <mtx/responses/sync.hpp>
|
||
|
|
||
|
class CommunitiesModel : public QAbstractListModel
|
||
|
{
|
||
|
Q_OBJECT
|
||
|
Q_PROPERTY(QString currentTagId READ currentTagId WRITE setCurrentTagId NOTIFY
|
||
|
currentTagIdChanged RESET resetCurrentTagId)
|
||
|
Q_PROPERTY(QStringList tags READ tags NOTIFY tagsChanged)
|
||
|
|
||
|
public:
|
||
|
enum Roles
|
||
|
{
|
||
|
AvatarUrl = Qt::UserRole,
|
||
|
DisplayName,
|
||
|
Tooltip,
|
||
|
ChildrenHidden,
|
||
|
Id,
|
||
|
};
|
||
|
|
||
|
CommunitiesModel(QObject *parent = nullptr);
|
||
|
QHash<int, QByteArray> roleNames() const override;
|
||
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override
|
||
|
{
|
||
|
(void)parent;
|
||
|
return 1 + tags_.size();
|
||
|
}
|
||
|
QVariant data(const QModelIndex &index, int role) const override;
|
||
|
|
||
|
public slots:
|
||
|
void initializeSidebar();
|
||
|
void sync(const mtx::responses::Rooms &rooms);
|
||
|
void clear();
|
||
|
QString currentTagId() const { return currentTagId_; }
|
||
|
void setCurrentTagId(QString tagId);
|
||
|
void resetCurrentTagId()
|
||
|
{
|
||
|
currentTagId_.clear();
|
||
|
emit currentTagIdChanged();
|
||
|
}
|
||
|
QStringList tags() const { return tags_; }
|
||
|
|
||
|
signals:
|
||
|
void currentTagIdChanged();
|
||
|
void tagsChanged();
|
||
|
|
||
|
private:
|
||
|
QStringList tags_;
|
||
|
QString currentTagId_;
|
||
|
};
|