diff options
| author | Peter Penz <[email protected]> | 2011-12-22 21:46:17 +0100 |
|---|---|---|
| committer | Peter Penz <[email protected]> | 2011-12-22 21:49:53 +0100 |
| commit | e0bbf1bf7115645a3591cdcace96682a10db3054 (patch) | |
| tree | 8bc381323a5875dcfc6ae76084c1e37f28eae1d4 /src | |
| parent | 42c07bebde73f35d20520716101255a29e8fc0c2 (diff) | |
Don't show child items of collapsed parent items
If a parent item got expanded and collapsed again, KDirLister keeps
the items of the previously expanded directory. Hence inserting new
items there will result in emitting the signal newItems() and a check
must be done whether the parent is still expanded.
BUG: 289598
FIXED-IN: 4.8.0
Diffstat (limited to 'src')
| -rw-r--r-- | src/kitemviews/kfileitemmodel.cpp | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/src/kitemviews/kfileitemmodel.cpp b/src/kitemviews/kfileitemmodel.cpp index 8e1943b4b..3d4e65302 100644 --- a/src/kitemviews/kfileitemmodel.cpp +++ b/src/kitemviews/kfileitemmodel.cpp @@ -674,19 +674,31 @@ void KFileItemModel::slotCanceled() void KFileItemModel::slotNewItems(const KFileItemList& items) { + Q_ASSERT(!items.isEmpty()); + if (m_requestRole[ExpansionLevelRole] && m_rootExpansionLevel >= 0) { - // If the expanding of items is enabled in the model, it might be - // possible that the call dirLister->openUrl(url, KDirLister::Keep) in - // KFileItemModel::setExpanded() results in emitting of the same items - // twice due to the Keep-parameter. This case happens if an item gets - // expanded, collapsed and expanded again before the items could be loaded - // for the first expansion. - foreach (const KFileItem& item, items) { - const int index = m_items.value(item.url(), -1); - if (index >= 0) { - // The items are already part of the model. - return; - } + const KFileItem item = items.first(); + + // If the expanding of items is enabled, the call + // dirLister->openUrl(url, KDirLister::Keep) in KFileItemModel::setExpanded() + // might result in emitting the same items twice due to the Keep-parameter. + // This case happens if an item gets expanded, collapsed and expanded again + // before the items could be loaded for the first expansion. + const int index = m_items.value(item.url(), -1); + if (index >= 0) { + // The items are already part of the model. + return; + } + + // KDirLister keeps the children of items that got expanded once even if + // they got collapsed again with KFileItemModel::setExpanded(false). So it must be + // checked whether the parent for new items is still expanded. + KUrl parentUrl = item.url().upUrl(); + parentUrl.adjustPath(KUrl::RemoveTrailingSlash); + const int parentIndex = m_items.value(parentUrl, -1); + if (parentIndex >= 0 && !m_itemData[parentIndex]->values.value("isExpanded").toBool()) { + // The parent is not expanded. + return; } } |
