QList<BookmarksItem*> BookmarksModel::findUrls(const QUrl &url, QStandardItem *branch) const { if (!branch) { branch = item(0, 0); } QList<BookmarksItem*> items; for (int i = 0; i < branch->rowCount(); ++i) { BookmarksItem *item = dynamic_cast<BookmarksItem*>(branch->child(i)); if (item) { const BookmarkType type = static_cast<BookmarkType>(item->data(TypeRole).toInt()); if (type == FolderBookmark) { items.append(findUrls(url, item)); } else if (type == UrlBookmark && item->data(UrlRole).toUrl() == url) { items.append(item); } } } return items; }
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(); }
QList<QUrl> BookmarksItem::getUrls() const { QList<QUrl> urls; if (static_cast<BookmarksModel::BookmarkType>(data(BookmarksModel::TypeRole).toInt()) == BookmarksModel::UrlBookmark) { urls.append(data(BookmarksModel::UrlRole).toUrl()); } for (int i = 0; i < rowCount(); ++i) { BookmarksItem *bookmark = dynamic_cast<BookmarksItem*>(child(i, 0)); if (!bookmark) { continue; } const BookmarksModel::BookmarkType type = static_cast<BookmarksModel::BookmarkType>(bookmark->data(BookmarksModel::TypeRole).toInt()); if (type == BookmarksModel::FolderBookmark) { urls.append(bookmark->getUrls()); } else if (type == BookmarksModel::UrlBookmark) { urls.append(bookmark->data(BookmarksModel::UrlRole).toUrl()); } } return urls; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- Qt::ItemFlags BookmarksModel::flags(const QModelIndex& index) const { if (!index.isValid()) { return 0; } Qt::ItemFlags defaultFlags = QAbstractItemModel::flags(index); BookmarksItem* item = getItem(index); QString name = item->data(BookmarksItem::Name).toString(); if (item->data(BookmarksItem::Path).toString().isEmpty()) { // This is a node return (defaultFlags | Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled); } else { // This is a leaf return (defaultFlags | Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsDragEnabled); } }
void WebWidget::pasteNote(QAction *action) { if (action && action->data().isValid()) { BookmarksItem *note = NotesManager::getModel()->bookmarkFromIndex(action->data().toModelIndex()); if (note) { pasteText(note->data(BookmarksModel::DescriptionRole).toString()); } } }
BookmarksItem* BookmarksManager::getLastUsedFolder() { BookmarksItem *folder = getModel()->getBookmark(m_lastUsedFolder); return ((!folder || static_cast<BookmarksModel::BookmarkType>(folder->data(BookmarksModel::TypeRole).toInt()) != BookmarksModel::FolderBookmark) ? getModel()->getRootItem() : folder); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- QVariant BookmarksModel::data(const QModelIndex& index, int role) const { if (!index.isValid()) { return QVariant(); } BookmarksItem* item = getItem(index); if (role == Qt::DisplayRole) { return item->data(index.column()); } else if (role == Qt::UserRole) { return item->getItemHasErrors(); } else if (role == Qt::BackgroundRole) { if (item->getItemHasErrors() == true) { return QColor(235, 110, 110); } else { return QVariant(); } } else if (role == Qt::ForegroundRole) { if (item->getItemHasErrors() == true) { return QColor(240, 240, 240); } else { return QColor(Qt::black); } } else if (role == Qt::ToolTipRole) { QString tooltip = "'" + this->index(index.row(), BookmarksItem::Path, index.parent()).data().toString() + "' was not found on the file system.\nYou can either locate the file or delete the entry from the table."; if (item->getItemHasErrors() == true) { return tooltip; } else { return ""; } } else if (role == Qt::DecorationRole) { QModelIndex nameIndex = this->index(index.row(), BookmarksItem::Name, index.parent()); if (nameIndex == index) { BookmarksItem* item = getItem(index); return item->getIcon(); } else { return QVariant(); } } else { return QVariant(); } }
QStandardItem* ToolBarDialog::createEntry(const QString &identifier) { QStandardItem *item = new QStandardItem(); item->setData(identifier, Qt::UserRole); item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled); if (identifier == QLatin1String("separator")) { item->setText(tr("--- separator ---")); } else if (identifier == QLatin1String("spacer")) { item->setText(tr("--- spacer ---")); } else if (identifier == QLatin1String("AddressWidget")) { item->setText(tr("Address Field")); } else if (identifier == QLatin1String("ClosedWindowsWidget")) { item->setText(tr("List of Closed Windows and Tabs")); } else if (identifier == QLatin1String("MenuBarWidget")) { item->setText(tr("Menu Bar")); } else if (identifier == QLatin1String("MenuButtonWidget")) { item->setText(tr("Menu Button")); } else if (identifier == QLatin1String("PanelChooserWidget")) { item->setText(tr("Sidebar Panel Chooser")); } else if (identifier == QLatin1String("SearchWidget")) { item->setText(tr("Search Field")); } else if (identifier == QLatin1String("StatusMessageWidget")) { item->setText(tr("Status Message Field")); } else if (identifier == QLatin1String("TabBarWidget")) { item->setText(tr("Tab Bar")); } else if (identifier == QLatin1String("ZoomWidget")) { item->setText(tr("Zoom Slider")); } else if (identifier.startsWith(QLatin1String("bookmarks:"))) { BookmarksItem *bookmark = (identifier.startsWith(QLatin1String("bookmarks:/")) ? BookmarksManager::getModel()->getItem(identifier.mid(11)) : BookmarksManager::getBookmark(identifier.mid(10).toULongLong())); if (bookmark) { item->setText(bookmark->data(BookmarksModel::TitleRole).isValid() ? bookmark->data(BookmarksModel::TitleRole).toString() : tr("(Untitled)")); item->setIcon(bookmark->data(Qt::DecorationRole).value<QIcon>()); } else { item->setText(tr("Invalid Bookmark")); } } else if (identifier.endsWith(QLatin1String("Action"))) { const int actionIdentifier = ActionsManager::getActionIdentifier(identifier.left(identifier.length() - 6)); if (actionIdentifier < 0) { item->setText(tr("Invalid Entry")); } else { const ActionDefinition definition = ActionsManager::getActionDefinition(actionIdentifier); item->setText(QCoreApplication::translate("actions", (definition.description.isEmpty() ? definition.text : definition.description).toUtf8().constData())); item->setIcon(definition.icon); } } else { item->setText(tr("Invalid Entry")); } return item; }