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(); } } }
bool BookmarksModel::setData(const QModelIndex &index, const QVariant &value, int role) { BookmarksItem *bookmark = dynamic_cast<BookmarksItem*>(itemFromIndex(index)); if (!bookmark) { return QStandardItemModel::setData(index, value, role); } if (role == UrlRole && value.toUrl() != index.data(UrlRole).toUrl()) { const QUrl oldUrl = Utils::normalizeUrl(index.data(UrlRole).toUrl()); const QUrl newUrl = Utils::normalizeUrl(value.toUrl()); if (!oldUrl.isEmpty() && m_urls.contains(oldUrl)) { m_urls[oldUrl].removeAll(bookmark); if (m_urls[oldUrl].isEmpty()) { m_urls.remove(oldUrl); } } if (!newUrl.isEmpty()) { if (!m_urls.contains(newUrl)) { m_urls[newUrl] = QList<BookmarksItem*>(); } m_urls[newUrl].append(bookmark); } } else if (role == KeywordRole && value.toString() != index.data(KeywordRole).toString()) { const QString oldKeyword = index.data(KeywordRole).toString(); const QString newKeyword = value.toString(); if (!oldKeyword.isEmpty() && m_keywords.contains(oldKeyword)) { m_keywords.remove(oldKeyword); } if (!newKeyword.isEmpty()) { m_keywords[newKeyword] = bookmark; } } else if (m_mode == NotesMode && role == DescriptionRole) { const QString title = value.toString().section(QLatin1Char('\n'), 0, 0).left(100); setData(index, ((title == value.toString().trimmed()) ? title : title + QStringLiteral("…")), TitleRole); } bookmark->setItemData(value, role); switch (role) { case TitleRole: case UrlRole: case DescriptionRole: case IdentifierRole: case TypeRole: case KeywordRole: case TimeAddedRole: case TimeModifiedRole: case TimeVisitedRole: case VisitsRole: emit bookmarkModified(bookmark); emit modelModified(); break; } return true; }
int BookmarksController::modifyBookmark(int origBookmarkId, QString newTitle, QString newURL) { int retstat = m_bm->modifyBookmark(origBookmarkId, newTitle, newURL); emit bookmarkModified(newTitle, newURL, origBookmarkId); return retstat; }