[Qt5-feedback] A childrenLayoutChanged signal for QAbstractItemModel
Stephen Kelly
steveire at gmail.com
Tue Jul 12 12:58:37 CEST 2011
Hi,
One of the most expensive signals to process from a QAbstractItemModel is
layoutAboutToBeChanged and layoutChanged.
Processing them in a proxy model is more expensive than processing the
reset() signals, because you have to recreate the mappings for all
QPersistentModelIndexes as well as all of their ancestors.
The problem is that the signals contain no granularity regarding what part
of the structure is being changed. A layout change can result in rows in a
tree being added, removed and moved.
In theory it would be possible to take a QPersistentModelIndex of every
element in the tree on layoutAboutToBeChanged and examine the changes to
them on layoutChanged to figure out what happened, but taking a
QPersistentModelIndex of every element in the tree is prohibitively
expensive and not smart.
The layout change signals are used when sorting in QSFPM for example (even
if only sorting a single level when data changes for example). They can also
be used to move stuff around.
I intend to add more granular ways to signal a structural change.
signals:
void childrenLayoutsAboutToBeChanged(QModelIndex, QModelIndex)
void childrenLayoutsChanged(QModelIndex, QModelIndex)
The new signals allow signalling about a change localized in just two parent
indexes. That is enough to signal a move between two parents, and can be
used with the same index for both arguments in the case of sorting the
children of a single parent index, similar to the way dataChanged() is used.
If you're paying close attention you might think that the existing move
signal is enough, but it is not really because it is too exact for a QSFPM
that does sorting:
If a contiguous range of rows is moved in the source model, the result in
the sorting proxy model might be entirely different, or no change at all.
See also https://qt.gitorious.org/qt/qt/merge_requests/776 which is this
feature applied to Qt4.
The
+ if (ignoreNextLayoutAboutToBeChanged) {
+ ignoreNextLayoutAboutToBeChanged = false;
+ return;
+ }
code complained about is not needed in Qt5.
The branch contains some commits so you should look at the commits in the
branch if you're interested for clarity, and not at the diff in gitorious.
Thanks,
Steve.
More information about the Qt5-feedback
mailing list