aboutsummaryrefslogtreecommitdiff
path: root/libqmenumodel/src
diff options
context:
space:
mode:
authorOlivier Tilloy <olivier.tilloy@canonical.com>2012-12-04 09:21:06 +0100
committerOlivier Tilloy <olivier.tilloy@canonical.com>2012-12-04 09:21:06 +0100
commit395a8c64acee78f206b021b3218de4641c4d95d6 (patch)
tree7f9d1e4612ddfa7957e20d51132314b370eecb1c /libqmenumodel/src
parent02cfba5c7f3781bb2d7cd2a4a55948efa4ed7918 (diff)
downloadqmenumodel-395a8c64acee78f206b021b3218de4641c4d95d6.tar.gz
qmenumodel-395a8c64acee78f206b021b3218de4641c4d95d6.tar.bz2
qmenumodel-395a8c64acee78f206b021b3218de4641c4d95d6.zip
Add comments to explain non-trivial cache updates.
Diffstat (limited to 'libqmenumodel/src')
-rw-r--r--libqmenumodel/src/qmenumodel.cpp3
1 files changed, 3 insertions, 0 deletions
diff --git a/libqmenumodel/src/qmenumodel.cpp b/libqmenumodel/src/qmenumodel.cpp
index e9f6acc..1326d77 100644
--- a/libqmenumodel/src/qmenumodel.cpp
+++ b/libqmenumodel/src/qmenumodel.cpp
@@ -292,11 +292,13 @@ void QMenuModel::onItemsChanged(GMenuModel *model,
int prevcount = g_menu_model_get_n_items(model) + removed - added;
if (removed > 0) {
self->beginRemoveRows(QModelIndex(), position, position + removed - 1);
+ // Remove invalidated menus from the cache
for (int i = position, iMax = position + removed; i < iMax; ++i) {
if (cache->contains(i)) {
delete cache->take(i);
}
}
+ // Update the indexes of other cached menus to account for the removals
for (int i = position + removed; i < prevcount; ++i) {
if (cache->contains(i)) {
cache->insert(i - removed, cache->take(i));
@@ -307,6 +309,7 @@ void QMenuModel::onItemsChanged(GMenuModel *model,
if (added > 0) {
self->beginInsertRows(QModelIndex(), position, position + added - 1);
+ // Update the indexes of cached menus to account for the insertions
for (int i = prevcount - removed - 1; i >= position; --i) {
if (cache->contains(i)) {
cache->insert(i + added, cache->take(i));