Ejemplo n.º 1
0
void OnyxMainWindow::showTableOfContents()
{
    std::vector<int> paragraphs;
    std::vector<int> pages;
    std::vector<QString> titles;
    std::vector<QString> paths;
    LVTocItem * root = this->view_->getToc();

    for ( int i=0; i<root->getChildCount(); i++ )
    {
        LVTocItem *n = root->getChild(i);
        paragraphs.push_back(n->getLevel());
        titles.push_back( cr2qt(n->getName()));
        paths.push_back(cr2qt(n->getPath()));
        pages.push_back(n->getPage());
        for ( int j=0; j<n->getChildCount(); j++ )
        {
            LVTocItem *m = n->getChild(j);
            paragraphs.push_back(m->getLevel());
            titles.push_back( cr2qt(m->getName()));
            paths.push_back(cr2qt(m->getPath()));
            pages.push_back(m->getPage());
        }
    }

    std::vector<QStandardItem *> ptrs;
    QStandardItemModel model;

    QStandardItem *parent = model.invisibleRootItem();
    for (size_t i = 0;i < paragraphs.size();++i)
    {
        QStandardItem *item= new QStandardItem(titles[i]);
        item->setData(paths[i],Qt::UserRole+100);
        item->setEditable(false);
        ptrs.push_back(item);

        // Get parent.
        parent = searchParent(i, paragraphs, ptrs, model);
        parent->appendRow(item);
    }

    TreeViewDialog dialog( this );
    dialog.setModel( &model);

    int ret = dialog.popup( tr("Table of Contents") );
    if (ret != QDialog::Accepted)
    {
        onyx::screen::watcher().enqueue(this, onyx::screen::ScreenProxy::GU);
        return;
    }

    QModelIndex index = dialog.selectedItem();
    if ( !index.isValid() )
    {
        return;
    }
    view_->goToXPointer(index.data(Qt::UserRole+100).toString());
}