┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/panels/places/placesitemmodel.cpp
diff options
context:
space:
mode:
authorPeter Penz <[email protected]>2012-05-02 21:23:38 +0200
committerPeter Penz <[email protected]>2012-05-02 21:24:16 +0200
commitf158bf097a079cba181afa9ecc03e5eb20f3573a (patch)
treef7780c7a2366a42745b4de0cabfde23e92a3f321 /src/panels/places/placesitemmodel.cpp
parentd76b113ad10fe207ef23d5dd44c63ee076c71521 (diff)
Places Panel: Fix implementation issues when hiding items
Diffstat (limited to 'src/panels/places/placesitemmodel.cpp')
-rw-r--r--src/panels/places/placesitemmodel.cpp47
1 files changed, 41 insertions, 6 deletions
diff --git a/src/panels/places/placesitemmodel.cpp b/src/panels/places/placesitemmodel.cpp
index 060c77f81..d6569ef2d 100644
--- a/src/panels/places/placesitemmodel.cpp
+++ b/src/panels/places/placesitemmodel.cpp
@@ -89,12 +89,15 @@ void PlacesItemModel::setItemHidden(int index, bool hide)
KStandardItem* shownItem = this->item(index);
shownItem->setDataValue("isHidden", hide);
if (!m_hiddenItemsShown && hide) {
+ const int newIndex = hiddenIndex(index);
KStandardItem* hiddenItem = new KStandardItem(*shownItem);
removeItem(index);
- index = hiddenIndex(index);
- Q_ASSERT(!m_hiddenItems[index]);
- m_hiddenItems[index] = hiddenItem;
+ m_hiddenItems.insert(newIndex, hiddenItem);
}
+#ifdef PLACESITEMMODEL_DEBUG
+ kDebug() << "Changed hide-state from" << index << "to" << hide;
+ showModelState();
+#endif
}
}
@@ -172,7 +175,11 @@ QAction* PlacesItemModel::tearDownAction(int index) const
void PlacesItemModel::onItemInserted(int index)
{
- m_hiddenItems.insert(hiddenIndex(index), 0);
+ if (index == count() - 1) {
+ m_hiddenItems.append(0);
+ } else {
+ m_hiddenItems.insert(hiddenIndex(index), 0);
+ }
}
void PlacesItemModel::onItemRemoved(int index)
@@ -180,6 +187,10 @@ void PlacesItemModel::onItemRemoved(int index)
const int removeIndex = hiddenIndex(index);
Q_ASSERT(!m_hiddenItems[removeIndex]);
m_hiddenItems.removeAt(removeIndex);
+#ifdef PLACESITEMMODEL_DEBUG
+ kDebug() << "Removed item" << index;
+ showModelState();
+#endif
}
void PlacesItemModel::loadBookmarks()
@@ -251,6 +262,11 @@ void PlacesItemModel::loadBookmarks()
}
}
}
+
+#ifdef PLACESITEMMODEL_DEBUG
+ kDebug() << "Loaded bookmarks";
+ showModelState();
+#endif
}
void PlacesItemModel::createSystemBookmarks()
@@ -326,14 +342,17 @@ int PlacesItemModel::hiddenIndex(int index) const
{
int hiddenIndex = 0;
int visibleItemIndex = 0;
- while (visibleItemIndex < index && hiddenIndex < m_hiddenItems.count()) {
+ while (hiddenIndex < m_hiddenItems.count()) {
if (!m_hiddenItems[hiddenIndex]) {
+ if (visibleItemIndex == index) {
+ break;
+ }
++visibleItemIndex;
}
++hiddenIndex;
}
- return hiddenIndex;
+ return hiddenIndex >= m_hiddenItems.count() ? -1 : hiddenIndex;
}
QString PlacesItemModel::placesGroupName()
@@ -445,4 +464,20 @@ KUrl PlacesItemModel::searchUrlForTerm(const Nepomuk::Query::Term& term)
}
#endif
+#ifdef PLACESITEMMODEL_DEBUG
+void PlacesItemModel::showModelState()
+{
+ kDebug() << "hidden-index model-index text";
+ int j = 0;
+ for (int i = 0; i < m_hiddenItems.count(); ++i) {
+ if (m_hiddenItems[i]) {
+ kDebug() << i << "(Hidden) " << " " << m_hiddenItems[i]->dataValue("text").toString();
+ } else {
+ kDebug() << i << " " << j << " " << item(j)->dataValue("text").toString();
+ ++j;
+ }
+ }
+}
+#endif
+
#include "placesitemmodel.moc"