Changeset View
Changeset View
Standalone View
Standalone View
src/core/model/accountschannelsmodel.h
Show All 24 Lines | |||||
25 | 25 | | |||
26 | #include "libruqolacore_export.h" | 26 | #include "libruqolacore_export.h" | ||
27 | 27 | | |||
28 | class RocketChatAccount; | 28 | class RocketChatAccount; | ||
29 | class RoomFilterProxyModel; | 29 | class RoomFilterProxyModel; | ||
30 | 30 | | |||
31 | class LIBRUQOLACORE_EXPORT AccountsChannelsModel : public QAbstractItemModel | 31 | class LIBRUQOLACORE_EXPORT AccountsChannelsModel : public QAbstractItemModel | ||
32 | { | 32 | { | ||
33 | Q_OBJECT | ||||
33 | public: | 34 | public: | ||
34 | explicit AccountsChannelsModel(QObject *parent = nullptr); | 35 | explicit AccountsChannelsModel(QObject *parent = nullptr); | ||
35 | 36 | | |||
37 | void setFilterString(const QString &filter); | ||||
38 | bool isFiltered() const; | ||||
39 | | ||||
36 | QModelIndex index(int row, int column, const QModelIndex &parent = {}) const override; | 40 | QModelIndex index(int row, int column, const QModelIndex &parent = {}) const override; | ||
37 | QModelIndex parent(const QModelIndex &child) const override; | 41 | QModelIndex parent(const QModelIndex &child) const override; | ||
38 | int rowCount(const QModelIndex &parent = {}) const override; | 42 | int rowCount(const QModelIndex &parent = {}) const override; | ||
39 | int columnCount(const QModelIndex &parent = {}) const override; | 43 | int columnCount(const QModelIndex &parent = {}) const override; | ||
40 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; | 44 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; | ||
41 | 45 | | |||
46 | QModelIndex findRoomById(const QString &roomId) const; | ||||
47 | QModelIndex findRoomByName(const QString &roomName) const; | ||||
48 | QModelIndex findRoomByRole(int role, const QVariant &value) const; | ||||
49 | | ||||
50 | QString accountForIndex(const QModelIndex &index) const; | ||||
51 | | ||||
52 | Q_SIGNALS: | ||||
53 | void modelChanged(); | ||||
54 | | ||||
42 | private: | 55 | private: | ||
43 | QModelIndex modelRoot(QAbstractItemModel *model) const; | 56 | QModelIndex modelRoot(QAbstractItemModel *model) const; | ||
44 | QAbstractItemModel *rootModel(const QModelIndex &root) const; | 57 | QAbstractItemModel *rootModel(const QModelIndex &root) const; | ||
45 | void mapModelToIndex(QAbstractItemModel *model, const std::function<QModelIndex()> &root); | 58 | void mapModelToIndex(QAbstractItemModel *model, const std::function<QModelIndex()> &root); | ||
46 | void unproxyModel(QAbstractItemModel *model); | 59 | void unproxyModel(QAbstractItemModel *model); | ||
47 | 60 | | |||
48 | struct ProxyIndex | 61 | struct ProxyIndex | ||
49 | { | 62 | { | ||
50 | QAbstractItemModel *model; | 63 | QAbstractItemModel *model; | ||
51 | std::function<QModelIndex()> root; | 64 | std::function<QModelIndex()> root; | ||
52 | }; | 65 | }; | ||
53 | QVector<ProxyIndex> mProxied; | 66 | QVector<ProxyIndex> mProxied; | ||
67 | bool mFiltered = false; | ||||
68 | | ||||
69 | enum Visit | ||||
70 | { | ||||
71 | Continue, | ||||
72 | Abort | ||||
73 | }; | ||||
74 | template<class T, class Fn> | ||||
75 | void visitProxied(const Fn &fn) const | ||||
76 | { | ||||
77 | for (const auto &proxied: mProxied) | ||||
78 | { | ||||
79 | if (auto model = qobject_cast<T*>(proxied.model)) | ||||
80 | if (fn(model, proxied.root()) == Abort) | ||||
81 | return; | ||||
82 | } | ||||
83 | } | ||||
54 | }; | 84 | }; | ||
55 | 85 | | |||
56 | #endif // ACCOUNTSCHANNELSMODEL_H | 86 | #endif // ACCOUNTSCHANNELSMODEL_H |