diff options
| author | Peter Penz <[email protected]> | 2012-03-20 13:22:12 +0100 |
|---|---|---|
| committer | Peter Penz <[email protected]> | 2012-03-20 17:23:27 +0100 |
| commit | 0dcb51b927f70afa6cba0b9185abb1f323052696 (patch) | |
| tree | 55aaa4e94cf24f03c3e967a63f4db28608c33caa | |
| parent | 5798e081f52371b9fd91cf0348cc946ebcc28a4a (diff) | |
Fix alternate background issue
When items get inserted or deleted, the alternate background
must be updated.
| -rw-r--r-- | src/kitemviews/kitemlistview.cpp | 46 | ||||
| -rw-r--r-- | src/kitemviews/kitemlistview.h | 6 |
2 files changed, 33 insertions, 19 deletions
diff --git a/src/kitemviews/kitemlistview.cpp b/src/kitemviews/kitemlistview.cpp index d7777b541..678b09bff 100644 --- a/src/kitemviews/kitemlistview.cpp +++ b/src/kitemviews/kitemlistview.cpp @@ -157,21 +157,17 @@ void KItemListView::setItemSize(const QSizeF& itemSize) itemSize, m_layouter->itemMargin()); - const bool updateAlternateBackgrounds = (m_visibleRoles.count() > 1) && - (( m_itemSize.isEmpty() && !itemSize.isEmpty()) || - (!m_itemSize.isEmpty() && itemSize.isEmpty())); + const bool alternateBackgroundsChanged = (m_visibleRoles.count() > 1) && + (( m_itemSize.isEmpty() && !itemSize.isEmpty()) || + (!m_itemSize.isEmpty() && itemSize.isEmpty())); m_itemSize = itemSize; - if (updateAlternateBackgrounds) { + if (alternateBackgroundsChanged) { // For an empty item size alternate backgrounds are drawn if more than // one role is shown. Assure that the backgrounds for visible items are // updated when changing the size in this context. - QHashIterator<int, KItemListWidget*> it(m_visibleItems); - while (it.hasNext()) { - it.next(); - updateAlternateBackgroundForWidget(it.value()); - } + updateAlternateBackgrounds(); } if (itemSize.isEmpty()) { @@ -253,9 +249,9 @@ void KItemListView::setVisibleRoles(const QList<QByteArray>& roles) const QList<QByteArray> previousRoles = m_visibleRoles; m_visibleRoles = roles; - const bool updateAlternateBackgrounds = m_itemSize.isEmpty() && - ((roles.count() > 1 && previousRoles.count() <= 1) || - (roles.count() <= 1 && previousRoles.count() > 1)); + const bool alternateBackgroundsChanged = m_itemSize.isEmpty() && + ((roles.count() > 1 && previousRoles.count() <= 1) || + (roles.count() <= 1 && previousRoles.count() > 1)); QHashIterator<int, KItemListWidget*> it(m_visibleItems); while (it.hasNext()) { @@ -263,7 +259,7 @@ void KItemListView::setVisibleRoles(const QList<QByteArray>& roles) KItemListWidget* widget = it.value(); widget->setVisibleRoles(roles); widget->setVisibleRolesSizes(m_stretchedVisibleRolesSizes); - if (updateAlternateBackgrounds) { + if (alternateBackgroundsChanged) { updateAlternateBackgroundForWidget(widget); } } @@ -898,6 +894,10 @@ void KItemListView::slotItemsInserted(const KItemRangeList& itemRanges) endTransaction(); updateSiblingsInformation(); } + + if (useAlternateBackgrounds()) { + updateAlternateBackgrounds(); + } } void KItemListView::slotItemsRemoved(const KItemRangeList& itemRanges) @@ -999,6 +999,10 @@ void KItemListView::slotItemsRemoved(const KItemRangeList& itemRanges) endTransaction(); updateSiblingsInformation(); } + + if (useAlternateBackgrounds()) { + updateAlternateBackgrounds(); + } } void KItemListView::slotItemsMoved(const KItemRange& itemRange, const QList<int>& movedToIndexes) @@ -1085,13 +1089,8 @@ void KItemListView::slotGroupedSortingChanged(bool current) // Changing the group mode requires to update the alternate backgrounds // as with the enabled group mode the altering is done on base of the first // group item. - QHashIterator<int, KItemListWidget*> it(m_visibleItems); - while (it.hasNext()) { - it.next(); - updateAlternateBackgroundForWidget(it.value()); - } + updateAlternateBackgrounds(); } - updateSiblingsInformation(); doLayout(NoAnimation); } @@ -1875,6 +1874,15 @@ int KItemListView::groupIndexForItem(int index) const return mid; } +void KItemListView::updateAlternateBackgrounds() +{ + QHashIterator<int, KItemListWidget*> it(m_visibleItems); + while (it.hasNext()) { + it.next(); + updateAlternateBackgroundForWidget(it.value()); + } +} + void KItemListView::updateAlternateBackgroundForWidget(KItemListWidget* widget) { bool enabled = useAlternateBackgrounds(); diff --git a/src/kitemviews/kitemlistview.h b/src/kitemviews/kitemlistview.h index 8f6e11e38..bbdb4081c 100644 --- a/src/kitemviews/kitemlistview.h +++ b/src/kitemviews/kitemlistview.h @@ -499,6 +499,12 @@ private: int groupIndexForItem(int index) const; /** + * Updates the alternate background for all visible items. + * @see updateAlternateBackgroundForWidget() + */ + void updateAlternateBackgrounds(); + + /** * Updates the alternateBackground-property of the widget dependent * on the state of useAlternateBackgrounds() and the grouping state. */ |
