From 69ff0eeb83d4503ec039806688dcad0df3ce541b Mon Sep 17 00:00:00 2001 From: dt <qtc-committer@nokia.com> Date: Wed, 17 Jun 2009 18:53:06 +0200 Subject: [PATCH] Switching sessions didn't clear the bookmark list from old bookmarks. Task-Nr: 255922 --- src/plugins/bookmarks/bookmarkmanager.cpp | 30 +++++++++++++++++++++-- src/plugins/bookmarks/bookmarkmanager.h | 1 + 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/plugins/bookmarks/bookmarkmanager.cpp b/src/plugins/bookmarks/bookmarkmanager.cpp index feb285bdec4..33adc3eb564 100644 --- a/src/plugins/bookmarks/bookmarkmanager.cpp +++ b/src/plugins/bookmarks/bookmarkmanager.cpp @@ -415,8 +415,34 @@ void BookmarkManager::updateBookmark(Bookmark *bookmark) saveBookmarks(); } +void BookmarkManager::removeAllBookmarks() +{ + if (m_bookmarksList.isEmpty()) + return; + beginRemoveRows(QModelIndex(), 0, m_bookmarksList.size() - 1); + + DirectoryFileBookmarksMap::const_iterator it, end; + end = m_bookmarksMap.constEnd(); + for (it = m_bookmarksMap.constBegin(); it != end; ++it) { + FileNameBookmarksMap *files = it.value(); + FileNameBookmarksMap::const_iterator jt, jend; + jend = files->constEnd(); + for (jt = files->constBegin(); jt != jend; ++jt) { + delete jt.value(); + } + files->clear(); + delete files; + } + m_bookmarksMap.clear(); + m_bookmarksList.clear(); + endRemoveRows(); +} + void BookmarkManager::removeBookmark(Bookmark *bookmark) { + int idx = m_bookmarksList.indexOf(bookmark); + beginRemoveRows(QModelIndex(), idx, idx); + const QFileInfo fi(bookmark->filePath() ); FileNameBookmarksMap *files = m_bookmarksMap.value(fi.path()); @@ -434,8 +460,7 @@ void BookmarkManager::removeBookmark(Bookmark *bookmark) delete files; } - int idx = m_bookmarksList.indexOf(bookmark); - beginRemoveRows(QModelIndex(), idx, idx); + m_bookmarksList.removeAt(idx); endRemoveRows(); @@ -700,6 +725,7 @@ void BookmarkManager::saveBookmarks() /* Loads the bookmarks from the session settings. */ void BookmarkManager::loadBookmarks() { + removeAllBookmarks(); SessionManager *s = sessionManager(); if (!s) return; diff --git a/src/plugins/bookmarks/bookmarkmanager.h b/src/plugins/bookmarks/bookmarkmanager.h index f04aa2c0c94..0c732daf7e7 100644 --- a/src/plugins/bookmarks/bookmarkmanager.h +++ b/src/plugins/bookmarks/bookmarkmanager.h @@ -67,6 +67,7 @@ public: ~BookmarkManager(); void updateBookmark(Bookmark *bookmark); void removeBookmark(Bookmark *bookmark); // Does not remove the mark + void removeAllBookmarks(); Bookmark *bookmarkForIndex(QModelIndex index); enum State { NoBookMarks, HasBookMarks, HasBookmarksInDocument }; -- GitLab