From 62abee0e973f15f6d5ff4a23de286732e7e44130 Mon Sep 17 00:00:00 2001 From: Jakub Melka Date: Sat, 30 Dec 2023 17:42:38 +0100 Subject: [PATCH] Issue #140: New bookmarks created empty? --- Pdf4QtViewer/pdfsidebarwidget.cpp | 30 ++++++++++++++++++++++++++++-- RELEASES.txt | 1 + 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/Pdf4QtViewer/pdfsidebarwidget.cpp b/Pdf4QtViewer/pdfsidebarwidget.cpp index 4d7de7a..c2469b4 100644 --- a/Pdf4QtViewer/pdfsidebarwidget.cpp +++ b/Pdf4QtViewer/pdfsidebarwidget.cpp @@ -939,13 +939,39 @@ void PDFSidebarWidget::onOutlineTreeViewContextMenuRequested(const QPoint& pos) auto onInsert = [this, proxyIndex]() { + QModelIndex insertProxyIndex; + + QAbstractItemModel* model = ui->outlineTreeView->model(); if (proxyIndex.isValid()) { - ui->outlineTreeView->model()->insertRow(proxyIndex.row() + 1, proxyIndex.parent()); + if (model->insertRow(proxyIndex.row() + 1, proxyIndex.parent())) + { + insertProxyIndex = proxyIndex.sibling(proxyIndex.row() + 1, 0); + } } else { - ui->outlineTreeView->model()->insertRow(ui->outlineTreeView->model()->rowCount()); + if (model->insertRow(model->rowCount())) + { + insertProxyIndex = model->index(model->rowCount() - 1, 0); + } + } + + if (insertProxyIndex.isValid()) + { + std::vector pages = m_proxy->getWidget()->getDrawWidget()->getCurrentPages(); + + if (!pages.empty()) + { + QModelIndex sourceInsertIndex = m_outlineSortProxyTreeModel->mapToSource(insertProxyIndex); + + pdf::PDFDestination destination; + destination.setDestinationType(pdf::DestinationType::Fit); + destination.setPageIndex(pages.front()); + destination.setPageReference(m_document->getCatalog()->getPage(pages.front())->getPageReference()); + destination.setZoom(m_proxy->getZoom()); + m_outlineTreeModel->setDestination(sourceInsertIndex, destination); + } } }; diff --git a/RELEASES.txt b/RELEASES.txt index d202b20..a492edc 100644 --- a/RELEASES.txt +++ b/RELEASES.txt @@ -1,4 +1,5 @@ CURRENT: + - Issue #140: New bookmarks created empty? - Issue #139: Changing page layout reset the current page - Issue #137: Redaction - Cannot convert '#000000' to color value - Issue #134: Add search bar for actions