diff options
author | Sefa Eyeoglu <contact@scrumplex.net> | 2023-08-14 18:16:53 +0200 |
---|---|---|
committer | Sefa Eyeoglu <contact@scrumplex.net> | 2023-08-14 18:16:53 +0200 |
commit | 91ba4cf75ee30c64779edb5b7644e5a830de5026 (patch) | |
tree | aa8c2433bfc3a54577aceeb706c4c2cd0986c95d /launcher/meta/Index.cpp | |
parent | 779f70057b021e285afd60cc650a14cd5feacffd (diff) | |
download | PrismLauncher-91ba4cf75ee30c64779edb5b7644e5a830de5026.tar.gz PrismLauncher-91ba4cf75ee30c64779edb5b7644e5a830de5026.tar.bz2 PrismLauncher-91ba4cf75ee30c64779edb5b7644e5a830de5026.zip |
chore: reformat
Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
Diffstat (limited to 'launcher/meta/Index.cpp')
-rw-r--r-- | launcher/meta/Index.cpp | 97 |
1 files changed, 39 insertions, 58 deletions
diff --git a/launcher/meta/Index.cpp b/launcher/meta/Index.cpp index 4dccccca..657019f8 100644 --- a/launcher/meta/Index.cpp +++ b/launcher/meta/Index.cpp @@ -15,84 +15,75 @@ #include "Index.h" -#include "VersionList.h" #include "JsonFormat.h" +#include "VersionList.h" -namespace Meta -{ -Index::Index(QObject *parent) - : QAbstractListModel(parent) +namespace Meta { +Index::Index(QObject* parent) : QAbstractListModel(parent) {} +Index::Index(const QVector<VersionList::Ptr>& lists, QObject* parent) : QAbstractListModel(parent), m_lists(lists) { -} -Index::Index(const QVector<VersionList::Ptr> &lists, QObject *parent) - : QAbstractListModel(parent), m_lists(lists) -{ - for (int i = 0; i < m_lists.size(); ++i) - { + for (int i = 0; i < m_lists.size(); ++i) { m_uids.insert(m_lists.at(i)->uid(), m_lists.at(i)); connectVersionList(i, m_lists.at(i)); } } -QVariant Index::data(const QModelIndex &index, int role) const +QVariant Index::data(const QModelIndex& index, int role) const { - if (index.parent().isValid() || index.row() < 0 || index.row() >= m_lists.size()) - { + if (index.parent().isValid() || index.row() < 0 || index.row() >= m_lists.size()) { return QVariant(); } VersionList::Ptr list = m_lists.at(index.row()); - switch (role) - { - case Qt::DisplayRole: - if (index.column() == 0) { - return list->humanReadable(); - } else { - break; - } - case UidRole: return list->uid(); - case NameRole: return list->name(); - case ListPtrRole: return QVariant::fromValue(list); + switch (role) { + case Qt::DisplayRole: + if (index.column() == 0) { + return list->humanReadable(); + } else { + break; + } + case UidRole: + return list->uid(); + case NameRole: + return list->name(); + case ListPtrRole: + return QVariant::fromValue(list); } return QVariant(); } -int Index::rowCount(const QModelIndex &parent) const +int Index::rowCount(const QModelIndex& parent) const { return parent.isValid() ? 0 : m_lists.size(); } -int Index::columnCount(const QModelIndex &parent) const +int Index::columnCount(const QModelIndex& parent) const { return parent.isValid() ? 0 : 1; } QVariant Index::headerData(int section, Qt::Orientation orientation, int role) const { - if (orientation == Qt::Horizontal && role == Qt::DisplayRole && section == 0) - { + if (orientation == Qt::Horizontal && role == Qt::DisplayRole && section == 0) { return tr("Name"); - } - else - { + } else { return QVariant(); } } -bool Index::hasUid(const QString &uid) const +bool Index::hasUid(const QString& uid) const { return m_uids.contains(uid); } -VersionList::Ptr Index::get(const QString &uid) +VersionList::Ptr Index::get(const QString& uid) { VersionList::Ptr out = m_uids.value(uid, nullptr); - if(!out) - { + if (!out) { out = std::make_shared<VersionList>(uid); m_uids[uid] = out; } return out; } -Version::Ptr Index::get(const QString &uid, const QString &version) +Version::Ptr Index::get(const QString& uid, const QString& version) { auto list = get(uid); return list->getVersion(version); @@ -103,31 +94,23 @@ void Index::parse(const QJsonObject& obj) parseIndex(obj, this); } -void Index::merge(const std::shared_ptr<Index> &other) +void Index::merge(const std::shared_ptr<Index>& other) { const QVector<VersionList::Ptr> lists = std::dynamic_pointer_cast<Index>(other)->m_lists; // initial load, no need to merge - if (m_lists.isEmpty()) - { + if (m_lists.isEmpty()) { beginResetModel(); m_lists = lists; - for (int i = 0; i < lists.size(); ++i) - { + for (int i = 0; i < lists.size(); ++i) { m_uids.insert(lists.at(i)->uid(), lists.at(i)); connectVersionList(i, lists.at(i)); } endResetModel(); - } - else - { - for (const VersionList::Ptr &list : lists) - { - if (m_uids.contains(list->uid())) - { + } else { + for (const VersionList::Ptr& list : lists) { + if (m_uids.contains(list->uid())) { m_uids[list->uid()]->mergeFromIndex(list); - } - else - { + } else { beginInsertRows(QModelIndex(), m_lists.size(), m_lists.size()); connectVersionList(m_lists.size(), list); m_lists.append(list); @@ -138,11 +121,9 @@ void Index::merge(const std::shared_ptr<Index> &other) } } -void Index::connectVersionList(const int row, const VersionList::Ptr &list) +void Index::connectVersionList(const int row, const VersionList::Ptr& list) { - connect(list.get(), &VersionList::nameChanged, this, [this, row]() - { - emit dataChanged(index(row), index(row), QVector<int>() << Qt::DisplayRole); - }); -} + connect(list.get(), &VersionList::nameChanged, this, + [this, row]() { emit dataChanged(index(row), index(row), QVector<int>() << Qt::DisplayRole); }); } +} // namespace Meta |