]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Places Panel: Allow showing of hidden items
authorPeter Penz <peter.penz19@gmail.com>
Wed, 2 May 2012 21:56:22 +0000 (23:56 +0200)
committerPeter Penz <peter.penz19@gmail.com>
Wed, 2 May 2012 21:57:04 +0000 (23:57 +0200)
src/kitemviews/kitemlistview.cpp
src/kitemviews/kstandarditem.cpp
src/kitemviews/kstandarditemlistwidget.cpp
src/kitemviews/kstandarditemmodel.cpp
src/kitemviews/kstandarditemmodel.h
src/panels/places/placesitemmodel.cpp
src/panels/places/placespanel.cpp

index a3fc2bafce69187cc1fc88dc179d46a2e7d50840..4bcdab1058f520c876ffd74f85eece37b98cbe9f 100644 (file)
@@ -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
index e7655f9c8113b50d68ab53c4277c61fc8b9e90de..cce1dece1bc8a5ef4c99e2898f8e5a3112813d57 100644 (file)
@@ -20,6 +20,7 @@
 #include "kstandarditem.h"
 
 #include <KDebug>
+#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<QByteArray> changedRoles;
+        changedRoles.insert(role);
+        emit m_model->itemsChanged(KItemRangeList() << KItemRange(index, 1), changedRoles);
+    }
 }
 
 QVariant KStandardItem::dataValue(const QByteArray& role) const
index 14a3db066616f675640acffae6ad0d779f49a20a..3f470b8cf5097944bc9ca8be34e5433c7a2f34c1 100644 (file)
@@ -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<QByteArray, QVariant>& cur
     QSet<QByteArray> 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<QByteArray> it(dirtyRoles);
     while (it.hasNext()) {
         const QByteArray& role = it.next();
index d0be1325f7b288c436196bf56b096f5aa8fbce2e..ffacd3c596d83a1bf7338e101ce37529e0629913 100644 (file)
@@ -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<QByteArray> changedRoles;
index d1a036fd09329ec6962aa79a4ea3b147f48f3074..510342a818bccf8de32b27ab908dbe09c991dfc3 100644 (file)
@@ -98,6 +98,8 @@ protected:
 private:
     QList<KStandardItem*> m_items;
     QHash<const KStandardItem*, int> m_indexesForItems;
+
+    friend class KStandardItem;
 };
 
 #endif
index d6569ef2d3f4a6dac960f7c4cf11f1c1c2f9e267..4fb85dea095daa5bc9209f558a9e029d78c79f67 100644 (file)
@@ -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)
index dc0f2b8baa9865a95f4ebbb0ea2631791accc034..89b4b4a319712bc6b657762d44f3aa83ad48495a 100644 (file)
@@ -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();