diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/mainwindow.cpp | 2 | ||||
| -rw-r--r-- | src/modlist.cpp | 23 | ||||
| -rw-r--r-- | src/modlist.h | 2 | ||||
| -rw-r--r-- | src/qtgroupingproxy.cpp | 27 | ||||
| -rw-r--r-- | src/qtgroupingproxy.h | 13 |
5 files changed, 61 insertions, 6 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 2efbdc0f..592c933d 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -4062,7 +4062,7 @@ void MainWindow::on_groupCombo_currentIndexChanged(int index) QAbstractProxyModel *newModel = NULL; switch (index) { case 1: { - newModel = new QtGroupingProxy(m_ModListSortProxy, QModelIndex(), ModList::COL_CATEGORY); + newModel = new QtGroupingProxy(m_ModListSortProxy, QModelIndex(), ModList::COL_CATEGORY, Qt::UserRole); } break; case 2: { newModel = new QtGroupingProxy(m_ModListSortProxy, QModelIndex(), ModList::COL_MODID); diff --git a/src/modlist.cpp b/src/modlist.cpp index 84e76b75..2d681a0d 100644 --- a/src/modlist.cpp +++ b/src/modlist.cpp @@ -196,7 +196,21 @@ QVariant ModList::data(const QModelIndex &modelIndex, int role) const return QVariant(Qt::AlignCenter | Qt::AlignVCenter); } } else if (role == Qt::UserRole) { - return modInfo->getNexusID(); + if (column == COL_CATEGORY) { + QVariantList categoryNames; + std::set<int> categories = modInfo->getCategories(); + CategoryFactory &categoryFactory = CategoryFactory::instance(); + for (auto iter = categories.begin(); iter != categories.end(); ++iter) { + categoryNames.append(categoryFactory.getCategoryName(categoryFactory.getCategoryIndex(*iter))); + } + if (categoryNames.count() != 0) { + return categoryNames; + } else { + return QVariant(); + } + } else { + return modInfo->getNexusID(); + } } else if (role == Qt::UserRole + 1) { return modIndex; } else if (role == Qt::FontRole) { @@ -588,6 +602,13 @@ QModelIndex ModList::parent(const QModelIndex&) const return QModelIndex(); } +QMap<int, QVariant> ModList::itemData(const QModelIndex &index) const +{ + QMap<int, QVariant> result = QAbstractItemModel::itemData(index); + result[Qt::UserRole] = data(index, Qt::UserRole); + return result; +} + QString ModList::getColumnName(int column) { diff --git a/src/modlist.h b/src/modlist.h index a520ba75..ea850d54 100644 --- a/src/modlist.h +++ b/src/modlist.h @@ -114,6 +114,8 @@ public: // implementation of virtual functions of QAbstractItemModel const QModelIndex &parent = QModelIndex()) const; virtual QModelIndex parent(const QModelIndex &child) const; + virtual QMap<int, QVariant> itemData(const QModelIndex &index) const; + public slots: signals: diff --git a/src/qtgroupingproxy.cpp b/src/qtgroupingproxy.cpp index 5c1e0275..95a4aad0 100644 --- a/src/qtgroupingproxy.cpp +++ b/src/qtgroupingproxy.cpp @@ -14,6 +14,9 @@ * this program. If not, see <http://www.gnu.org/licenses/>. *
****************************************************************************************/
+// Modifications 2013-03-27 to 2013-03-28 by Sebastian Herbord
+
+
#include "QtGroupingProxy.h"
#include <QDebug>
@@ -28,10 +31,12 @@ \ingroup model-view
*/
-QtGroupingProxy::QtGroupingProxy( QAbstractItemModel *model, QModelIndex rootNode, int groupedColumn )
+QtGroupingProxy::QtGroupingProxy(QAbstractItemModel *model, QModelIndex rootNode, int groupedColumn, Qt::ItemDataRole groupedRole, unsigned int flags )
: QAbstractProxyModel()
, m_rootNode( rootNode )
, m_groupedColumn( 0 )
+ , m_groupedRole( groupedRole )
+ , m_flags( flags )
{
setSourceModel( model );
@@ -84,14 +89,23 @@ QtGroupingProxy::belongsTo( const QModelIndex &idx ) //get all the data for this index from the model
ItemData itemData = sourceModel()->itemData( idx );
+ if (m_groupedRole != Qt::DisplayRole) {
+ itemData[Qt::DisplayRole] = itemData[m_groupedRole];
+ }
+
+ // invalid value in grouped role -> ungrouped
+ if (!itemData[Qt::DisplayRole].isValid()) {
+ return rowDataList;
+ }
+
QMapIterator<int, QVariant> i( itemData );
while( i.hasNext() )
{
i.next();
int role = i.key();
QVariant variant = i.value();
- // qDebug() << "role " << role << " : (" << variant.typeName() << ") : "<< variant;
- if( variant.type() == QVariant::List )
+ qDebug() << "role " << role << " : (" << variant.typeName() << ") : "<< variant;
+ if ( variant.type() == QVariant::List )
{
//a list of variants get's expanded to multiple rows
QVariantList list = variant.toList();
@@ -111,6 +125,7 @@ QtGroupingProxy::belongsTo( const QModelIndex &idx ) rowData.insert( m_groupedColumn, indexData );
rowDataList.insert( i, rowData );
}
+ break;
}
else if( !variant.isNull() )
{
@@ -155,8 +170,13 @@ QtGroupingProxy::buildTree() }
//dumpGroups();
+ if (m_flags & FLAG_NOSINGLE) {
+
+ }
+
endResetModel();
+ // restore expand-state
for( int row = 0; row < rowCount(); row++ ) {
QModelIndex idx = index( row, 0, QModelIndex() );
if (m_expandedItems.contains(idx.data(Qt::UserRole).toString())) {
@@ -326,6 +346,7 @@ QtGroupingProxy::rowCount( const QModelIndex &index ) const if( !index.isValid() )
{
//the number of top level groups + the number of non-grouped items
+ qDebug("groups: %d - ungrouped: %d", m_groupMaps.count(), m_groupHash.value(std::numeric_limits<quint32>::max()).count());
int rows = m_groupMaps.count() + m_groupHash.value( std::numeric_limits<quint32>::max() ).count();
//qDebug() << rows << " in root group";
return rows;
diff --git a/src/qtgroupingproxy.h b/src/qtgroupingproxy.h index 6ec34481..a7f151ce 100644 --- a/src/qtgroupingproxy.h +++ b/src/qtgroupingproxy.h @@ -14,6 +14,8 @@ * this program. If not, see <http://www.gnu.org/licenses/>. *
****************************************************************************************/
+// Modifications 2013-03-27 to 2013-03-28 by Sebastian Herbord
+
#ifndef GROUPINGPROXY_H
#define GROUPINGPROXY_H
@@ -30,9 +32,16 @@ typedef QMap<int, ItemData> RowData; class QtGroupingProxy : public QAbstractProxyModel
{
Q_OBJECT
+
+public:
+
+ static const unsigned int FLAG_NOSINGLE = 1;
+ static const unsigned int FLAG_NAMETOPITEM = 2;
+
public:
explicit QtGroupingProxy( QAbstractItemModel *model, QModelIndex rootNode = QModelIndex(),
- int groupedColumn = -1 );
+ int groupedColumn = -1, Qt::ItemDataRole groupedRole = Qt::DisplayRole,
+ unsigned int flags = 0);
~QtGroupingProxy();
void setGroupedColumn( int groupedColumn );
@@ -139,6 +148,8 @@ protected: private:
QSet<QString> m_expandedItems;
+ unsigned int m_flags;
+ int m_groupedRole;
};
#endif //GROUPINGPROXY_H
|
