From 10485e15e4de3e1a6c30733ad2d4850591d31509 Mon Sep 17 00:00:00 2001 From: Tannin Date: Wed, 27 Mar 2013 12:32:23 +0100 Subject: - some cleanup to hookdll - exchanged grouping proxies with existing solution from the kde project --- src/modlistgroupcategoriesproxy.cpp | 123 ------------------------------------ 1 file changed, 123 deletions(-) delete mode 100644 src/modlistgroupcategoriesproxy.cpp (limited to 'src/modlistgroupcategoriesproxy.cpp') 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); -} -- cgit v1.3.1