static void fillToc(const QDomNode &parent, QTreeWidget *tree, QTreeWidgetItem *parentItem) { QTreeWidgetItem *newitem = 0; for (QDomNode node = parent.firstChild(); !node.isNull(); node = node.nextSibling()) { QDomElement e = node.toElement(); if (!parentItem) newitem = new QTreeWidgetItem(tree, newitem); else newitem = new QTreeWidgetItem(parentItem, newitem); newitem->setText(0, e.tagName()); bool isOpen = false; if (e.hasAttribute("Open")) isOpen = QVariant(e.attribute("Open")).toBool(); if (isOpen) tree->expandItem(newitem); if (e.hasAttribute("DestinationName")) newitem->setText(1, e.attribute("DestinationName")); if (e.hasChildNodes()) fillToc(node, tree, newitem); } }
static void fillToc(Poppler::Document *doc, const QDomNode &parent, QTreeWidget *tree, QTreeWidgetItem *parentItem) { QTreeWidgetItem *newitem = 0; for (QDomNode node = parent.firstChild(); !node.isNull(); node = node.nextSibling()) { QDomElement e = node.toElement(); // for some unknown reason e.attribute("Destination") does not exist while Okular successfully uses it; so we cannot use Poppler::LinkDestination(e.attribute(QString::fromLatin1("Destination"))).pageNumber() and must use the following // const int pageNumber = doc->linkDestination(e.attribute(QString::fromLatin1("DestinationName")))->pageNumber(); Poppler::LinkDestination *dest = doc->linkDestination(e.attribute(QString::fromLatin1("DestinationName"))); const double pageNumber = dest->pageNumber() + dest->top(); delete dest; if (!parentItem) { newitem = new QTreeWidgetItem(tree, newitem); } else { newitem = new QTreeWidgetItem(parentItem, newitem); } newitem->setText(0, e.tagName()); newitem->setData(0, Qt::UserRole, pageNumber); bool isOpen = false; if (e.hasAttribute(QString::fromLatin1("Open"))) { isOpen = QVariant(e.attribute(QString::fromLatin1("Open"))).toBool(); } if (isOpen) { tree->expandItem(newitem); } if (e.hasChildNodes()) { fillToc(doc, node, tree, newitem); } } }
void TocDock::fillInfo() { const QDomDocument *toc = document()->toc(); if (toc) { fillToc(*toc, m_tree, 0); } else { QTreeWidgetItem *item = new QTreeWidgetItem(); item->setText(0, tr("No TOC")); item->setFlags(item->flags() & ~Qt::ItemIsEnabled); m_tree->addTopLevelItem(item); } }
void PDFOutlineDock::fillInfo() { tree->clear(); const QDomDocument *toc = document->popplerDoc()->toc(); if (toc) { fillToc(*toc, tree, 0); connect(tree, SIGNAL(itemSelectionChanged()), this, SLOT(followTocSelection())); delete toc; } else { QTreeWidgetItem *item = new QTreeWidgetItem(); item->setText(0, tr("No TOC")); item->setFlags(item->flags() & ~Qt::ItemIsEnabled); tree->addTopLevelItem(item); } }
void TocDock::fillInfo() { if (!m_tree) // use delayed initialization for faster startup if not all docks are visible loadWidget(); const QDomDocument *toc = document()->toc(); if (toc) { fillToc(document(), *toc, m_tree, 0); } else { QTreeWidgetItem *item = new QTreeWidgetItem(); item->setText(0, tr("No table of contents found.")); item->setFlags(item->flags() & ~Qt::ItemIsEnabled); m_tree->addTopLevelItem(item); } delete toc; }