diff options
| author | Peter Penz <[email protected]> | 2012-05-02 23:56:22 +0200 |
|---|---|---|
| committer | Peter Penz <[email protected]> | 2012-05-02 23:57:04 +0200 |
| commit | aacf20282d9b7d78bda93ba946cdcf2e0fee5692 (patch) | |
| tree | 738a8680f755b2800bb1921ca1d60a33b75c047b /src/panels | |
| parent | f158bf097a079cba181afa9ecc03e5eb20f3573a (diff) | |
Places Panel: Allow showing of hidden items
Diffstat (limited to 'src/panels')
| -rw-r--r-- | src/panels/places/placesitemmodel.cpp | 57 | ||||
| -rw-r--r-- | src/panels/places/placespanel.cpp | 16 |
2 files changed, 63 insertions, 10 deletions
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(); |
