T
T
typbl42011-12-02 16:47:37
Qt
typbl4, 2011-12-02 16:47:37

Qt4. Incorrect rendering of a hierarchical model when setting a proxy model that swaps columns?

Hello gentlemen!
There is a custom hierarchical model inherited from QAbstractItemModel. Written its own proxy model. Inherited from QSortFilterProxyModel'i (overridden methods: data, setData, headerData, mapToSource, mapFromSource, hasChildren, rowCount). In addition to the functionality of QSortFilterProxyModel, it also knows how to throw out some columns, as well as swap the rest. Everything works if the null column from the original model matches the null column in the proxy model. If the proxy model moves this column, then the display is incorrect: Arrows (or crosses) are drawn correctly - opposite those elements that have descendants. But when you try to open such an element, it turns out that there are no elements inside.
Here are some proxy model methods:
bool MySortFilterProxyModel::hasChildren(const QModelIndex &parent) const

{<br/>
 if (parent.isValid() && parent.column() != 0)<br/>
 return false;<br/>
 <br/>
 QModelIndex source_parent = mapToSource(parent);<br/>
 return sourceModel()-&gt;hasChildren( source_parent.sibling(source_parent.row(), 0) );<br/>
}<br/>
<br/>
int MySortFilterProxyModel::rowCount(const QModelIndex &parent) const<br/>
{<br/>
 if (parent.isValid() && parent.column() != 0)<br/>
 return 0;<br/>
 <br/>
 QModelIndex source_parent = mapToSource(parent);<br/>
 return sourceModel()-&gt;rowCount( source_parent.sibling(source_parent.row(), 0) );<br/>
}

And MySortFilterProxyModel::rowCount returns the correct number of columns. But we also noticed the call to the rowCount method of the original model, bypassing the call to MySortFilterProxyModel::rowCount. This happens when the View calls QSortFilterProxyModel::index(). Maybe the problem is related to this?
I will be glad for your help. Thank you.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question