summaryrefslogtreecommitdiffstats
path: root/api/logic/meta/Index.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'api/logic/meta/Index.cpp')
-rw-r--r--api/logic/meta/Index.cpp162
1 files changed, 81 insertions, 81 deletions
diff --git a/api/logic/meta/Index.cpp b/api/logic/meta/Index.cpp
index 6e1e34cd..4dbc0a86 100644
--- a/api/logic/meta/Index.cpp
+++ b/api/logic/meta/Index.cpp
@@ -21,128 +21,128 @@
namespace Meta
{
Index::Index(QObject *parent)
- : QAbstractListModel(parent)
+ : QAbstractListModel(parent)
{
}
Index::Index(const QVector<VersionListPtr> &lists, QObject *parent)
- : QAbstractListModel(parent), m_lists(lists)
+ : QAbstractListModel(parent), m_lists(lists)
{
- 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));
- }
+ 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
{
- if (index.parent().isValid() || index.row() < 0 || index.row() >= m_lists.size())
- {
- return QVariant();
- }
+ if (index.parent().isValid() || index.row() < 0 || index.row() >= m_lists.size())
+ {
+ return QVariant();
+ }
- VersionListPtr list = m_lists.at(index.row());
- switch (role)
- {
- case Qt::DisplayRole:
- switch (index.column())
- {
- case 0: return list->humanReadable();
- default: break;
- }
- case UidRole: return list->uid();
- case NameRole: return list->name();
- case ListPtrRole: return QVariant::fromValue(list);
- }
- return QVariant();
+ VersionListPtr list = m_lists.at(index.row());
+ switch (role)
+ {
+ case Qt::DisplayRole:
+ switch (index.column())
+ {
+ case 0: return list->humanReadable();
+ default: 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
{
- return m_lists.size();
+ return m_lists.size();
}
int Index::columnCount(const QModelIndex &parent) const
{
- return 1;
+ return 1;
}
QVariant Index::headerData(int section, Qt::Orientation orientation, int role) const
{
- if (orientation == Qt::Horizontal && role == Qt::DisplayRole && section == 0)
- {
- return tr("Name");
- }
- else
- {
- return QVariant();
- }
+ if (orientation == Qt::Horizontal && role == Qt::DisplayRole && section == 0)
+ {
+ return tr("Name");
+ }
+ else
+ {
+ return QVariant();
+ }
}
bool Index::hasUid(const QString &uid) const
{
- return m_uids.contains(uid);
+ return m_uids.contains(uid);
}
VersionListPtr Index::get(const QString &uid)
{
- VersionListPtr out = m_uids.value(uid, nullptr);
- if(!out)
- {
- out = std::make_shared<VersionList>(uid);
- m_uids[uid] = out;
- }
- return out;
+ VersionListPtr out = m_uids.value(uid, nullptr);
+ if(!out)
+ {
+ out = std::make_shared<VersionList>(uid);
+ m_uids[uid] = out;
+ }
+ return out;
}
VersionPtr Index::get(const QString &uid, const QString &version)
{
- auto list = get(uid);
- return list->getVersion(version);
+ auto list = get(uid);
+ return list->getVersion(version);
}
void Index::parse(const QJsonObject& obj)
{
- parseIndex(obj, this);
+ parseIndex(obj, this);
}
void Index::merge(const std::shared_ptr<Index> &other)
{
- const QVector<VersionListPtr> lists = std::dynamic_pointer_cast<Index>(other)->m_lists;
- // initial load, no need to merge
- if (m_lists.isEmpty())
- {
- beginResetModel();
- m_lists = lists;
- 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 VersionListPtr &list : lists)
- {
- if (m_uids.contains(list->uid()))
- {
- m_uids[list->uid()]->mergeFromIndex(list);
- }
- else
- {
- beginInsertRows(QModelIndex(), m_lists.size(), m_lists.size());
- connectVersionList(m_lists.size(), list);
- m_lists.append(list);
- m_uids.insert(list->uid(), list);
- endInsertRows();
- }
- }
- }
+ const QVector<VersionListPtr> lists = std::dynamic_pointer_cast<Index>(other)->m_lists;
+ // initial load, no need to merge
+ if (m_lists.isEmpty())
+ {
+ beginResetModel();
+ m_lists = lists;
+ 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 VersionListPtr &list : lists)
+ {
+ if (m_uids.contains(list->uid()))
+ {
+ m_uids[list->uid()]->mergeFromIndex(list);
+ }
+ else
+ {
+ beginInsertRows(QModelIndex(), m_lists.size(), m_lists.size());
+ connectVersionList(m_lists.size(), list);
+ m_lists.append(list);
+ m_uids.insert(list->uid(), list);
+ endInsertRows();
+ }
+ }
+ }
}
void Index::connectVersionList(const int row, const VersionListPtr &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);
+ });
}
}