summaryrefslogtreecommitdiff
path: root/src/modlistgroupcategoriesproxy.cpp
diff options
context:
space:
mode:
authorTannin <devnull@localhost>2013-03-27 12:32:23 +0100
committerTannin <devnull@localhost>2013-03-27 12:32:23 +0100
commit10485e15e4de3e1a6c30733ad2d4850591d31509 (patch)
treed4ca59328823e5d6ff8be6f403f0eb8c5c7cf05a /src/modlistgroupcategoriesproxy.cpp
parentec0ea9df8dabe686d3256665c7ed638660309915 (diff)
- some cleanup to hookdll
- exchanged grouping proxies with existing solution from the kde project
Diffstat (limited to 'src/modlistgroupcategoriesproxy.cpp')
-rw-r--r--src/modlistgroupcategoriesproxy.cpp123
1 files changed, 0 insertions, 123 deletions
diff --git a/src/modlistgroupcategoriesproxy.cpp b/src/modlistgroupcategoriesproxy.cpp
deleted file mode 100644
index 4320be97..00000000
--- a/src/modlistgroupcategoriesproxy.cpp
+++ /dev/null
@@ -1,123 +0,0 @@
-#include "modlistgroupcategoriesproxy.h"
-#include "categories.h"
-#include "modinfo.h"
-
-
-ModListGroupCategoriesProxy::ModListGroupCategoriesProxy(QObject *parent)
- : QAbstractProxyModel(parent)
-{
-}
-
-int ModListGroupCategoriesProxy::rowCount(const QModelIndex &parent) const
-{
- if (!parent.isValid()) {
- return CategoryFactory::instance().numCategories();
- } else {
- unsigned int count = 0;
- for (int i = 0; i < sourceModel()->rowCount(); ++i) {
- if (ModInfo::getByIndex(i)->getPrimaryCategory() ==
- CategoryFactory::instance().getCategoryID(parent.row())) {
- ++count;
- }
- }
- return count;
- }
-}
-
-int ModListGroupCategoriesProxy::columnCount(const QModelIndex &parent) const
-{
- return sourceModel()->columnCount(mapToSource(parent));
-}
-
-QModelIndex ModListGroupCategoriesProxy::mapToSource(const QModelIndex &proxyIndex) const
-{
- auto iter = m_IndexMap.find(proxyIndex);
- if (iter != m_IndexMap.end()) {
- return iter->second;
- } else {
- return QModelIndex();
- }
-}
-
-QModelIndex ModListGroupCategoriesProxy::mapFromSource(const QModelIndex &sourceIndex) const
-{
- if (!sourceIndex.isValid()) {
- return QModelIndex();
- } else {
- ModInfo::Ptr mod = ModInfo::getByIndex(sourceIndex.data(Qt::UserRole + 1).toInt());
- return index(sourceIndex.row(), sourceIndex.column(), index(mod->getPrimaryCategory(), 0, QModelIndex()));
- }
-}
-
-QModelIndex ModListGroupCategoriesProxy::index(int row, int column, const QModelIndex &parent) const
-{
- if (parent.isValid()) {
- // mod
- int categoryId = CategoryFactory::instance().getCategoryID(parent.row());
-
- int srcRow = 0;
- int offset = row;
- for (; srcRow < sourceModel()->rowCount(); ++srcRow) {
- int modId = sourceModel()->index(srcRow, column).data(Qt::UserRole + 1).toInt();
- if (ModInfo::getByIndex(modId)->getPrimaryCategory() == categoryId) {
-
- if (--offset < 0) {
- break;
- }
- }
- }
- QPersistentModelIndex idx = createIndex(row, column, categoryId);
- m_IndexMap[idx] = QPersistentModelIndex(sourceModel()->index(srcRow, column));
- return idx;
- } else {
- // category
- return createIndex(row, column, -1);
- }
-}
-
-QModelIndex ModListGroupCategoriesProxy::parent(const QModelIndex &child) const
-{
- if (!child.isValid()) {
- return QModelIndex();
- } else if (child.internalId() == -1) {
- return QModelIndex(); // top level
- } else {
- return index(CategoryFactory::instance().getCategoryIndex(child.internalId()), 0, QModelIndex());
- }
-}
-
-bool ModListGroupCategoriesProxy::hasChildren(const QModelIndex &parent) const
-{
- // root item always has children (the categories), mods don't
- if (!parent.isValid()) return true;
- else if (parent.internalId() != -1) return false;
-
- for (int i = 0; i < sourceModel()->rowCount(); ++i) {
- ModInfo::Ptr mod = ModInfo::getByIndex(i);
- if (mod->getPrimaryCategory() == CategoryFactory::instance().getCategoryID(parent.row())) {
- return true;
- }
- }
- return false;
-}
-
-QVariant ModListGroupCategoriesProxy::data(const QModelIndex &proxyIndex, int role) const
-{
- auto iter = m_IndexMap.find(proxyIndex);
- if (iter != m_IndexMap.end()) {
- // mod
- return sourceModel()->data(iter->second, role);
- } else {
- // category
- if ((role == Qt::DisplayRole) && (proxyIndex.column() == 0)) {
- return CategoryFactory::instance().getCategoryName(proxyIndex.row());
- } else {
- return QVariant();
- }
- }
-}
-
-QVariant ModListGroupCategoriesProxy::headerData(int section, Qt::Orientation orientation, int role) const
-{
- return sourceModel()->headerData(section, orientation, role);
-}