diff options
| author | Peter Penz <[email protected]> | 2012-05-01 23:11:06 +0200 |
|---|---|---|
| committer | Peter Penz <[email protected]> | 2012-05-01 23:14:52 +0200 |
| commit | d76b113ad10fe207ef23d5dd44c63ee076c71521 (patch) | |
| tree | 2cda5384e4036f4f048392548ea75243ce6b7fc2 /src/panels/places/placesitemmodel.cpp | |
| parent | 6a7cb5ff7d29cc636b432a96e0db9ef9f9030527 (diff) | |
Places Panel: Allow hiding of items
Related changes:
- Animate changed items for the details-view in case it is not expandable
- Remove the hardcoded "isHidden"-code in KStandardItemListWidget and
allow derived widgets to define themselves what means "hidden" within
their context.
The current code needs a lot of bugfixing, but lets make this in smaller
steps during the next days...
Diffstat (limited to 'src/panels/places/placesitemmodel.cpp')
| -rw-r--r-- | src/panels/places/placesitemmodel.cpp | 66 |
1 files changed, 63 insertions, 3 deletions
diff --git a/src/panels/places/placesitemmodel.cpp b/src/panels/places/placesitemmodel.cpp index 023e873eb..060c77f81 100644 --- a/src/panels/places/placesitemmodel.cpp +++ b/src/panels/places/placesitemmodel.cpp @@ -52,7 +52,8 @@ PlacesItemModel::PlacesItemModel(QObject* parent) : m_availableDevices(), m_bookmarkManager(0), m_systemBookmarks(), - m_systemBookmarksIndexes() + m_systemBookmarksIndexes(), + m_hiddenItems() { #ifdef HAVE_NEPOMUK m_nepomukRunning = (Nepomuk::ResourceManager::instance()->initialized()); @@ -66,11 +67,40 @@ PlacesItemModel::PlacesItemModel(QObject* parent) : PlacesItemModel::~PlacesItemModel() { + qDeleteAll(m_hiddenItems); + m_hiddenItems.clear(); } int PlacesItemModel::hiddenCount() const { - return 0; + int itemCount = 0; + foreach (const KStandardItem* item, m_hiddenItems) { + if (item) { + ++itemCount; + } + } + + return itemCount; +} + +void PlacesItemModel::setItemHidden(int index, bool hide) +{ + if (index >= 0 && index < count()) { + KStandardItem* shownItem = this->item(index); + shownItem->setDataValue("isHidden", hide); + if (!m_hiddenItemsShown && hide) { + KStandardItem* hiddenItem = new KStandardItem(*shownItem); + removeItem(index); + index = hiddenIndex(index); + Q_ASSERT(!m_hiddenItems[index]); + m_hiddenItems[index] = hiddenItem; + } + } +} + +bool PlacesItemModel::isItemHidden(int index) const +{ + return (index >= 0 && index < count()) ? m_hiddenItems[index] != 0 : false; } void PlacesItemModel::setHiddenItemsShown(bool show) @@ -140,6 +170,18 @@ QAction* PlacesItemModel::tearDownAction(int index) const return 0; } +void PlacesItemModel::onItemInserted(int index) +{ + m_hiddenItems.insert(hiddenIndex(index), 0); +} + +void PlacesItemModel::onItemRemoved(int index) +{ + const int removeIndex = hiddenIndex(index); + Q_ASSERT(!m_hiddenItems[removeIndex]); + m_hiddenItems.removeAt(removeIndex); +} + void PlacesItemModel::loadBookmarks() { KBookmarkGroup root = m_bookmarkManager->root(); @@ -187,7 +229,11 @@ void PlacesItemModel::loadBookmarks() item->setGroup(i18nc("@item", "Places")); } - appendItem(item); + if (bookmark.metaDataItem("IsHidden") == QLatin1String("true")) { + m_hiddenItems.append(item); + } else { + appendItem(item); + } } bookmark = root.next(bookmark); @@ -276,6 +322,20 @@ void PlacesItemModel::createSystemBookmarks() } } +int PlacesItemModel::hiddenIndex(int index) const +{ + int hiddenIndex = 0; + int visibleItemIndex = 0; + while (visibleItemIndex < index && hiddenIndex < m_hiddenItems.count()) { + if (!m_hiddenItems[hiddenIndex]) { + ++visibleItemIndex; + } + ++hiddenIndex; + } + + return hiddenIndex; +} + QString PlacesItemModel::placesGroupName() { return i18nc("@item", "Places"); |
