From f59e1e7a57e5b79858997aab317b15f556ff1d62 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Wed, 7 Feb 2018 12:42:38 +0100 Subject: Bookmarks bugfixes - Overwriting bookmarks file when saving - Added BookmarksModel::removeItem with mystery crash on QVector::count --- lib/bookmarks/bookmarksmodel.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'lib/bookmarks/bookmarksmodel.cpp') diff --git a/lib/bookmarks/bookmarksmodel.cpp b/lib/bookmarks/bookmarksmodel.cpp index ba537ba..5b91216 100644 --- a/lib/bookmarks/bookmarksmodel.cpp +++ b/lib/bookmarks/bookmarksmodel.cpp @@ -7,8 +7,8 @@ */ #include "bookmarksmodel.h" -#include #include +#include BookmarksModel::BookmarksModel(QStyle *style, QObject *parent) : QAbstractItemModel(parent) @@ -148,6 +148,21 @@ QModelIndex BookmarksModel::insertItem(BookmarkItem::BookmarkItemType type, cons return index(node); } +bool BookmarksModel::removeItem(const QModelIndex &node) +{ + if(!node.isValid()) + return false; + + auto *item = static_cast(node.internalPointer()); + auto *parentItem = item->parentItem(); + + beginRemoveRows(node, node.row(), node.row()); + parentItem->removeChild(item); + delete item; + endRemoveRows(); + return true; +} + int BookmarksModel::columnCount(const QModelIndex &parent) const { if(parent.isValid()) { -- cgit v1.2.1