summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@trolltech.com>2009-06-10 16:42:35 (GMT)
committerOlivier Goffart <ogoffart@trolltech.com>2009-06-11 10:57:35 (GMT)
commite0be99974d5d66f548543df9b5b919c8e81ade62 (patch)
tree598eb58063f035968b3c8d918eb7f6194cf47cb0 /src
parenta6eac57ee46c150aabd5cff331d6859e7999680f (diff)
downloadQt-e0be99974d5d66f548543df9b5b919c8e81ade62.zip
Qt-e0be99974d5d66f548543df9b5b919c8e81ade62.tar.gz
Qt-e0be99974d5d66f548543df9b5b919c8e81ade62.tar.bz2
Invalid QPersistentIndexes after QStandardItem::takeRow
We need the parent of each potential QPersistentModelIndex in order to cleanup when removing the rows. They need not to change in order QSortFilterProxyModel maping to be still valid. takeRow must not change the internal data before calling beginRemoveRow. Same thing for takeColumn Task-number: 255652 Reviewed-by: Thierry Reviewed-by: Leo
Diffstat (limited to 'src')
-rw-r--r--src/gui/itemviews/qstandarditemmodel.cpp36
1 files changed, 21 insertions, 15 deletions
diff --git a/src/gui/itemviews/qstandarditemmodel.cpp b/src/gui/itemviews/qstandarditemmodel.cpp
index 9d0f796..30daed2 100644
--- a/src/gui/itemviews/qstandarditemmodel.cpp
+++ b/src/gui/itemviews/qstandarditemmodel.cpp
@@ -1742,18 +1742,21 @@ QList<QStandardItem*> QStandardItem::takeRow(int row)
Q_D(QStandardItem);
if ((row < 0) || (row >= rowCount()))
return QList<QStandardItem*>();
+ if (d->model)
+ d->model->d_func()->rowsAboutToBeRemoved(this, row, row);
QList<QStandardItem*> items;
int index = d->childIndex(row, 0);
- for (int column = 0; column < d->columnCount(); ++column) {
- QStandardItem *ch = d->children.at(index);
- if (ch) {
+ int col_count = d->columnCount();
+ for (int column = 0; column < col_count; ++column) {
+ QStandardItem *ch = d->children.at(index + column);
+ if (ch)
ch->d_func()->setParentAndModel(0, 0);
- d->children.replace(index, 0);
- }
items.append(ch);
- ++index;
}
- removeRow(row);
+ d->children.remove(index, col_count);
+ d->rows--;
+ if (d->model)
+ d->model->d_func()->rowsRemoved(this, row, 1);
return items;
}
@@ -1769,18 +1772,21 @@ QList<QStandardItem*> QStandardItem::takeColumn(int column)
Q_D(QStandardItem);
if ((column < 0) || (column >= columnCount()))
return QList<QStandardItem*>();
+ if (d->model)
+ d->model->d_func()->columnsAboutToBeRemoved(this, column, column);
QList<QStandardItem*> items;
- int index = d->childIndex(0, column);
- for (int row = 0; row < d->rowCount(); ++row) {
+
+ for (int row = d->rowCount() - 1; row >= 0; --row) {
+ int index = d->childIndex(row, column);
QStandardItem *ch = d->children.at(index);
- if (ch) {
+ if (ch)
ch->d_func()->setParentAndModel(0, 0);
- d->children.replace(index, 0);
- }
- items.append(ch);
- index += d->columnCount();
+ d->children.remove(index);
+ items.prepend(ch);
}
- removeColumn(column);
+ d->columns--;
+ if (d->model)
+ d->model->d_func()->columnsRemoved(this, column, 1);
return items;
}