summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorStephen Kelly <steveire@gmail.com>2009-07-31 12:00:40 +0100
committerOlivier Goffart <ogoffart@trolltech.com>2009-08-28 11:34:24 +0200
commit4d197ec0eaeae61499d8ee6dc0e98147800f583e (patch)
tree606dd9392cc8e3bab799c38b118fc0f2c761a30f /src/gui
parent7091ec8cd1ec94fb889230d69fc70d40a9f69b2d (diff)
downloadqt4-tools-4d197ec0eaeae61499d8ee6dc0e98147800f583e.tar.gz
Fix the API for resetting QAbstractItemModels.
This commit deprecates the QAIM::reset() method, and adds beginResetModel() and endResetModel() methods, addressing Qt issue 247023. http://www.qtsoftware.com/developer/task-tracker/index_html?method=entry&id=247023 If models and proxies use QAIM::reset() alone, then proxies will emit modelAboutToBeReset after its source model is reset. This means that mapToSource will not behave as expected (Will always return an invalid index) in a slot connected to modelAboutToBeReset. The usecase for this is maintaining viewstate (which items are selected, expanded) when the model is reset. See BrowserWidget::modelChanged here: http://websvn.kde.org/trunk/KDE/kdepim/akonadi/akonadiconsole/browserwidget.cpp?view=markup Task-number: 247023 Reviewed-by: Olivier Goffart <ogoffart@trolltech.com> Merge-request: 1072
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/itemviews/qsortfilterproxymodel.cpp11
-rw-r--r--src/gui/itemviews/qsortfilterproxymodel.h1
2 files changed, 11 insertions, 1 deletions
diff --git a/src/gui/itemviews/qsortfilterproxymodel.cpp b/src/gui/itemviews/qsortfilterproxymodel.cpp
index d173efe97a..18fbf7b204 100644
--- a/src/gui/itemviews/qsortfilterproxymodel.cpp
+++ b/src/gui/itemviews/qsortfilterproxymodel.cpp
@@ -174,6 +174,7 @@ public:
const QModelIndex &source_bottom_right);
void _q_sourceHeaderDataChanged(Qt::Orientation orientation, int start, int end);
+ void _q_sourceAboutToBeReset();
void _q_sourceReset();
void _q_sourceLayoutAboutToBeChanged();
@@ -1148,11 +1149,17 @@ void QSortFilterProxyModelPrivate::_q_sourceHeaderDataChanged(Qt::Orientation or
emit q->headerDataChanged(orientation, proxy_start, proxy_end);
}
+void QSortFilterProxyModelPrivate::_q_sourceAboutToBeReset()
+{
+ Q_Q(QSortFilterProxyModel);
+ q->beginResetModel();
+}
+
void QSortFilterProxyModelPrivate::_q_sourceReset()
{
Q_Q(QSortFilterProxyModel);
// All internal structures are deleted in clear()
- q->reset();
+ q->endResetModel();
update_source_sort_column();
if (dynamic_sortfilter)
sort();
@@ -1499,6 +1506,7 @@ void QSortFilterProxyModel::setSourceModel(QAbstractItemModel *sourceModel)
disconnect(d->model, SIGNAL(layoutChanged()),
this, SLOT(_q_sourceLayoutChanged()));
+ disconnect(d->model, SIGNAL(modelAboutToBeReset()), this, SLOT(_q_sourceAboutToBeReset()));
disconnect(d->model, SIGNAL(modelReset()), this, SLOT(_q_sourceReset()));
QAbstractProxyModel::setSourceModel(sourceModel);
@@ -1539,6 +1547,7 @@ void QSortFilterProxyModel::setSourceModel(QAbstractItemModel *sourceModel)
connect(d->model, SIGNAL(layoutChanged()),
this, SLOT(_q_sourceLayoutChanged()));
+ connect(d->model, SIGNAL(modelAboutToBeReset()), this, SLOT(_q_sourceAboutToBeReset()));
connect(d->model, SIGNAL(modelReset()), this, SLOT(_q_sourceReset()));
d->clear_mapping();
diff --git a/src/gui/itemviews/qsortfilterproxymodel.h b/src/gui/itemviews/qsortfilterproxymodel.h
index 12baa19eb4..0314aec8ba 100644
--- a/src/gui/itemviews/qsortfilterproxymodel.h
+++ b/src/gui/itemviews/qsortfilterproxymodel.h
@@ -177,6 +177,7 @@ private:
Q_PRIVATE_SLOT(d_func(), void _q_sourceDataChanged(const QModelIndex &source_top_left, const QModelIndex &source_bottom_right))
Q_PRIVATE_SLOT(d_func(), void _q_sourceHeaderDataChanged(Qt::Orientation orientation, int start, int end))
+ Q_PRIVATE_SLOT(d_func(), void _q_sourceAboutToBeReset())
Q_PRIVATE_SLOT(d_func(), void _q_sourceReset())
Q_PRIVATE_SLOT(d_func(), void _q_sourceLayoutAboutToBeChanged())
Q_PRIVATE_SLOT(d_func(), void _q_sourceLayoutChanged())