summaryrefslogtreecommitdiffstats
path: root/src/gui/itemviews
diff options
context:
space:
mode:
authorThierry Bastian <thierry.bastian@nokia.com>2010-03-15 13:35:15 (GMT)
committerThierry Bastian <thierry.bastian@nokia.com>2010-03-15 14:10:28 (GMT)
commit378a82e8965f841f6f712a2f1725554f577e568a (patch)
tree20d5cc90ea4517e6eb3b19b7eb0a3aea99f162d3 /src/gui/itemviews
parent8e98c4c159c38ea48b6321674105762b2d3f517b (diff)
downloadQt-378a82e8965f841f6f712a2f1725554f577e568a.zip
Qt-378a82e8965f841f6f712a2f1725554f577e568a.tar.gz
Qt-378a82e8965f841f6f712a2f1725554f577e568a.tar.bz2
Fix a crash in QSortFilterProxyModel when deleting a row
...while changing data. Reviewed-By: gabi Task-Number: QTBUG-8841
Diffstat (limited to 'src/gui/itemviews')
-rw-r--r--src/gui/itemviews/qsortfilterproxymodel.cpp34
1 files changed, 33 insertions, 1 deletions
diff --git a/src/gui/itemviews/qsortfilterproxymodel.cpp b/src/gui/itemviews/qsortfilterproxymodel.cpp
index 5c7d24b7..c6ad345 100644
--- a/src/gui/itemviews/qsortfilterproxymodel.cpp
+++ b/src/gui/itemviews/qsortfilterproxymodel.cpp
@@ -111,6 +111,35 @@ private:
};
+//this struct is used to store what are the rows that are removed
+//between a call to rowsAboutToBeRemoved and rowsRemoved
+//it avoids readding rows to the mapping that are currently being removed
+struct QRowsRemoval
+{
+ QRowsRemoval(const QModelIndex &parent_source, int start, int end) : parent_source(parent_source), start(start), end(end)
+ {
+ }
+
+ QRowsRemoval() : start(-1), end(-1)
+ {
+ }
+
+ bool contains(QModelIndex parent, int row)
+ {
+ do {
+ if (parent == parent_source)
+ return row >= start && row <= end;
+ row = parent.row();
+ parent = parent.parent();
+ } while (row >= 0);
+ return false;
+ }
+private:
+ QModelIndex parent_source;
+ int start;
+ int end;
+};
+
class QSortFilterProxyModelPrivate : public QAbstractProxyModelPrivate
{
Q_DECLARE_PUBLIC(QSortFilterProxyModel)
@@ -139,6 +168,7 @@ public:
int filter_role;
bool dynamic_sortfilter;
+ QRowsRemoval itemsBeingRemoved;
QModelIndexPairList saved_persistent_indexes;
@@ -1096,7 +1126,7 @@ void QSortFilterProxyModelPrivate::_q_sourceDataChanged(const QModelIndex &sourc
source_rows_change.append(source_row);
}
} else {
- if (q->filterAcceptsRow(source_row, source_parent)) {
+ if (!itemsBeingRemoved.contains(source_parent, source_row) && q->filterAcceptsRow(source_row, source_parent)) {
// This source row now satisfies the filter, so it must be added
source_rows_insert.append(source_row);
}
@@ -1253,6 +1283,7 @@ void QSortFilterProxyModelPrivate::_q_sourceRowsInserted(
void QSortFilterProxyModelPrivate::_q_sourceRowsAboutToBeRemoved(
const QModelIndex &source_parent, int start, int end)
{
+ itemsBeingRemoved = QRowsRemoval(source_parent, start, end);
source_items_about_to_be_removed(source_parent, start, end,
Qt::Vertical);
}
@@ -1260,6 +1291,7 @@ void QSortFilterProxyModelPrivate::_q_sourceRowsAboutToBeRemoved(
void QSortFilterProxyModelPrivate::_q_sourceRowsRemoved(
const QModelIndex &source_parent, int start, int end)
{
+ itemsBeingRemoved = QRowsRemoval();
source_items_removed(source_parent, start, end, Qt::Vertical);
}