summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/gui/itemviews/qtreeview.cpp8
-rw-r--r--tests/auto/qtreeview/tst_qtreeview.cpp41
2 files changed, 47 insertions, 2 deletions
diff --git a/src/gui/itemviews/qtreeview.cpp b/src/gui/itemviews/qtreeview.cpp
index bc9d54c..40234e0 100644
--- a/src/gui/itemviews/qtreeview.cpp
+++ b/src/gui/itemviews/qtreeview.cpp
@@ -2884,7 +2884,9 @@ void QTreeViewPrivate::expand(int item, bool emitSignal)
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);
@@ -2975,7 +2977,9 @@ void QTreeViewPrivate::collapse(int item, bool emitSignal)
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;
diff --git a/tests/auto/qtreeview/tst_qtreeview.cpp b/tests/auto/qtreeview/tst_qtreeview.cpp
index 7ef5406..716fbd5 100644
--- a/tests/auto/qtreeview/tst_qtreeview.cpp
+++ b/tests/auto/qtreeview/tst_qtreeview.cpp
@@ -76,8 +76,11 @@ static void initStandardTreeModel(QStandardItemModel *model)
model->insertRow(2, item);
}
+class tst_QTreeView;
struct PublicView : public QTreeView
{
+ friend class tst_QTreeView;
+
inline void executeDelayedItemsLayout()
{ QTreeView::executeDelayedItemsLayout(); }
@@ -246,6 +249,10 @@ private slots:
void taskQTBUG_11466_keyboardNavigationRegression();
void taskQTBUG_13567_removeLastItemRegression();
void taskQTBUG_25333_adjustViewOptionsForIndex();
+
+#ifndef QT_NO_ANIMATION
+ void quickExpandCollapse();
+#endif
};
class QtTestModel: public QAbstractItemModel
@@ -4050,6 +4057,40 @@ void tst_QTreeView::taskQTBUG_25333_adjustViewOptionsForIndex()
}
+#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"