Hi,
I have a tree model:
A
|_AA
| |_id1 a b c d e f
| |_id2 e r t y i j
| |_id3 t f g h s w
| |_id4 l o m n h k
| |_id5 a b c d e f
| |_id6 a b c d e f
| |_id7 a b c d e f
| |_id8 a b c d e f
and I'd like to display it in the tree view as the following arrangement:
A
|_AA
| |_id1 id2 id3 id4
| |_id5 id6 id7 id8
Mapping algorithm would be:
if index has children then pass index otherwise map row to row/4, column to column%4 and don't display indices with column > 0.
I've reimplemented mapToSource, mapFromSource, filterAcceptsColumn:
bool MyProxyModel
::filterAcceptsColumn(int sourceColumn,
const QModelIndex &sourceParent
) const {
return ( sourceParent.isValid() ||
sourceParent.child(0,0).isValid() ||
( !sourceParent.child(0,0).isValid() && sourceColumn==0 )
);
}
{
if(sourceIndex.isValid()) {
if( sourceIndex.child(0,0).isValid() ) {
return sourceIndex;
} else {
if( sourceIndex.column() == 0 ) {
return createIndex(sourceIndex.row()/4, sourceIndex.row()%4);
} else {
}
}
} else {
}
}
{
if(proxyIndex.isValid()) {
if( item!=0 && item->hasChildren() ) {
return proxyIndex;
} else {
return sourceModel()->index(
proxyIndex.row()*4 + proxyIndex.column(),
0,
proxyIndex.parent()
);
}
} else {
}
}
bool MyProxyModel::filterAcceptsColumn(int sourceColumn, const QModelIndex &sourceParent) const
{
return ( sourceParent.isValid() ||
sourceParent.child(0,0).isValid() ||
( !sourceParent.child(0,0).isValid() && sourceColumn==0 )
);
}
QModelIndex MyProxyModel::mapFromSource( const QModelIndex & sourceIndex ) const
{
if(sourceIndex.isValid()) {
if( sourceIndex.child(0,0).isValid() ) {
return sourceIndex;
} else {
if( sourceIndex.column() == 0 ) {
return createIndex(sourceIndex.row()/4, sourceIndex.row()%4);
} else {
return QModelIndex();
}
}
} else {
return QModelIndex();
}
}
QModelIndex MyProxyModel::mapToSource ( const QModelIndex & proxyIndex ) const
{
if(proxyIndex.isValid()) {
QStandardItem *item = (QStandardItem *) proxyIndex.internalPointer();
if( item!=0 && item->hasChildren() ) {
return proxyIndex;
} else {
return sourceModel()->index(
proxyIndex.row()*4 + proxyIndex.column(),
0,
proxyIndex.parent()
);
}
} else {
return QModelIndex();
}
}
To copy to clipboard, switch view to plain text mode
I'm crashing while clicking on AA and trying to expand it.
( QTreeViewPrivate::layout(int i); line 3130 Q_Assert(i>-1) )
I'd appreciate ideas on how to approach this issue.
Cheers,
Wojtek
Bookmarks