aboutsummaryrefslogtreecommitdiff
path: root/lib/accountregistry.cpp
diff options
context:
space:
mode:
authorAlexey Rusakov <Kitsune-Ral@users.sf.net>2022-01-18 19:25:52 +0100
committerAlexey Rusakov <Kitsune-Ral@users.sf.net>2022-01-18 19:25:52 +0100
commit142fc5a21f541e2a7592119df075a543527195b9 (patch)
treef38cd3f38465a0cf8b38c198b202e624fe939ae1 /lib/accountregistry.cpp
parentecbff4c1a21ff4c0ab72141bc1a34ae189d33483 (diff)
parentbf82aeea369cacfc93a0e6d6d9feb01f1f2afdb2 (diff)
downloadlibquotient-142fc5a21f541e2a7592119df075a543527195b9.tar.gz
libquotient-142fc5a21f541e2a7592119df075a543527195b9.zip
Merge branch 'kitsune/cleanup2' into dev
Diffstat (limited to 'lib/accountregistry.cpp')
-rw-r--r--lib/accountregistry.cpp73
1 files changed, 21 insertions, 52 deletions
diff --git a/lib/accountregistry.cpp b/lib/accountregistry.cpp
index a292ed45..616b54b4 100644
--- a/lib/accountregistry.cpp
+++ b/lib/accountregistry.cpp
@@ -8,90 +8,59 @@
using namespace Quotient;
-void AccountRegistry::add(Connection* c)
+void AccountRegistry::add(Connection* a)
{
- if (m_accounts.contains(c))
+ if (contains(a))
return;
- beginInsertRows(QModelIndex(), m_accounts.size(), m_accounts.size());
- m_accounts += c;
+ beginInsertRows(QModelIndex(), size(), size());
+ push_back(a);
endInsertRows();
}
-void AccountRegistry::drop(Connection* c)
+void AccountRegistry::drop(Connection* a)
{
- beginRemoveRows(QModelIndex(), m_accounts.indexOf(c), m_accounts.indexOf(c));
- m_accounts.removeOne(c);
+ const auto idx = indexOf(a);
+ beginRemoveRows(QModelIndex(), idx, idx);
+ remove(idx);
endRemoveRows();
- Q_ASSERT(!m_accounts.contains(c));
+ Q_ASSERT(!contains(a));
}
bool AccountRegistry::isLoggedIn(const QString &userId) const
{
- return std::any_of(m_accounts.cbegin(), m_accounts.cend(),
- [&userId](Connection* a) { return a->userId() == userId; });
+ return std::any_of(cbegin(), cend(), [&userId](const Connection* a) {
+ return a->userId() == userId;
+ });
}
-bool AccountRegistry::contains(Connection *c) const
+QVariant AccountRegistry::data(const QModelIndex& index, int role) const
{
- return m_accounts.contains(c);
-}
-
-AccountRegistry::AccountRegistry() = default;
-
-QVariant AccountRegistry::data(const QModelIndex &index, int role) const
-{
- if (!index.isValid()) {
- return {};
- }
-
- if (index.row() >= m_accounts.count()) {
+ if (!index.isValid() || index.row() >= count())
return {};
- }
- auto account = m_accounts[index.row()];
-
- if (role == ConnectionRole) {
- return QVariant::fromValue(account);
- }
+ if (role == AccountRole)
+ return QVariant::fromValue(at(index.row()));
return {};
}
-int AccountRegistry::rowCount(const QModelIndex &parent) const
+int AccountRegistry::rowCount(const QModelIndex& parent) const
{
- if (parent.isValid()) {
- return 0;
- }
-
- return m_accounts.count();
+ return parent.isValid() ? 0 : count();
}
QHash<int, QByteArray> AccountRegistry::roleNames() const
{
- return {{ConnectionRole, "connection"}};
+ return { { AccountRole, "connection" } };
}
-bool AccountRegistry::isEmpty() const
-{
- return m_accounts.isEmpty();
-}
-int AccountRegistry::count() const
-{
- return m_accounts.count();
-}
-
-const QVector<Connection*> AccountRegistry::accounts() const
-{
- return m_accounts;
-}
Connection* AccountRegistry::get(const QString& userId)
{
- for (const auto &connection : m_accounts) {
- if(connection->userId() == userId) {
+ for (const auto &connection : *this) {
+ if (connection->userId() == userId)
return connection;
- }
}
return nullptr;
}