┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPeter Penz <[email protected]>2012-05-17 13:32:09 +0200
committerPeter Penz <[email protected]>2012-05-17 13:34:31 +0200
commitbd02faa982c263205b5cc21d6ceb4225a83c76b5 (patch)
tree118e378ba865ed6d6c66637568d9035c1eb9deb4 /src
parentbca055a38edf722c2433c41cd45f86c27fccc541 (diff)
KStandardItemModel: Fix inconsistent internal state
Assure that the index-cache is kept consistent with the items when a removing or inserting is done. A unit-test will be created as soon as possible.
Diffstat (limited to 'src')
-rw-r--r--src/kitemviews/kstandarditemmodel.cpp16
-rw-r--r--src/panels/places/placesitemmodel.cpp6
2 files changed, 17 insertions, 5 deletions
diff --git a/src/kitemviews/kstandarditemmodel.cpp b/src/kitemviews/kstandarditemmodel.cpp
index e3d40038d..11d72a4ac 100644
--- a/src/kitemviews/kstandarditemmodel.cpp
+++ b/src/kitemviews/kstandarditemmodel.cpp
@@ -42,6 +42,13 @@ void KStandardItemModel::insertItem(int index, KStandardItem* item)
item->m_model = this;
m_items.insert(index, item);
m_indexesForItems.insert(item, index);
+
+ // Inserting an item requires to update the indexes
+ // afterwards from m_indexesForItems.
+ for (int i = index + 1; i < m_items.count(); ++i) {
+ m_indexesForItems.insert(m_items[i], i);
+ }
+
// TODO: no hierarchical items are handled yet
onItemInserted(index);
@@ -94,12 +101,19 @@ void KStandardItemModel::removeItem(int index)
m_indexesForItems.remove(item);
m_items.removeAt(index);
+ // Removing an item requires to update the indexes
+ // afterwards from m_indexesForItems.
+ for (int i = index; i < m_items.count(); ++i) {
+ m_indexesForItems.insert(m_items[i], i);
+ }
+
onItemRemoved(index, item);
- emit itemsRemoved(KItemRangeList() << KItemRange(index, 1));
delete item;
item = 0;
+ emit itemsRemoved(KItemRangeList() << KItemRange(index, 1));
+
// TODO: no hierarchical items are handled yet
}
}
diff --git a/src/panels/places/placesitemmodel.cpp b/src/panels/places/placesitemmodel.cpp
index 21cbf9ed3..14ec54be8 100644
--- a/src/panels/places/placesitemmodel.cpp
+++ b/src/panels/places/placesitemmodel.cpp
@@ -395,7 +395,7 @@ void PlacesItemModel::onItemChanged(int index, const QSet<QByteArray>& changedRo
{
const PlacesItem* changedItem = placesItem(index);
if (changedItem) {
- // Take care to apply the PlacesItemModel-order of the inserted item
+ // Take care to apply the PlacesItemModel-order of the changed item
// also to the bookmark-manager.
const KBookmark insertedBookmark = changedItem->bookmark();
@@ -409,9 +409,7 @@ void PlacesItemModel::onItemChanged(int index, const QSet<QByteArray>& changedRo
}
if (changedRoles.contains("isHidden")) {
- const PlacesItem* shownItem = placesItem(index);
- Q_ASSERT(shownItem);
- if (!m_hiddenItemsShown && shownItem->isHidden()) {
+ if (!m_hiddenItemsShown && changedItem->isHidden()) {
m_hiddenItemToRemove = index;
QTimer::singleShot(0, this, SLOT(hideItem()));
}