diff options
author | Thierry Bastian <thierry.bastian@nokia.com> | 2009-09-01 14:39:30 (GMT) |
---|---|---|
committer | Thierry Bastian <thierry.bastian@nokia.com> | 2009-09-01 14:41:31 (GMT) |
commit | efc616f2a1a83bd4ca50aea9d40a0df005ada063 (patch) | |
tree | c6dd80685a33c36156d2a5d50c4a4182b0b0309e /src/gui/itemviews | |
parent | 3dfde91fcbeaf304edd8d0d09e0732597055cd53 (diff) | |
download | Qt-efc616f2a1a83bd4ca50aea9d40a0df005ada063.zip Qt-efc616f2a1a83bd4ca50aea9d40a0df005ada063.tar.gz Qt-efc616f2a1a83bd4ca50aea9d40a0df005ada063.tar.bz2 |
QTreeView: exapnding nodes just after replacing the model wouldn't work
The problem is that deleting the previous model would triggera delayed
reset. This reset could happen after the model has changed and nodes
are expanded. We can now cancel a reset when reset is called from
another place (like when we set a new model).
Note: autotest included
Task-number: 245654
Reviewed-by: ogoffart
Diffstat (limited to 'src/gui/itemviews')
-rw-r--r-- | src/gui/itemviews/qabstractitemview.cpp | 8 | ||||
-rw-r--r-- | src/gui/itemviews/qabstractitemview_p.h | 10 |
2 files changed, 15 insertions, 3 deletions
diff --git a/src/gui/itemviews/qabstractitemview.cpp b/src/gui/itemviews/qabstractitemview.cpp index 07c5454..ea98cb2 100644 --- a/src/gui/itemviews/qabstractitemview.cpp +++ b/src/gui/itemviews/qabstractitemview.cpp @@ -956,6 +956,7 @@ QModelIndex QAbstractItemView::currentIndex() const void QAbstractItemView::reset() { Q_D(QAbstractItemView); + d->delayedReset.stop(); //make sure we stop the timer QList<QEditorInfo>::const_iterator it = d->editors.constBegin(); for (; it != d->editors.constEnd(); ++it) d->releaseEditor(it->editor); @@ -2208,7 +2209,9 @@ void QAbstractItemView::timerEvent(QTimerEvent *event) Q_D(QAbstractItemView); if (event->timerId() == d->fetchMoreTimer.timerId()) d->fetchMore(); - if (event->timerId() == d->autoScrollTimer.timerId()) + else if (event->timerId() == d->delayedReset.timerId()) + reset(); + else if (event->timerId() == d->autoScrollTimer.timerId()) doAutoScroll(); else if (event->timerId() == d->updateTimer.timerId()) d->updateDirtyRegion(); @@ -3132,9 +3135,8 @@ void QAbstractItemViewPrivate::_q_columnsInserted(const QModelIndex &, int, int) */ void QAbstractItemViewPrivate::_q_modelDestroyed() { - Q_Q(QAbstractItemView); model = QAbstractItemModelPrivate::staticEmptyModel(); - QMetaObject::invokeMethod(q, "reset", Qt::QueuedConnection); + doDelayedReset(); } /*! diff --git a/src/gui/itemviews/qabstractitemview_p.h b/src/gui/itemviews/qabstractitemview_p.h index 4517941..434d644 100644 --- a/src/gui/itemviews/qabstractitemview_p.h +++ b/src/gui/itemviews/qabstractitemview_p.h @@ -328,6 +328,15 @@ public: QStyleOptionViewItemV4 viewOptionsV4() const; + void doDelayedReset() + { + //we delay the reset of the timer because some views (QTableView) + //with headers can't handle the fact that the model has been destroyed + //all _q_modelDestroyed slots must have been called + if (!delayedReset.isActive()) + delayedReset.start(0, q_func()); + } + QAbstractItemModel *model; QPointer<QAbstractItemDelegate> itemDelegate; QMap<int, QPointer<QAbstractItemDelegate> > rowDelegates; @@ -389,6 +398,7 @@ public: QBasicTimer updateTimer; QBasicTimer delayedEditing; QBasicTimer delayedAutoScroll; //used when an item is clicked + QBasicTimer delayedReset; QAbstractItemView::ScrollMode verticalScrollMode; QAbstractItemView::ScrollMode horizontalScrollMode; |