当前位置: 首页>>代码示例>>C++>>正文


C++ BookmarkNode类代码示例

本文整理汇总了C++中BookmarkNode的典型用法代码示例。如果您正苦于以下问题:C++ BookmarkNode类的具体用法?C++ BookmarkNode怎么用?C++ BookmarkNode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了BookmarkNode类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: QLatin1String

void BookmarksManager::load()
{
    if (m_loaded)
        return;
    m_loaded = true;

    QString dir = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
    QString bookmarkFile = dir + QLatin1String("/bookmarks.xbel");
    if (!QFile::exists(bookmarkFile))
        bookmarkFile = QLatin1String(":defaultbookmarks.xbel");

    XbelReader reader;
    m_bookmarkRootNode = reader.read(bookmarkFile);
    if (reader.error() != QXmlStreamReader::NoError) {
        QMessageBox::warning(0, QLatin1String("Loading Bookmark"),
            tr("Error when loading bookmarks on line %1, column %2:\n"
               "%3").arg(reader.lineNumber()).arg(reader.columnNumber()).arg(reader.errorString()));
    }

    QList<BookmarkNode*> others;
    for (int i = m_bookmarkRootNode->children().count() - 1; i >= 0; --i) {
        BookmarkNode *node = m_bookmarkRootNode->children().at(i);
        if (node->type() == BookmarkNode::Folder) {
            // Automatically convert
            if ((node->title == tr("Toolbar Bookmarks")
                 || node->title == QLatin1String(BOOKMARKBAR)) && !m_toolbar) {
                node->title = tr(BOOKMARKBAR);

                m_toolbar = node;
            }

            // Automatically convert
            if ((node->title == tr("Menu")
                 || node->title == QLatin1String(BOOKMARKMENU)) && !m_menu) {
                node->title = tr(BOOKMARKMENU);
                m_menu = node;
            }
        } else {
            others.append(node);
        }
        m_bookmarkRootNode->remove(node);
    }
    Q_ASSERT(m_bookmarkRootNode->children().count() == 0);
    if (!m_toolbar) {
        m_toolbar = new BookmarkNode(BookmarkNode::Folder, m_bookmarkRootNode);
        m_toolbar->title = tr(BOOKMARKBAR);
    } else {
        m_bookmarkRootNode->add(m_toolbar);
    }

    if (!m_menu) {
        m_menu = new BookmarkNode(BookmarkNode::Folder, m_bookmarkRootNode);
        m_menu->title = tr(BOOKMARKMENU);
    } else {
        m_bookmarkRootNode->add(m_menu);
    }

    for (int i = 0; i < others.count(); ++i)
        m_menu->add(others.at(i));
}
开发者ID:porphyr,项目名称:arora,代码行数:60,代码来源:bookmarks.cpp

示例2: index

QModelIndex BookmarksModel::index(BookmarkNode *node) const
{
    BookmarkNode *parent = node->parent();
    if (!parent)
        return QModelIndex();
    return createIndex(parent->children().indexOf(node), 0, node);
}
开发者ID:RobinWuDev,项目名称:Qt,代码行数:7,代码来源:bookmarks.cpp

示例3: load

