// Proxy model ... transparent at the moment
{
Q_OBJECT
private:
bool *groupBy;
public:
setParent(parent);
}
~GroupByModel() {}
// create a model index, don't bother with parent for now
// since -1,-1 has no parent and all others have a parent of -1.-1
return createIndex(row,column);
}
// parent is at -1, -1. All others have a parent of -1, -1
// we are at the top, return an invalid parent
if (index.
column() == -1 && index.
row() == -1) return QModelIndex();
else return createIndex(-1,-1);
}
// we use the same co-ords for now, so map to the same
return sourceModel()->index(proxyIndex.row(),proxyIndex.column());
}
// source model should be the same as ours
return index(sourceIndex.row(), sourceIndex.column());
}
// same columns as source please
return sourceModel()->columnCount(sourceModel()->index(parent.row(), parent.column()));
}
if (parent.row() == -1 && parent.column() == -1) {
return sourceModel()->rowCount(sourceModel()->index(parent.row(), parent.column()));
} else
return 0;
}
// does this index have children?
// if it is the root index (-1,-1) - it might have children
if (index.row() == -1 && index.column() == -1 && rowCount(createIndex(-1,-1)))
return true;
else
return false;
}
};
// Proxy model ... transparent at the moment
class GroupByModel : public QAbstractProxyModel
{
Q_OBJECT
private:
bool *groupBy;
public:
GroupByModel(bool *groupBy, QObject *parent = NULL) : QAbstractProxyModel(parent), groupBy(groupBy) {
setParent(parent);
}
~GroupByModel() {}
// create a model index, don't bother with parent for now
// since -1,-1 has no parent and all others have a parent of -1.-1
QModelIndex index(int row, int column, const QModelIndex & = QModelIndex()) const {
return createIndex(row,column);
}
// parent is at -1, -1. All others have a parent of -1, -1
QModelIndex parent(const QModelIndex &index) const {
// we are at the top, return an invalid parent
if (index.column() == -1 && index.row() == -1) return QModelIndex();
else return createIndex(-1,-1);
}
QModelIndex mapToSource(const QModelIndex &proxyIndex) const {
// we use the same co-ords for now, so map to the same
return sourceModel()->index(proxyIndex.row(),proxyIndex.column());
}
// source model should be the same as ours
QModelIndex mapFromSource(const QModelIndex &sourceIndex) const {
return index(sourceIndex.row(), sourceIndex.column());
}
// same columns as source please
int columnCount(const QModelIndex &parent = QModelIndex()) const {
return sourceModel()->columnCount(sourceModel()->index(parent.row(), parent.column()));
}
int rowCount(const QModelIndex &parent = QModelIndex()) const {
if (parent.row() == -1 && parent.column() == -1) {
return sourceModel()->rowCount(sourceModel()->index(parent.row(), parent.column()));
} else
return 0;
}
// does this index have children?
bool hasChildren(const QModelIndex &index) const {
// if it is the root index (-1,-1) - it might have children
if (index.row() == -1 && index.column() == -1 && rowCount(createIndex(-1,-1)))
return true;
else
return false;
}
};
To copy to clipboard, switch view to plain text mode
Bookmarks