summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorStephen Kelly <stephen@kdab.com>2010-05-20 11:07:41 (GMT)
committerOlivier Goffart <olivier.goffart@nokia.com>2010-05-20 11:07:41 (GMT)
commit2c1d1c136102a17eef9ae3c4e9f0cf01338306ae (patch)
tree646ad769de11c8d4d3fe42b7c4cb0436149ec490 /src/gui
parent76fcf30c0f275a7c9f9752b1be5cb1d5ba98d9b6 (diff)
downloadQt-2c1d1c136102a17eef9ae3c4e9f0cf01338306ae.zip
Qt-2c1d1c136102a17eef9ae3c4e9f0cf01338306ae.tar.gz
Qt-2c1d1c136102a17eef9ae3c4e9f0cf01338306ae.tar.bz2
Deselect the current selection when the QItemSelectionModel::model is reset.
Merge-request: 639 Reviewed-by: Olivier Goffart <olivier.goffart@nokia.com>
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/itemviews/qitemselectionmodel.cpp25
-rw-r--r--src/gui/itemviews/qitemselectionmodel.h1
-rw-r--r--src/gui/itemviews/qitemselectionmodel_p.h3
3 files changed, 24 insertions, 5 deletions
diff --git a/src/gui/itemviews/qitemselectionmodel.cpp b/src/gui/itemviews/qitemselectionmodel.cpp
index f848321..fc99439 100644
--- a/src/gui/itemviews/qitemselectionmodel.cpp
+++ b/src/gui/itemviews/qitemselectionmodel.cpp
@@ -566,6 +566,8 @@ void QItemSelectionModelPrivate::initModel(QAbstractItemModel *model)
q, SLOT(_q_layoutAboutToBeChanged()));
QObject::connect(model, SIGNAL(layoutChanged()),
q, SLOT(_q_layoutChanged()));
+ QObject::connect(model, SIGNAL(modelAboutToBeReset()),
+ q, SLOT(_q_modelAboutToBeReset()));
}
}
@@ -896,6 +898,13 @@ void QItemSelectionModelPrivate::_q_layoutChanged()
savedPersistentCurrentIndexes.clear();
}
+void QItemSelectionModelPrivate::_q_modelAboutToBeReset()
+{
+ Q_Q(QItemSelectionModel);
+ q->clearSelection();
+ clearCurrentIndex();
+}
+
/*!
\class QItemSelectionModel
@@ -1095,12 +1104,18 @@ void QItemSelectionModel::clear()
{
Q_D(QItemSelectionModel);
clearSelection();
- QModelIndex previous = d->currentIndex;
- d->currentIndex = QModelIndex();
+ d->clearCurrentIndex();
+}
+
+void QItemSelectionModelPrivate::clearCurrentIndex()
+{
+ Q_Q(QItemSelectionModel);
+ QModelIndex previous = currentIndex;
+ currentIndex = QModelIndex();
if (previous.isValid()) {
- emit currentChanged(d->currentIndex, previous);
- emit currentRowChanged(d->currentIndex, previous);
- emit currentColumnChanged(d->currentIndex, previous);
+ emit q->currentChanged(currentIndex, previous);
+ emit q->currentRowChanged(currentIndex, previous);
+ emit q->currentColumnChanged(currentIndex, previous);
}
}
diff --git a/src/gui/itemviews/qitemselectionmodel.h b/src/gui/itemviews/qitemselectionmodel.h
index 436514f..8682109 100644
--- a/src/gui/itemviews/qitemselectionmodel.h
+++ b/src/gui/itemviews/qitemselectionmodel.h
@@ -197,6 +197,7 @@ private:
Q_PRIVATE_SLOT(d_func(), void _q_rowsAboutToBeInserted(const QModelIndex&, int, int))
Q_PRIVATE_SLOT(d_func(), void _q_layoutAboutToBeChanged())
Q_PRIVATE_SLOT(d_func(), void _q_layoutChanged())
+ Q_PRIVATE_SLOT(d_func(), void _q_modelAboutToBeReset())
};
Q_DECLARE_OPERATORS_FOR_FLAGS(QItemSelectionModel::SelectionFlags)
diff --git a/src/gui/itemviews/qitemselectionmodel_p.h b/src/gui/itemviews/qitemselectionmodel_p.h
index 5afa90d..c2fe976 100644
--- a/src/gui/itemviews/qitemselectionmodel_p.h
+++ b/src/gui/itemviews/qitemselectionmodel_p.h
@@ -78,6 +78,7 @@ public:
void _q_columnsAboutToBeInserted(const QModelIndex &parent, int start, int end);
void _q_layoutAboutToBeChanged();
void _q_layoutChanged();
+ void _q_modelAboutToBeReset();
inline void remove(QList<QItemSelectionRange> &r)
{
@@ -93,6 +94,8 @@ public:
currentSelection.clear();
}
+ void clearCurrentIndex();
+
QPointer<QAbstractItemModel> model;
QItemSelection ranges;
QItemSelection currentSelection;