QTreeView::expandToDepth - add missing emit of expanded and collapsed
Just like other functions this function should emit expanded and collapsed. A part of fixing Task-number: QTBUG-8176 Change-Id: I6d801f61e6f0cb8836634cc52f0be2b610f6c728 Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
This commit is contained in:
parent
ebca7d2ea7
commit
08a632ac1a
@ -2668,6 +2668,8 @@ void QTreeView::expandToDepth(int depth)
|
||||
{
|
||||
Q_D(QTreeView);
|
||||
d->viewItems.clear();
|
||||
QSet<QPersistentModelIndex> old_expandedIndexes;
|
||||
old_expandedIndexes = d->expandedIndexes;
|
||||
d->expandedIndexes.clear();
|
||||
d->interruptDelayedItemsLayout();
|
||||
d->layout(-1);
|
||||
@ -2678,6 +2680,24 @@ void QTreeView::expandToDepth(int depth)
|
||||
d->storeExpanded(d->viewItems.at(i).index);
|
||||
}
|
||||
}
|
||||
|
||||
// emit signals
|
||||
QSet<QPersistentModelIndex> collapsedIndexes = old_expandedIndexes - d->expandedIndexes;
|
||||
QSet<QPersistentModelIndex>::const_iterator i = collapsedIndexes.constBegin();
|
||||
for (; i != collapsedIndexes.constEnd(); ++i) {
|
||||
const QPersistentModelIndex &mi = (*i);
|
||||
if (mi.isValid() && !(mi.flags() & Qt::ItemNeverHasChildren))
|
||||
emit collapsed(mi);
|
||||
}
|
||||
|
||||
QSet<QPersistentModelIndex> expandedIndexs = d->expandedIndexes - old_expandedIndexes;
|
||||
i = expandedIndexs.constBegin();
|
||||
for (; i != expandedIndexs.constEnd(); ++i) {
|
||||
const QPersistentModelIndex &mi = (*i);
|
||||
if (mi.isValid() && !(mi.flags() & Qt::ItemNeverHasChildren))
|
||||
emit expanded(mi);
|
||||
}
|
||||
|
||||
updateGeometries();
|
||||
d->viewport->update();
|
||||
}
|
||||
|
@ -4225,6 +4225,15 @@ void tst_QTreeView::taskQTBUG_8176_emitOnExpandAll()
|
||||
spy2.clear();
|
||||
tw.collapseAll();
|
||||
QCOMPARE(spy2.size(), 5);
|
||||
|
||||
// expand to depth
|
||||
item2->setExpanded(true);
|
||||
spy.clear();
|
||||
spy2.clear();
|
||||
tw.expandToDepth(0);
|
||||
|
||||
QCOMPARE(spy.size(), 2); // item and item5 are expanded
|
||||
QCOMPARE(spy2.size(), 1); // item2 is collapsed
|
||||
}
|
||||
|
||||
#ifndef QT_NO_ANIMATION
|
||||
|
Loading…
Reference in New Issue
Block a user