if (emitSignal && animationsEnabled)
prepareAnimatedOperation(item, QVariantAnimation::Forward);
#endif //QT_NO_ANIMATION
- stateBeforeAnimation = state;
+ //if already animating, stateBeforeAnimation is set to the correct value
+ if (state != QAbstractItemView::AnimatingState)
+ stateBeforeAnimation = state;
q->setState(QAbstractItemView::ExpandingState);
const QModelIndex index = viewItems.at(item).index;
storeExpanded(index);
prepareAnimatedOperation(item, QVariantAnimation::Backward);
#endif //QT_NO_ANIMATION
- stateBeforeAnimation = state;
+ //if already animating, stateBeforeAnimation is set to the correct value
+ if (state != QAbstractItemView::AnimatingState)
+ stateBeforeAnimation = state;
q->setState(QAbstractItemView::CollapsingState);
expandedIndexes.erase(it);
viewItems[item].expanded = false;
model->insertRow(2, item);
}
+class tst_QTreeView;
struct PublicView : public QTreeView
{
+ friend class tst_QTreeView;
inline void executeDelayedItemsLayout()
{ QTreeView::executeDelayedItemsLayout(); }
void expandAndCollapse();
void expandAndCollapseAll();
void expandWithNoChildren();
+#ifndef QT_NO_ANIMATION
+ void quickExpandCollapse();
+#endif
void keyboardNavigation();
void headerSections();
void moveCursor_data();
QTest::keyClick(&tree, Qt::Key_Left);
QVERIFY(!root.isExpanded());
-
-
}
void tst_QTreeView::task202039_closePersistentEditor()
QCOMPARE(afterRISpy.size(), 0);
}
+#ifndef QT_NO_ANIMATION
+void tst_QTreeView::quickExpandCollapse()
+{
+ //this unit tests makes sure the state after the animation is restored correctly
+ //after starting a 2nd animation while the first one was still on-going
+ //this tests that the stateBeforeAnimation is not set to AnimatingState
+ PublicView tree;
+ tree.setAnimated(true);
+ QStandardItemModel model;
+ QStandardItem *root = new QStandardItem("root");
+ root->appendRow(new QStandardItem("subnode"));
+ model.appendRow(root);
+ tree.setModel(&model);
+
+ QModelIndex rootIndex = root->index();
+ QVERIFY(rootIndex.isValid());
+
+ tree.show();
+ QTest::qWaitForWindowShown(&tree);
+
+ int initialState = tree.state();
+
+ tree.expand(rootIndex);
+ QCOMPARE(tree.state(), (int)PublicView::AnimatingState);
+
+ tree.collapse(rootIndex);
+ QCOMPARE(tree.state(), (int)PublicView::AnimatingState);
+
+ QTest::qWait(500); //the animation lasts for 250ms max so 500 should be enough
+
+ QCOMPARE(tree.state(), initialState);
+}
+#endif
+
QTEST_MAIN(tst_QTreeView)
#include "tst_qtreeview.moc"