void BookmarksModel::restoreBookmark(BookmarksItem *bookmark) { if (!bookmark) { return; } BookmarksItem *formerParent = (m_trash.contains(bookmark) ? getBookmark(m_trash[bookmark].first) : getRootItem()); if (!formerParent || static_cast<BookmarkType>(formerParent->data(TypeRole).toInt()) != FolderBookmark) { formerParent = getRootItem(); } if (m_trash.contains(bookmark)) { formerParent->insertRow(m_trash[bookmark].second, bookmark->parent()->takeRow(bookmark->row())); m_trash.remove(bookmark); } else { formerParent->appendRow(bookmark->parent()->takeRow(bookmark->row())); } readdBookmarkUrl(bookmark); BookmarksItem *trashItem = getTrashItem(); trashItem->setEnabled(trashItem->rowCount() > 0); emit bookmarkModified(bookmark); emit bookmarkRestored(bookmark); emit modelModified(); }
void BookmarksModel::trashBookmark(BookmarksItem *bookmark) { if (!bookmark) { return; } const BookmarkType type = static_cast<BookmarkType>(bookmark->data(TypeRole).toInt()); if (type != RootBookmark && type != TrashBookmark) { if (type == SeparatorBookmark || bookmark->data(IsTrashedRole).toBool()) { bookmark->remove(); } else { BookmarksItem *trashItem = getTrashItem(); m_trash[bookmark] = qMakePair(bookmark->parent()->index(), bookmark->row()); trashItem->appendRow(bookmark->parent()->takeRow(bookmark->row())); trashItem->setEnabled(true); removeBookmarkUrl(bookmark); emit bookmarkModified(bookmark); emit bookmarkTrashed(bookmark); emit modelModified(); } } }