diff options
Diffstat (limited to 'lib/accountregistry.h')
-rw-r--r-- | lib/accountregistry.h | 49 |
1 files changed, 31 insertions, 18 deletions
diff --git a/lib/accountregistry.h b/lib/accountregistry.h index f7a864df..2f6dffdf 100644 --- a/lib/accountregistry.h +++ b/lib/accountregistry.h @@ -6,42 +6,55 @@ #include "quotient_export.h" -#include <QtCore/QObject> -#include <QtCore/QList> #include <QtCore/QAbstractListModel> namespace Quotient { class Connection; -class QUOTIENT_API AccountRegistry : public QAbstractListModel { +class QUOTIENT_API AccountRegistry : public QAbstractListModel, + private QVector<Connection*> { Q_OBJECT public: + using const_iterator = QVector::const_iterator; + using const_reference = QVector::const_reference; + enum EventRoles { - ConnectionRole = Qt::UserRole + 1, + AccountRole = Qt::UserRole + 1, + ConnectionRole = AccountRole }; - static AccountRegistry &instance() { - static AccountRegistry _instance; - return _instance; - } + [[deprecated("Use Accounts variable instead")]] // + static AccountRegistry& instance(); + + // Expose most of QVector's const-API but only provide add() and drop() + // for changing it. In theory other changing operations could be supported + // too; but then boilerplate begin/end*() calls has to be tucked into each + // and this class gives no guarantees on the order of entries, so why care. - const QVector<Connection*> accounts() const; + const QVector<Connection*>& accounts() const { return *this; } void add(Connection* a); void drop(Connection* a); + const_iterator begin() const { return QVector::begin(); } + const_iterator end() const { return QVector::end(); } + const_reference front() const { return QVector::front(); } + const_reference back() const { return QVector::back(); } bool isLoggedIn(const QString& userId) const; - bool isEmpty() const; - int count() const; - bool contains(Connection*) const; Connection* get(const QString& userId); - [[nodiscard]] QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; - [[nodiscard]] int rowCount(const QModelIndex &parent = QModelIndex()) const override; + using QVector::isEmpty, QVector::empty; + using QVector::size, QVector::count, QVector::capacity; + using QVector::cbegin, QVector::cend, QVector::contains; + + // QAbstractItemModel interface implementation + [[nodiscard]] QVariant data(const QModelIndex& index, + int role) const override; + [[nodiscard]] int rowCount( + const QModelIndex& parent = QModelIndex()) const override; [[nodiscard]] QHash<int, QByteArray> roleNames() const override; +}; -private: - AccountRegistry(); +inline QUOTIENT_API AccountRegistry Accounts {}; - QVector<Connection *> m_accounts; -}; +inline AccountRegistry& AccountRegistry::instance() { return Accounts; } } |