diff --git a/src/plugins/bookmarks/bookmarkmanager.cpp b/src/plugins/bookmarks/bookmarkmanager.cpp index feb285bdec4e4e98fe03bb1d43ed9b304547410b..33adc3eb564aaf98c4fff4a90e12b7cb5445c04e 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 f04aa2c0c9436f38eca99e29ddc2a5ea25c4c7b6..0c732daf7e710e9afe7fdd089711252b83f28118 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 };