From: Peter Penz Date: Wed, 2 May 2012 21:56:22 +0000 (+0200) Subject: Places Panel: Allow showing of hidden items X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/aacf20282d9b7d78bda93ba946cdcf2e0fee5692 Places Panel: Allow showing of hidden items --- diff --git a/src/kitemviews/kitemlistview.cpp b/src/kitemviews/kitemlistview.cpp index a3fc2bafc..4bcdab105 100644 --- a/src/kitemviews/kitemlistview.cpp +++ b/src/kitemviews/kitemlistview.cpp @@ -922,6 +922,13 @@ void KItemListView::slotItemsInserted(const KItemRangeList& itemRanges) } } + // In case if items of the same group have been inserted before an item that + // currently represents the first item of the group, the group header of + // this item must be removed. + if (m_grouped && index + count < m_model->count()) { + updateGroupHeaderForWidget(m_visibleItems.value(index + count)); + } + if (m_model->count() == count && m_activeTransactions == 0) { // Check whether a scrollbar is required to show the inserted items. In this case // the size of the layouter will be decreased before calling doLayout(): This prevents diff --git a/src/kitemviews/kstandarditem.cpp b/src/kitemviews/kstandarditem.cpp index e7655f9c8..cce1dece1 100644 --- a/src/kitemviews/kstandarditem.cpp +++ b/src/kitemviews/kstandarditem.cpp @@ -20,6 +20,7 @@ #include "kstandarditem.h" #include +#include "kstandarditemmodel.h" KStandardItem::KStandardItem(KStandardItem* parent) : m_parent(parent), @@ -62,7 +63,7 @@ KStandardItem::~KStandardItem() void KStandardItem::setText(const QString& text) { - m_data.insert("text", text); + setDataValue("text", text); } QString KStandardItem::text() const @@ -72,7 +73,7 @@ QString KStandardItem::text() const void KStandardItem::setIcon(const QIcon& icon) { - m_data.insert("iconName", icon.name()); + setDataValue("iconName", icon.name()); } QIcon KStandardItem::icon() const @@ -82,7 +83,7 @@ QIcon KStandardItem::icon() const void KStandardItem::setGroup(const QString& group) { - m_data.insert("group", group); + setDataValue("group", group); } QString KStandardItem::group() const @@ -93,6 +94,12 @@ QString KStandardItem::group() const void KStandardItem::setDataValue(const QByteArray& role, const QVariant& value) { m_data.insert(role, value); + if (m_model) { + const int index = m_model->index(this); + QSet changedRoles; + changedRoles.insert(role); + emit m_model->itemsChanged(KItemRangeList() << KItemRange(index, 1), changedRoles); + } } QVariant KStandardItem::dataValue(const QByteArray& role) const diff --git a/src/kitemviews/kstandarditemlistwidget.cpp b/src/kitemviews/kstandarditemlistwidget.cpp index 14a3db066..3f470b8cf 100644 --- a/src/kitemviews/kstandarditemlistwidget.cpp +++ b/src/kitemviews/kstandarditemlistwidget.cpp @@ -259,7 +259,7 @@ void KStandardItemListWidget::paint(QPainter* painter, const QStyleOptionGraphic } painter->setFont(itemListStyleOption.font); - painter->setPen(textColor()); + painter->setPen(m_isHidden ? m_additionalInfoTextColor : textColor()); const TextInfo* textInfo = m_textInfo.value("text"); painter->drawStaticText(textInfo->pos, textInfo->staticText); @@ -480,12 +480,15 @@ void KStandardItemListWidget::dataChanged(const QHash& cur QSet dirtyRoles; if (roles.isEmpty()) { dirtyRoles = visibleRoles().toSet(); - dirtyRoles.insert("iconPixmap"); - dirtyRoles.insert("iconName"); } else { dirtyRoles = roles; } + // The icon-state might depend from other roles and hence is + // marked as dirty whenever a role has been changed + dirtyRoles.insert("iconPixmap"); + dirtyRoles.insert("iconName"); + QSetIterator it(dirtyRoles); while (it.hasNext()) { const QByteArray& role = it.next(); diff --git a/src/kitemviews/kstandarditemmodel.cpp b/src/kitemviews/kstandarditemmodel.cpp index d0be1325f..ffacd3c59 100644 --- a/src/kitemviews/kstandarditemmodel.cpp +++ b/src/kitemviews/kstandarditemmodel.cpp @@ -38,7 +38,7 @@ KStandardItemModel::~KStandardItemModel() void KStandardItemModel::insertItem(int index, KStandardItem* item) { - if (item && !m_indexesForItems.contains(item) && !item->m_model) { + if (item && !m_indexesForItems.contains(item)) { item->m_model = this; m_items.insert(index, item); m_indexesForItems.insert(item, index); @@ -51,7 +51,7 @@ void KStandardItemModel::insertItem(int index, KStandardItem* item) void KStandardItemModel::replaceItem(int index, KStandardItem* item) { - if (item && index >= 0 && index < count() && !item->m_model) { + if (item && index >= 0 && index < count()) { item->m_model = this; QSet changedRoles; diff --git a/src/kitemviews/kstandarditemmodel.h b/src/kitemviews/kstandarditemmodel.h index d1a036fd0..510342a81 100644 --- a/src/kitemviews/kstandarditemmodel.h +++ b/src/kitemviews/kstandarditemmodel.h @@ -98,6 +98,8 @@ protected: private: QList m_items; QHash m_indexesForItems; + + friend class KStandardItem; }; #endif diff --git a/src/panels/places/placesitemmodel.cpp b/src/panels/places/placesitemmodel.cpp index d6569ef2d..4fb85dea0 100644 --- a/src/panels/places/placesitemmodel.cpp +++ b/src/panels/places/placesitemmodel.cpp @@ -73,10 +73,16 @@ PlacesItemModel::~PlacesItemModel() int PlacesItemModel::hiddenCount() const { + int modelIndex = 0; int itemCount = 0; - foreach (const KStandardItem* item, m_hiddenItems) { - if (item) { + foreach (const KStandardItem* hiddenItem, m_hiddenItems) { + if (hiddenItem) { ++itemCount; + } else { + if (item(modelIndex)->dataValue("isHidden").toBool()) { + ++itemCount; + } + ++modelIndex; } } @@ -108,9 +114,31 @@ bool PlacesItemModel::isItemHidden(int index) const void PlacesItemModel::setHiddenItemsShown(bool show) { - if (m_hiddenItemsShown != show) { - m_hiddenItemsShown = show; + if (m_hiddenItemsShown == show) { + return; + } + + m_hiddenItemsShown = show; + + if (show) { + int modelIndex = 0; + for (int hiddenIndex = 0; hiddenIndex < m_hiddenItems.count(); ++hiddenIndex) { + if (m_hiddenItems[hiddenIndex]) { + KStandardItem* visibleItem = new KStandardItem(*m_hiddenItems[hiddenIndex]); + delete m_hiddenItems[hiddenIndex]; + m_hiddenItems.removeAt(hiddenIndex); + insertItem(modelIndex, visibleItem); + Q_ASSERT(!m_hiddenItems[hiddenIndex]); + } + ++modelIndex; + } + } else { + } +#ifdef PLACESITEMMODEL_DEBUG + kDebug() << "Changed visibility of hidden items"; + showModelState(); +#endif } bool PlacesItemModel::hiddenItemsShown() const @@ -175,11 +203,24 @@ QAction* PlacesItemModel::tearDownAction(int index) const void PlacesItemModel::onItemInserted(int index) { - if (index == count() - 1) { - m_hiddenItems.append(0); - } else { - m_hiddenItems.insert(hiddenIndex(index), 0); + int modelIndex = 0; + int hiddenIndex = 0; + while (hiddenIndex < m_hiddenItems.count()) { + if (!m_hiddenItems[hiddenIndex]) { + ++modelIndex; + if (modelIndex + 1 == index) { + ++hiddenIndex; + break; + } + } + ++hiddenIndex; } + m_hiddenItems.insert(hiddenIndex, 0); + +#ifdef PLACESITEMMODEL_DEBUG + kDebug() << "Inserted item" << index; + showModelState(); +#endif } void PlacesItemModel::onItemRemoved(int index) diff --git a/src/panels/places/placespanel.cpp b/src/panels/places/placespanel.cpp index dc0f2b8ba..89b4b4a31 100644 --- a/src/panels/places/placespanel.cpp +++ b/src/panels/places/placespanel.cpp @@ -218,14 +218,26 @@ void PlacesPanel::slotViewContextMenuRequested(const QPointF& pos) KMenu menu(this); QAction* addAction = menu.addAction(KIcon("document-new"), i18nc("@item:inmenu", "Add Entry...")); + + QAction* showAllAction = 0; + if (m_model->hiddenCount() > 0) { + showAllAction = menu.addAction(i18nc("@item:inmenu", "Show All Entries")); + showAllAction->setCheckable(true); + showAllAction->setChecked(m_model->hiddenItemsShown()); + } + menu.addSeparator(); foreach (QAction* action, customContextMenuActions()) { menu.addAction(action); } QAction* action = menu.exec(pos.toPoint()); - if (action == addAction) { - addEntry(); + if (action) { + if (action == addAction) { + addEntry(); + } else if (action == showAllAction) { + m_model->setHiddenItemsShown(showAllAction->isChecked()); + } } selectClosestItem();