本文整理汇总了C++中BookmarksItem类的典型用法代码示例。如果您正苦于以下问题:C++ BookmarksItem类的具体用法?C++ BookmarksItem怎么用?C++ BookmarksItem使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BookmarksItem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getTrashItem
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();
}
}
}
示例2: if
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;
}
示例3: item
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;
}
示例4: QUrl
void BookmarksContentsWidget::addBookmark()
{
BookmarksItem *bookmark = BookmarksManager::addBookmark(BookmarksModel::UrlBookmark, QUrl(), QString(), findFolder(m_ui->bookmarksViewWidget->currentIndex()));
BookmarkPropertiesDialog dialog(bookmark, BookmarkPropertiesDialog::AddBookmarkMode, this);
if (dialog.exec() == QDialog::Rejected)
{
bookmark->remove();
}
}
示例5: QStandardItemModel
BookmarksModel::BookmarksModel(const QString &path, FormatMode mode, QObject *parent) : QStandardItemModel(parent),
m_mode(mode)
{
BookmarksItem *rootItem = new BookmarksItem();
rootItem->setData(RootBookmark, TypeRole);
rootItem->setData(((mode == NotesMode) ? tr("Notes") : tr("Bookmarks")), TitleRole);
rootItem->setDragEnabled(false);
BookmarksItem *trashItem = new BookmarksItem();
trashItem->setData(TrashBookmark, TypeRole);
trashItem->setData(tr("Trash"), TitleRole);
trashItem->setDragEnabled(false);
trashItem->setEnabled(false);
appendRow(rootItem);
appendRow(trashItem);
setItemPrototype(new BookmarksItem());
QFile file(path);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
Console::addMessage(((mode == NotesMode) ? tr("Failed to open notes file: %1") : tr("Failed to open bookmarks file: %1")).arg(file.errorString()), OtherMessageCategory, ErrorMessageLevel, path);
return;
}
QXmlStreamReader reader(file.readAll());
if (reader.readNextStartElement() && reader.name() == QLatin1String("xbel") && reader.attributes().value(QLatin1String("version")).toString() == QLatin1String("1.0"))
{
while (reader.readNextStartElement())
{
if (reader.name() == QLatin1String("folder") || reader.name() == QLatin1String("bookmark") || reader.name() == QLatin1String("separator"))
{
readBookmark(&reader, rootItem);
}
else
{
reader.skipCurrentElement();
}
if (reader.hasError())
{
getRootItem()->removeRows(0, getRootItem()->rowCount());
Console::addMessage(((m_mode == NotesMode) ? tr("Failed to load notes file: %1") : tr("Failed to load bookmarks file: %1")).arg(reader.errorString()), OtherMessageCategory, ErrorMessageLevel, path);
QMessageBox::warning(NULL, tr("Error"), ((m_mode == NotesMode) ? tr("Failed to load notes file.") : tr("Failed to load bookmarks file.")), QMessageBox::Close);
return;
}
}
}
connect(this, SIGNAL(itemChanged(QStandardItem*)), this, SIGNAL(modelModified()));
connect(this, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SIGNAL(modelModified()));
connect(this, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SIGNAL(modelModified()));
connect(this, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)), this, SIGNAL(modelModified()));
}
示例6: getItem
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
bool BookmarksModel::insertRows(int position, int rows, const QModelIndex& parent)
{
BookmarksItem* parentItem = getItem(parent);
bool success;
beginInsertRows(parent, position, position + rows - 1);
success = parentItem->insertChildren(position, rows, rootItem->columnCount());
endInsertRows();
return success;
}
示例7: bookmarkProperties
void BookmarksContentsWidget::bookmarkProperties()
{
BookmarksItem *bookmark = dynamic_cast<BookmarksItem*>(BookmarksManager::getModel()->itemFromIndex(m_ui->bookmarksViewWidget->currentIndex()));
if (bookmark)
{
BookmarkPropertiesDialog(bookmark, (bookmark->isInTrash() ? BookmarkPropertiesDialog::ViewBookmarkMode : BookmarkPropertiesDialog::EditBookmarkMode), this).exec();
updateActions();
}
}
示例8: pasteNote
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());
}
}
}
示例9: removeChild
void BookmarksItem::removeChild(int index, bool d)
{
BookmarksItem * child = this->child(index);
if(child)
{
if(d)
{
child->deleteLater();
}
m_children.removeAt(index);
}
}
示例10: QModelIndex
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
QModelIndex BookmarksModel::index(int row, int column, const QModelIndex& parent) const
{
if (parent.isValid() && parent.column() != 0)
{ return QModelIndex(); }
BookmarksItem* parentItem = getItem(parent);
BookmarksItem* childItem = parentItem->child(row);
if (childItem)
{ return createIndex(row, column, childItem); }
else
{ return QModelIndex(); }
}
示例11: BookmarksItem
QStandardItem* BookmarksItem::clone() const
{
BookmarksItem *item = new BookmarksItem();
item->setData(data(BookmarksModel::TypeRole), BookmarksModel::TypeRole);
item->setData(data(BookmarksModel::UrlRole), BookmarksModel::UrlRole);
item->setData(data(BookmarksModel::TitleRole), BookmarksModel::TitleRole);
item->setData(data(BookmarksModel::DescriptionRole), BookmarksModel::DescriptionRole);
item->setData(data(BookmarksModel::KeywordRole), BookmarksModel::KeywordRole);
item->setData(data(BookmarksModel::TimeAddedRole), BookmarksModel::TimeAddedRole);
item->setData(data(BookmarksModel::TimeModifiedRole), BookmarksModel::TimeModifiedRole);
item->setData(data(BookmarksModel::TimeVisitedRole), BookmarksModel::TimeVisitedRole);
item->setData(data(BookmarksModel::VisitsRole), BookmarksModel::VisitsRole);
return item;
}
示例12: index
int BookmarksItem::index()
{
BookmarksItem * parent = qobject_cast<BookmarksItem *>(this->parent());
if(parent)
{
for(int i = 0; i < parent->childrenCount(); i++)
{
if(parent->child(i) == this)
{
return i;
}
}
}
return -1;
}
示例13: getBookmark
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();
}
示例14: addBookmark
void MainWindow::addBookmark(const QUrl &url, const QString &title, const QString &description, bool warn)
{
const QUrl bookmarkUrl = (url.isValid() ? url.adjusted(QUrl::RemovePassword) : m_windowsManager->getUrl().adjusted(QUrl::RemovePassword));
if (bookmarkUrl.isEmpty() || (warn && BookmarksManager::hasBookmark(bookmarkUrl) && QMessageBox::warning(this, tr("Warning"), tr("You already have this address in your bookmarks.\nDo you want to continue?"), (QMessageBox::Yes | QMessageBox::Cancel)) == QMessageBox::Cancel))
{
return;
}
BookmarksItem *bookmark = BookmarksManager::addBookmark(BookmarksModel::UrlBookmark, bookmarkUrl, (url.isValid() ? title : m_windowsManager->getTitle()));
bookmark->setData(description, BookmarksModel::DescriptionRole);
BookmarkPropertiesDialog dialog(bookmark, BookmarkPropertiesDialog::AddBookmarkMode, this);
if (dialog.exec() == QDialog::Rejected)
{
bookmark->remove();
}
}
示例15: blockSignals
BookmarksItem* BookmarksModel::addBookmark(BookmarkType type, quint64 identifier, const QUrl &url, const QString &title, BookmarksItem *parent, int index)
{
blockSignals(true);
BookmarksItem *bookmark = new BookmarksItem();
if (parent)
{
parent->insertRow(((index < 0) ? parent->rowCount() : index), bookmark);
}
else
{
getRootItem()->insertRow(((index < 0) ? getRootItem()->rowCount() : index), bookmark);
}
if (type == UrlBookmark || type == SeparatorBookmark)
{
bookmark->setDropEnabled(false);
}
setData(bookmark->index(), type, TypeRole);
setData(bookmark->index(), url, UrlRole);
setData(bookmark->index(), title, TitleRole);
if (type != RootBookmark && type != TrashBookmark && type != FolderBookmark)
{
bookmark->setFlags(bookmark->flags() | Qt::ItemNeverHasChildren);
}
if (type != TrashBookmark && type != UnknownBookmark)
{
if (identifier == 0 || m_identifiers.contains(identifier))
{
identifier = (m_identifiers.isEmpty() ? 1 : (m_identifiers.keys().last() + 1));
}
setData(bookmark->index(), identifier, IdentifierRole);
m_identifiers[identifier] = bookmark;
}
blockSignals(false);
emit bookmarkAdded(bookmark);
emit modelModified();
return bookmark;
}