diff --git a/Pdf4QtLib/sources/pdfitemmodels.cpp b/Pdf4QtLib/sources/pdfitemmodels.cpp index 855ee30..1a8ffaa 100644 --- a/Pdf4QtLib/sources/pdfitemmodels.cpp +++ b/Pdf4QtLib/sources/pdfitemmodels.cpp @@ -522,6 +522,12 @@ void PDFOutlineTreeItemModel::setDestination(const QModelIndex& index, const PDF } } +const PDFOutlineItem* PDFOutlineTreeItemModel::getRootOutlineItem() const +{ + PDFOutlineTreeItem* item = static_cast(m_rootItem.get()); + return item->getOutlineItem(); +} + bool PDFOutlineTreeItemModel::setData(const QModelIndex& index, const QVariant& value, int role) { if (!m_editable || !index.isValid() || role != Qt::EditRole) diff --git a/Pdf4QtLib/sources/pdfitemmodels.h b/Pdf4QtLib/sources/pdfitemmodels.h index b4b0fce..f26fa25 100644 --- a/Pdf4QtLib/sources/pdfitemmodels.h +++ b/Pdf4QtLib/sources/pdfitemmodels.h @@ -211,6 +211,8 @@ public: void setFontItalics(const QModelIndex& index, bool value); void setDestination(const QModelIndex& index, const PDFDestination& destination); + const PDFOutlineItem* getRootOutlineItem() const; + private: QIcon m_icon; bool m_editable; diff --git a/Pdf4QtViewer/pdfprogramcontroller.h b/Pdf4QtViewer/pdfprogramcontroller.h index 7e79e6c..ba051be 100644 --- a/Pdf4QtViewer/pdfprogramcontroller.h +++ b/Pdf4QtViewer/pdfprogramcontroller.h @@ -285,6 +285,7 @@ public: void performSaveAs(); void onActionTriggered(const pdf::PDFAction* action); + void onDocumentModified(pdf::PDFModifiedDocument document); void updateActionsAvailability(); bool getIsBusy() const; @@ -356,7 +357,6 @@ private: void onDrawSpaceChanged(); void onPageLayoutChanged(); void onDocumentReadingFinished(); - void onDocumentModified(pdf::PDFModifiedDocument document); void onDocumentUndoRedo(pdf::PDFModifiedDocument document); void onQueryPasswordRequest(QString* password, bool* ok); void onPageRenderingErrorsChanged(pdf::PDFInteger pageIndex, int errorsCount); diff --git a/Pdf4QtViewer/pdfsidebarwidget.cpp b/Pdf4QtViewer/pdfsidebarwidget.cpp index e06cb0d..4d2f0ba 100644 --- a/Pdf4QtViewer/pdfsidebarwidget.cpp +++ b/Pdf4QtViewer/pdfsidebarwidget.cpp @@ -31,6 +31,7 @@ #include "pdfexception.h" #include "pdfsignaturehandler.h" #include "pdfdrawspacecontroller.h" +#include "pdfdocumentbuilder.h" #include #include @@ -88,6 +89,10 @@ PDFSidebarWidget::PDFSidebarWidget(pdf::PDFDrawWidgetProxy* proxy, ui->bookmarksTreeView->setDragDropMode(QAbstractItemView::InternalMove); ui->bookmarksTreeView->setContextMenuPolicy(Qt::CustomContextMenu); connect(ui->bookmarksTreeView, &QTreeView::customContextMenuRequested, this, &PDFSidebarWidget::onBookmarksTreeViewContextMenuRequested); + connect(m_outlineTreeModel, &pdf::PDFOutlineTreeItemModel::dataChanged, this, &PDFSidebarWidget::onOutlineItemsChanged); + connect(m_outlineTreeModel, &pdf::PDFOutlineTreeItemModel::rowsInserted, this, &PDFSidebarWidget::onOutlineItemsChanged); + connect(m_outlineTreeModel, &pdf::PDFOutlineTreeItemModel::rowsRemoved, this, &PDFSidebarWidget::onOutlineItemsChanged); + connect(m_outlineTreeModel, &pdf::PDFOutlineTreeItemModel::rowsMoved, this, &PDFSidebarWidget::onOutlineItemsChanged); } connect(ui->bookmarksTreeView, &QTreeView::clicked, this, &PDFSidebarWidget::onOutlineItemClicked); @@ -862,6 +867,19 @@ void PDFSidebarWidget::onBookmarksTreeViewContextMenuRequested(const QPoint& pos contextMenu.exec(ui->bookmarksTreeView->mapToGlobal(pos)); } +void PDFSidebarWidget::onOutlineItemsChanged() +{ + if (m_document) + { + pdf::PDFDocumentBuilder builder(m_document); + builder.setOutline(m_outlineTreeModel->getRootOutlineItem()); + + pdf::PDFDocumentPointer pointer(new pdf::PDFDocument(builder.build())); + pdf::PDFModifiedDocument document(qMove(pointer), m_optionalContentActivity, pdf::PDFModifiedDocument::None); + Q_EMIT documentModified(qMove(document)); + } +} + void PDFSidebarWidget::paintEvent(QPaintEvent* event) { Q_UNUSED(event); diff --git a/Pdf4QtViewer/pdfsidebarwidget.h b/Pdf4QtViewer/pdfsidebarwidget.h index 4ecac46..1a215e3 100644 --- a/Pdf4QtViewer/pdfsidebarwidget.h +++ b/Pdf4QtViewer/pdfsidebarwidget.h @@ -100,6 +100,7 @@ public: signals: void actionTriggered(const pdf::PDFAction* action); + void documentModified(pdf::PDFModifiedDocument document); private: void updateGUI(Page preferredPage); @@ -113,6 +114,7 @@ private: void onThumbnailClicked(const QModelIndex& index); void onSignatureCustomContextMenuRequested(const QPoint &pos); void onBookmarksTreeViewContextMenuRequested(const QPoint &pos); + void onOutlineItemsChanged(); struct PageInfo { diff --git a/Pdf4QtViewer/pdfviewermainwindow.cpp b/Pdf4QtViewer/pdfviewermainwindow.cpp index 889bb34..5a242db 100644 --- a/Pdf4QtViewer/pdfviewermainwindow.cpp +++ b/Pdf4QtViewer/pdfviewermainwindow.cpp @@ -261,6 +261,7 @@ PDFViewerMainWindow::PDFViewerMainWindow(QWidget* parent) : addDockWidget(Qt::LeftDockWidgetArea, m_sidebarDockWidget); m_sidebarDockWidget->hide(); connect(m_sidebarWidget, &PDFSidebarWidget::actionTriggered, m_programController, &PDFProgramController::onActionTriggered); + connect(m_sidebarWidget, &PDFSidebarWidget::documentModified, m_programController, &PDFProgramController::onDocumentModified); m_advancedFindWidget = new PDFAdvancedFindWidget(m_programController->getPdfWidget()->getDrawWidgetProxy(), this); m_advancedFindDockWidget = new QDockWidget(tr("Advanced find"), this); diff --git a/Pdf4QtViewer/pdfviewermainwindowlite.cpp b/Pdf4QtViewer/pdfviewermainwindowlite.cpp index 392d79f..23efb9a 100644 --- a/Pdf4QtViewer/pdfviewermainwindowlite.cpp +++ b/Pdf4QtViewer/pdfviewermainwindowlite.cpp @@ -196,6 +196,7 @@ PDFViewerMainWindowLite::PDFViewerMainWindowLite(QWidget* parent) : addDockWidget(Qt::LeftDockWidgetArea, m_sidebarDockWidget); m_sidebarDockWidget->hide(); connect(m_sidebarWidget, &PDFSidebarWidget::actionTriggered, m_programController, &PDFProgramController::onActionTriggered); + connect(m_sidebarWidget, &PDFSidebarWidget::documentModified, m_programController, &PDFProgramController::onDocumentModified); ui->menuView->addSeparator(); ui->menuView->addAction(m_sidebarDockWidget->toggleViewAction());