QStringList BookmarksManager::find_tag_urls(BookmarkNode *start_node, const QString& tag)
{
    if (!m_loaded)
        load();

    if (!start_node)
        start_node = m_bookmarkRootNode;

    QStringList tags;

    for (int i = start_node->children().count() - 1; i >= 0; --i) {
        BookmarkNode *node = start_node->children().at(i);
        if (node)
        {
            if (node->type() == BookmarkNode::Bookmark)
            {
                QStringList node_tags = node->tags.split(QRegExp("\\W+"), QString::SkipEmptyParts);
                foreach(QString node_tag, node_tags)
                {
                    if (tag.toLower() == node_tag.toLower())
                    {
                        tags.append(node->url);
                        break;
                    }
                }
            }
            if (node->type() == BookmarkNode::Folder)
            {
                tags += find_tag_urls(node, tag);
            }
        }
    }
开发者ID:OS2World,项目名称:APP-INTERNET-QtWeb,代码行数:32,代码来源:bookmarks.cpp

示例4: QModelIndex

QModelIndex BookmarksModel::index(int row, int column, const QModelIndex &parent) const
{
    if (row < 0 || column < 0 || row >= rowCount(parent) || column >= columnCount(parent))
        return QModelIndex();

    // get the parent node
    BookmarkNode *parentNode = node(parent);
    return createIndex(row, column, parentNode->children().at(row));
}
开发者ID:RobinWuDev,项目名称:Qt,代码行数:9,代码来源:bookmarks.cpp

示例5: node

bool BookmarksModel::dropMimeData(const QMimeData *data,
                                  Qt::DropAction action, int row, int column, const QModelIndex &parent)
{
    if (action == Qt::IgnoreAction)
        return true;

    if (column > 0)
        return false;

    BookmarkNode *parentNode = node(parent);

    if (!data->hasFormat(MIMETYPE)) {
        if (!data->hasUrls())
            return false;

        BookmarkNode *node = new BookmarkNode(BookmarkNode::Bookmark, parentNode);
        node->url = QString::fromUtf8(data->urls().at(0).toEncoded());

        if (data->hasText())
            node->title = data->text();
        else
            node->title = node->url;

        m_bookmarksManager->addBookmark(parentNode, node, row);
        return true;
    }

    QByteArray ba = data->data(MIMETYPE);
    QDataStream stream(&ba, QIODevice::ReadOnly);
    if (stream.atEnd())
        return false;

    QUndoStack *undoStack = m_bookmarksManager->undoRedoStack();
    undoStack->beginMacro(QLatin1String("Move Bookmarks"));

    while (!stream.atEnd()) {
        QByteArray encodedData;
        stream >> encodedData;
        QBuffer buffer(&encodedData);
        buffer.open(QBuffer::ReadOnly);

        XbelReader reader;
        BookmarkNode *rootNode = reader.read(&buffer);
        QList<BookmarkNode*> children = rootNode->children();
        for (int i = 0; i < children.count(); ++i) {
            BookmarkNode *bookmarkNode = children.at(i);
            rootNode->remove(bookmarkNode);
            row = qMax(0, row);
            m_bookmarksManager->addBookmark(parentNode, bookmarkNode, row);
            m_endMacro = true;
        }
        delete rootNode;
    }
    return true;
}
开发者ID:tibmeister,项目名称:arora,代码行数:55,代码来源:bookmarksmodel.cpp

示例6: Q_ASSERT

void BookmarksModel::entryAdded(BookmarkNode *item)
{
    Q_ASSERT(item && item->parent());
    int row = item->parent()->children().indexOf(item);
    BookmarkNode *parent = item->parent();
    // item was already added so remove beore beginInsertRows is called
    parent->remove(item);
    beginInsertRows(index(parent), row, row);
    parent->add(item, row);
    endInsertRows();
}
开发者ID:RobinWuDev,项目名称:Qt,代码行数:11,代码来源:bookmarks.cpp

示例7: node

Qt::ItemFlags BookmarksModel::flags(const QModelIndex &index) const
{
    if (!index.isValid())
        return Qt::NoItemFlags;

    Qt::ItemFlags flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled;

    BookmarkNode *bookmarkNode = node(index);

    if (bookmarkNode != m_bookmarksManager->menu()
        && bookmarkNode != m_bookmarksManager->toolbar()) {
        flags |= Qt::ItemIsDragEnabled;
        if (bookmarkNode->type() != BookmarkNode::Separator)
            flags |= Qt::ItemIsEditable;
    }
    if (hasChildren(index))
        flags |= Qt::ItemIsDropEnabled;
    return flags;
}
开发者ID:RobinWuDev,项目名称:Qt,代码行数:19,代码来源:bookmarks.cpp

示例8: init

// This will be called before each test function is executed.
void tst_AddBookmarkDialog::init()
{
    BookmarksManager *manager = BrowserApplication::bookmarksManager();
    BookmarkNode *root = manager->bookmarks();
    QList<BookmarkNode*> nodes = root->children();
    BookmarkNode *menu = nodes[0];
    BookmarkNode *toolbar = nodes[1];
    while (!menu->children().isEmpty())
        manager->removeBookmark(menu->children().first());
    while (!toolbar->children().isEmpty())
        manager->removeBookmark(toolbar->children().first());
}
开发者ID:jafo2128,项目名称:arora,代码行数:13,代码来源:tst_addbookmarkdialog.cpp

示例9: tr

void BookmarksManager::importBookmarks()
{
    QString fileName = QFileDialog::getOpenFileName(0, tr("Open File"),
                                                     QString(),
                                                     tr("XBEL (*.xbel *.xml)"));
    if (fileName.isEmpty())
        return;

    XbelReader reader;
    BookmarkNode *importRootNode = reader.read(fileName);
    if (reader.error() != QXmlStreamReader::NoError) {
        QMessageBox::warning(0, QLatin1String("Loading Bookmark"),
            tr("Error when loading bookmarks on line %1, column %2:\n"
               "%3").arg(reader.lineNumber()).arg(reader.columnNumber()).arg(reader.errorString()));
    }

    importRootNode->setType(BookmarkNode::Folder);
    importRootNode->title = (tr("Imported %1").arg(QDate::currentDate().toString(Qt::SystemLocaleShortDate)));
    addBookmark(menu(), importRootNode);
}
开发者ID:RobinWuDev,项目名称:Qt,代码行数:20,代码来源:bookmarks.cpp

示例10: tr

void BookmarksManager::importBookmarks()
{
    QString fileName = QFileDialog::getOpenFileName(0, tr("Open File"),
                                                     QString(),
                                                     tr("XBEL (*.xbel *.xml *.html)"));
    if (fileName.isEmpty())
        return;

    XbelReader reader;
    BookmarkNode *importRootNode = 0;
    if (fileName.endsWith(QLatin1String(".html"))) {
        QString program = QLatin1String("htmlToXBel");
        QStringList arguments;
        arguments << fileName;
        QProcess process;
        process.start(program, arguments);
        process.waitForFinished(-1);
        if (process.error() != QProcess::UnknownError) {
            QMessageBox::warning(0, QLatin1String("Loading Bookmark"),
                tr("Error when loading html bookmarks: %1\n").arg(process.errorString()));
            return;
        }
        importRootNode = reader.read(&process);
    } else {
        importRootNode = reader.read(fileName);
    }
    if (reader.error() != QXmlStreamReader::NoError) {
        QMessageBox::warning(0, QLatin1String("Loading Bookmark"),
            tr("Error when loading bookmarks on line %1, column %2:\n"
               "%3").arg(reader.lineNumber()).arg(reader.columnNumber()).arg(reader.errorString()));
        delete importRootNode;
        return;
    }

    importRootNode->setType(BookmarkNode::Folder);
    importRootNode->title = (tr("Imported %1").arg(QDate::currentDate().toString(Qt::SystemLocaleShortDate)));
    addBookmark(menu(), importRootNode);
}
开发者ID:porphyr,项目名称:arora,代码行数:38,代码来源:bookmarks.cpp

示例11: flags

Qt::ItemFlags BookmarksModel::flags(const QModelIndex &index) const
{
    if (!index.isValid())
        return Qt::NoItemFlags;

    BookmarkNode *node = this->node(index);
    BookmarkNode::Type type = node->type();
    Qt::ItemFlags flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled;

    if (hasChildren(index))
        flags |= Qt::ItemIsDropEnabled;

    if (node == m_bookmarksManager->menu()
            || node == m_bookmarksManager->toolbar())
        return flags;

    flags |= Qt::ItemIsDragEnabled;

    if ((index.column() == 0 && type != BookmarkNode::Separator)
            || (index.column() == 1 && type == BookmarkNode::Bookmark))
        flags |= Qt::ItemIsEditable;

    return flags;
}
开发者ID:tibmeister,项目名称:arora,代码行数:24,代码来源:bookmarksmodel.cpp

示例12: QFETCH

void tst_AddBookmarkDialog::addbookmarkdialog()
{
    QFETCH(QString, url);
    QFETCH(QString, title);
    QFETCH(QDialogButtonBox::StandardButton, button);
    QFETCH(int, menuCount);
    QFETCH(int, toolbarCount);
    QFETCH(int, select);

    BookmarksManager *manager = BrowserApplication::bookmarksManager();
    qRegisterMetaType<BookmarkNode *>("BookmarkNode *");
    QSignalSpy spy(manager, SIGNAL(entryAdded(BookmarkNode *)));
    BookmarkNode *menu = manager->menu();
    BookmarkNode *toolbar = manager->toolbar();
    QCOMPARE(menu->children().count(), 0);
    QCOMPARE(toolbar->children().count(), 0);

    SubAddBookmarkDialog dialog(0, manager);
    dialog.setUrl(url);
    dialog.setTitle(title);
    QComboBox *combobox = dialog.findChild<QComboBox*>();
    QVERIFY(combobox);
    if (select != -1) {
        combobox->setCurrentIndex(select);
        combobox->view()->setCurrentIndex(combobox->model()->index(select, 0));
    }
    QDialogButtonBox *buttonBox = dialog.findChild<QDialogButtonBox*>();
    QVERIFY(buttonBox);
    QPushButton *pushButton = buttonBox->button(button);
    pushButton->click();

    QCOMPARE(spy.count(), menuCount + toolbarCount);

    QCOMPARE(menu->children().count(), menuCount);
    QCOMPARE(toolbar->children().count(), toolbarCount);
    BookmarkNode *node = 0;
    if (menuCount == 1) node = menu->children()[0];
    if (toolbarCount == 1) node = toolbar->children()[0];
    if (node) {
        QCOMPARE(node->title, title);
        QCOMPARE(node->url, url);
    }
}
开发者ID:jafo2128,项目名称:arora,代码行数:43,代码来源:tst_addbookmarkdialog.cpp

示例13: QCOMPARE

void tst_Xbel::readProperly()
{
    SubXbelReader reader;
    BookmarkNode *root = reader.read("all.xbel");
    QCOMPARE(reader.error(), QXmlStreamReader::NoError);
    QList<BookmarkNode *>children = root->children();
    QCOMPARE(children.count(), 4);
    // null folder
    QCOMPARE(children[0]->children().count(), 0);
    QCOMPARE(children[0]->title, QString());
    QCOMPARE(children[0]->url, QString());
    QCOMPARE(children[0]->expanded, false);

    // folded = no
    QCOMPARE(children[1]->children().count(), 0);
    QCOMPARE(children[1]->title, QString());
    QCOMPARE(children[1]->url, QString());
    QCOMPARE(children[1]->expanded, true);
    QCOMPARE(children[1]->type(), BookmarkNode::Folder);

    // folder with two bookmarks
    QCOMPARE(children[2]->children().count(), 2);
    QCOMPARE(children[2]->title, QString("Folder Title"));
    QCOMPARE(children[2]->url, QString());
    QCOMPARE(children[2]->expanded, false);
    QCOMPARE(children[2]->type(), BookmarkNode::Folder);
    {
        children = children[2]->children();
        QCOMPARE(children[0]->children().count(), 0);
        QCOMPARE(children[0]->title, QString("Title"));
        QCOMPARE(children[0]->url, QString("http://www.foo.com/"));
        QCOMPARE(children[0]->expanded, false);
        QCOMPARE(children[0]->type(), BookmarkNode::Bookmark);

        QCOMPARE(children[1]->children().count(), 0);
        QCOMPARE(children[1]->title, QString("Title 2"));
        QCOMPARE(children[1]->url, QString("http://www.bar.com/"));
        QCOMPARE(children[1]->expanded, false);
        QCOMPARE(children[1]->type(), BookmarkNode::Bookmark);
    }

    children = root->children();
    QCOMPARE(children[3]->children().count(), 3);
    QCOMPARE(children[3]->title, QString("Has SubFolder"));
    QCOMPARE(children[3]->url, QString());
    QCOMPARE(children[3]->expanded, true);
    QCOMPARE(children[3]->type(), BookmarkNode::Folder);
    {
        children = children[3]->children();
        QCOMPARE(children[0]->children().count(), 0);
        QCOMPARE(children[0]->title, QString());
        QCOMPARE(children[0]->url, QString());
        QCOMPARE(children[0]->expanded, false);
        QCOMPARE(children[0]->type(), BookmarkNode::Separator);

        QCOMPARE(children[1]->children().count(), 3);
        QCOMPARE(children[1]->title, QString("SubFolder"));
        QCOMPARE(children[1]->url, QString());
        QCOMPARE(children[1]->expanded, true);
        QCOMPARE(children[1]->type(), BookmarkNode::Folder);
        // children not checked

        QCOMPARE(children[2]->children().count(), 0);
        QCOMPARE(children[2]->title, QString());
        QCOMPARE(children[2]->url, QString());
        QCOMPARE(children[2]->expanded, false);
        QCOMPARE(children[2]->type(), BookmarkNode::Separator);
    }
}
开发者ID:Sektor,项目名称:arora-neo,代码行数:69,代码来源:tst_xbel.cpp

示例14: QLatin1String

void BookmarksManager::load()
{
    if (m_loaded)
        return;
    m_loaded = true;

    QString dir = BrowserApplication::dataLocation();
    QString bookmarkFile = dir + QLatin1String("/bookmarks.xbel");
    if (!QFile::exists(bookmarkFile))
#ifdef WINPE
        bookmarkFile = QLatin1String(":defaultbookmarks_winpe.xbel");
#else
        bookmarkFile = QLatin1String(":defaultbookmarks.xbel");
#endif

    XbelReader reader;
    m_bookmarkRootNode = reader.read(bookmarkFile);
    if (reader.error() != QXmlStreamReader::NoError) {
        QMessageBox::warning(0, tr("Loading Bookmark"),
            tr("Error when loading bookmarks on line %1, column %2:\n"
               "%3").arg(reader.lineNumber()).arg(reader.columnNumber()).arg(reader.errorString()));
    }

    BookmarkNode *toolbar = 0;
    BookmarkNode *menu = 0;
    QList<BookmarkNode*> others;
    for (int i = m_bookmarkRootNode->children().count() - 1; i >= 0; --i) 
    {
        BookmarkNode *node = m_bookmarkRootNode->children().at(i);
        if (node->type() == BookmarkNode::Folder) 
        {
            // Automatically convert
            if (node->title == ("Bookmarks Bar") && !toolbar) 
            {
                node->title = tr("Bookmarks Bar"); 
            }

            if (node->title == tr("Bookmarks Bar") && !toolbar) 
            {
                toolbar = node;
            }

            // Automatically convert
            if (node->title == ("Bookmarks Menu") && !menu) 
            {
                node->title = tr("Bookmarks Menu");
            }
            if (node->title == tr("Bookmarks Menu") && !menu) 
            {
                menu = node;
            }
        } 
        else 
        {
            others.append(node);
        }
        m_bookmarkRootNode->remove(node);
    }
    
    Q_ASSERT(m_bookmarkRootNode->children().count() == 0);
    if (!toolbar) {
        toolbar = new BookmarkNode(BookmarkNode::Folder, m_bookmarkRootNode);
        toolbar->title = tr("Bookmarks Bar"); 
    } else 
    {
        m_bookmarkRootNode->add(toolbar);
    }

    if (!menu) 
    {
        menu = new BookmarkNode(BookmarkNode::Folder, m_bookmarkRootNode);
        menu->title = tr("Bookmarks Menu");
    } else 
    {
        m_bookmarkRootNode->add(menu);
    }
    
    for (int i = 0; i < others.count(); ++i)
        menu->add(others.at(i));
}
开发者ID:OS2World,项目名称:APP-INTERNET-QtWeb,代码行数:80,代码来源:bookmarks.cpp


注:本文中的BookmarkNode类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。