mirror of https://github.com/JakubMelka/PDF4QT.git
DocDiff application: view documents
This commit is contained in:
parent
a78ed9f0b3
commit
8975a18d93
|
@ -76,11 +76,13 @@ QSize DifferenceItemDelegate::sizeHint(const QStyleOptionViewItem& option,
|
|||
}
|
||||
|
||||
DifferencesDockWidget::DifferencesDockWidget(QWidget* parent,
|
||||
pdf::PDFDiffResult* unfilteredDiffResult,
|
||||
pdf::PDFDiffResult* diffResult,
|
||||
pdf::PDFDiffResultNavigator* diffNavigator,
|
||||
Settings* settings) :
|
||||
QDockWidget(parent),
|
||||
ui(new Ui::DifferencesDockWidget),
|
||||
m_unfilteredDiffResult(unfilteredDiffResult),
|
||||
m_diffResult(diffResult),
|
||||
m_diffNavigator(diffNavigator),
|
||||
m_settings(settings),
|
||||
|
@ -190,7 +192,17 @@ void DifferencesDockWidget::update()
|
|||
};
|
||||
|
||||
const size_t differenceCount = m_diffResult->getDifferencesCount();
|
||||
const size_t unfilteredDifferenceCount = m_unfilteredDiffResult->getDifferencesCount();
|
||||
const size_t hiddenDifferences = unfilteredDifferenceCount - differenceCount;
|
||||
|
||||
if (hiddenDifferences > 0)
|
||||
{
|
||||
ui->infoTextLabel->setText(tr("%1 Differences (+%2 hidden)").arg(differenceCount).arg(hiddenDifferences));
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->infoTextLabel->setText(tr("%1 Differences").arg(differenceCount));
|
||||
}
|
||||
|
||||
pdf::PDFInteger lastLeftPageIndex = -1;
|
||||
pdf::PDFInteger lastRightPageIndex = -1;
|
||||
|
|
|
@ -59,6 +59,7 @@ class DifferencesDockWidget : public QDockWidget
|
|||
|
||||
public:
|
||||
explicit DifferencesDockWidget(QWidget* parent,
|
||||
pdf::PDFDiffResult* unfilteredDiffResult,
|
||||
pdf::PDFDiffResult* diffResult,
|
||||
pdf::PDFDiffResultNavigator* diffNavigator,
|
||||
Settings* settings);
|
||||
|
@ -76,6 +77,7 @@ private:
|
|||
QColor getColorForIndex(size_t index) const;
|
||||
QModelIndex findResultIndex(size_t index) const;
|
||||
|
||||
pdf::PDFDiffResult* m_unfilteredDiffResult;
|
||||
pdf::PDFDiffResult* m_diffResult;
|
||||
pdf::PDFDiffResultNavigator* m_diffNavigator;
|
||||
Settings* m_settings;
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
|
||||
#include "pdfwidgetutils.h"
|
||||
#include "pdfdocumentreader.h"
|
||||
#include "pdfdrawspacecontroller.h"
|
||||
|
||||
#include <QToolBar>
|
||||
#include <QDesktopWidget>
|
||||
|
@ -31,6 +32,7 @@
|
|||
#include <QMessageBox>
|
||||
#include <QInputDialog>
|
||||
#include <QFileDialog>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
namespace pdfdocdiff
|
||||
{
|
||||
|
@ -41,8 +43,11 @@ MainWindow::MainWindow(QWidget* parent) :
|
|||
m_progress(new pdf::PDFProgress(this)),
|
||||
m_taskbarButton(new QWinTaskbarButton(this)),
|
||||
m_progressTaskbarIndicator(nullptr),
|
||||
m_cmsManager(nullptr),
|
||||
m_pdfWidget(nullptr),
|
||||
m_settingsDockWidget(nullptr),
|
||||
m_differencesDockWidget(nullptr),
|
||||
m_optionalContentActivity(nullptr),
|
||||
m_diff(nullptr),
|
||||
m_isChangingProgressStep(false),
|
||||
m_dontDisplayErrorMessage(false),
|
||||
|
@ -58,9 +63,16 @@ MainWindow::MainWindow(QWidget* parent) :
|
|||
m_settingsDockWidget = new SettingsDockWidget(this);
|
||||
addDockWidget(Qt::LeftDockWidgetArea, m_settingsDockWidget);;
|
||||
|
||||
m_differencesDockWidget = new DifferencesDockWidget(this, &m_filteredDiffResult, &m_diffNavigator, &m_settings);
|
||||
m_differencesDockWidget = new DifferencesDockWidget(this, &m_diffResult, &m_filteredDiffResult, &m_diffNavigator, &m_settings);
|
||||
addDockWidget(Qt::LeftDockWidgetArea, m_differencesDockWidget);
|
||||
|
||||
ui->documentFrame->setLayout(new QVBoxLayout);
|
||||
|
||||
m_cmsManager = new pdf::PDFCMSManager(this);
|
||||
m_pdfWidget = new pdf::PDFWidget(m_cmsManager, pdf::RendererEngine::Software, 1, ui->documentFrame);
|
||||
m_pdfWidget->getDrawWidgetProxy()->setProgress(m_progress);
|
||||
ui->documentFrame->layout()->addWidget(m_pdfWidget);
|
||||
|
||||
ui->menuView->addSeparator();
|
||||
ui->menuView->addAction(m_settingsDockWidget->toggleViewAction());
|
||||
ui->menuView->addAction(m_differencesDockWidget->toggleViewAction());
|
||||
|
@ -86,6 +98,14 @@ MainWindow::MainWindow(QWidget* parent) :
|
|||
ui->actionShow_Pages_with_Differences->setData(int(Operation::ShowPageswithDifferences));
|
||||
ui->actionSave_Differences_to_XML->setData(int(Operation::SaveDifferencesToXML));
|
||||
|
||||
QActionGroup* actionGroup = new QActionGroup(this);
|
||||
actionGroup->setExclusionPolicy(QActionGroup::ExclusionPolicy::Exclusive);
|
||||
actionGroup->addAction(ui->actionView_Differences);
|
||||
actionGroup->addAction(ui->actionView_Left);
|
||||
actionGroup->addAction(ui->actionView_Right);
|
||||
actionGroup->addAction(ui->actionView_Overlay);
|
||||
ui->actionView_Differences->setChecked(true);
|
||||
|
||||
QToolBar* mainToolbar = addToolBar(tr("Main"));
|
||||
mainToolbar->setObjectName("main_toolbar");
|
||||
mainToolbar->addActions({ ui->actionOpen_Left, ui->actionOpen_Right });
|
||||
|
@ -170,6 +190,8 @@ void MainWindow::onMappedActionTriggered(int actionId)
|
|||
|
||||
void MainWindow::onComparationFinished()
|
||||
{
|
||||
clear(false, false);
|
||||
|
||||
m_diffResult = m_diff.getResult();
|
||||
|
||||
if (!m_dontDisplayErrorMessage)
|
||||
|
@ -326,6 +348,7 @@ void MainWindow::performOperation(Operation operation)
|
|||
std::optional<pdf::PDFDocument> document = openDocument();
|
||||
if (document)
|
||||
{
|
||||
clear(true, false);
|
||||
m_leftDocument = std::move(*document);
|
||||
|
||||
const size_t pageCount = m_leftDocument.getCatalog()->getPageCount();
|
||||
|
@ -341,11 +364,10 @@ void MainWindow::performOperation(Operation operation)
|
|||
{
|
||||
ui->leftPageSelectionEdit->clear();
|
||||
}
|
||||
|
||||
updateViewDocument();
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->leftPageSelectionEdit->clear();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -357,6 +379,7 @@ void MainWindow::performOperation(Operation operation)
|
|||
std::optional<pdf::PDFDocument> document = openDocument();
|
||||
if (document)
|
||||
{
|
||||
clear(false, true);
|
||||
m_rightDocument = std::move(*document);
|
||||
|
||||
const size_t pageCount = m_rightDocument.getCatalog()->getPageCount();
|
||||
|
@ -372,11 +395,10 @@ void MainWindow::performOperation(Operation operation)
|
|||
{
|
||||
ui->rightPageSelectionEdit->clear();
|
||||
}
|
||||
|
||||
updateViewDocument();
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->rightPageSelectionEdit->clear();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -451,6 +473,9 @@ void MainWindow::performOperation(Operation operation)
|
|||
case Operation::ViewLeft:
|
||||
case Operation::ViewRight:
|
||||
case Operation::ViewOverlay:
|
||||
updateViewDocument();
|
||||
break;
|
||||
|
||||
case Operation::ShowPageswithDifferences:
|
||||
case Operation::SaveDifferencesToXML:
|
||||
case Operation::CreateCompareReport:
|
||||
|
@ -467,6 +492,53 @@ void MainWindow::performOperation(Operation operation)
|
|||
updateActions();
|
||||
}
|
||||
|
||||
void MainWindow::setViewDocument(pdf::PDFDocument* document)
|
||||
{
|
||||
if (document != m_pdfWidget->getDrawWidgetProxy()->getDocument())
|
||||
{
|
||||
m_optionalContentActivity->deleteLater();
|
||||
m_optionalContentActivity = nullptr;
|
||||
|
||||
if (document)
|
||||
{
|
||||
m_optionalContentActivity = new pdf::PDFOptionalContentActivity(document, pdf::OCUsage::View, this);
|
||||
}
|
||||
|
||||
if (document)
|
||||
{
|
||||
pdf::PDFModifiedDocument modifiedDocument(document, m_optionalContentActivity);
|
||||
m_pdfWidget->setDocument(modifiedDocument);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pdfWidget->setDocument(pdf::PDFModifiedDocument());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::clear(bool clearLeftDocument, bool clearRightDocument)
|
||||
{
|
||||
setViewDocument(nullptr);
|
||||
|
||||
if (clearLeftDocument)
|
||||
{
|
||||
m_leftDocument = pdf::PDFDocument();
|
||||
ui->leftPageSelectionEdit->clear();
|
||||
}
|
||||
|
||||
if (clearRightDocument)
|
||||
{
|
||||
m_rightDocument = pdf::PDFDocument();
|
||||
ui->rightPageSelectionEdit->clear();
|
||||
}
|
||||
|
||||
m_diffResult = pdf::PDFDiffResult();
|
||||
m_filteredDiffResult = pdf::PDFDiffResult();
|
||||
m_diffNavigator.update();
|
||||
|
||||
updateAll(false);
|
||||
}
|
||||
|
||||
void MainWindow::updateAll(bool resetFilters)
|
||||
{
|
||||
if (resetFilters)
|
||||
|
@ -479,6 +551,7 @@ void MainWindow::updateAll(bool resetFilters)
|
|||
}
|
||||
|
||||
updateFilteredResult();
|
||||
updateViewDocument();
|
||||
}
|
||||
|
||||
void MainWindow::updateFilteredResult()
|
||||
|
@ -498,6 +571,28 @@ void MainWindow::updateFilteredResult()
|
|||
updateActions();
|
||||
}
|
||||
|
||||
void MainWindow::updateViewDocument()
|
||||
{
|
||||
pdf::PDFDocument* document = nullptr;
|
||||
|
||||
if (ui->actionView_Left->isChecked())
|
||||
{
|
||||
document = &m_leftDocument;
|
||||
}
|
||||
|
||||
if (ui->actionView_Right->isChecked())
|
||||
{
|
||||
document = &m_rightDocument;
|
||||
}
|
||||
|
||||
if (ui->actionView_Differences->isChecked() || ui->actionView_Overlay->isChecked())
|
||||
{
|
||||
document = &m_combinedDocument;
|
||||
}
|
||||
|
||||
setViewDocument(document);
|
||||
}
|
||||
|
||||
std::optional<pdf::PDFDocument> MainWindow::openDocument()
|
||||
{
|
||||
QString fileName = QFileDialog::getOpenFileName(this, tr("Select PDF document"), m_settings.directory, tr("PDF document (*.pdf)"));
|
||||
|
|
|
@ -22,6 +22,9 @@
|
|||
|
||||
#include "pdfdocument.h"
|
||||
#include "pdfdiff.h"
|
||||
#include "pdfdrawwidget.h"
|
||||
#include "pdfcms.h"
|
||||
#include "pdfoptionalcontent.h"
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QSignalMapper>
|
||||
|
@ -95,8 +98,17 @@ private:
|
|||
bool canPerformOperation(Operation operation) const;
|
||||
void performOperation(Operation operation);
|
||||
|
||||
void setViewDocument(pdf::PDFDocument* document);
|
||||
|
||||
/// Clears all data, and possibly documents also.
|
||||
/// View document is set to nullptr.
|
||||
/// \param clearLeftDocument Clear left document?
|
||||
/// \param clearRightDocument Clear left document?
|
||||
void clear(bool clearLeftDocument, bool clearRightDocument);
|
||||
|
||||
void updateAll(bool resetFilters);
|
||||
void updateFilteredResult();
|
||||
void updateViewDocument();
|
||||
|
||||
std::optional<pdf::PDFDocument> openDocument();
|
||||
|
||||
|
@ -105,8 +117,11 @@ private:
|
|||
pdf::PDFProgress* m_progress;
|
||||
QWinTaskbarButton* m_taskbarButton;
|
||||
QWinTaskbarProgress* m_progressTaskbarIndicator;
|
||||
pdf::PDFCMSManager* m_cmsManager;
|
||||
pdf::PDFWidget* m_pdfWidget;
|
||||
SettingsDockWidget* m_settingsDockWidget;
|
||||
DifferencesDockWidget* m_differencesDockWidget;
|
||||
pdf::PDFOptionalContentActivity* m_optionalContentActivity;
|
||||
|
||||
Settings m_settings;
|
||||
QSignalMapper m_mapper;
|
||||
|
@ -116,6 +131,7 @@ private:
|
|||
|
||||
pdf::PDFDocument m_leftDocument;
|
||||
pdf::PDFDocument m_rightDocument;
|
||||
pdf::PDFDocument m_combinedDocument;
|
||||
|
||||
pdf::PDFDiffResult m_diffResult;
|
||||
pdf::PDFDiffResult m_filteredDiffResult; ///< Difference result with filters applied
|
||||
|
|
|
@ -54,16 +54,13 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="2">
|
||||
<widget class="QFrame" name="frame">
|
||||
<widget class="QFrame" name="documentFrame">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Box</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<property name="midLineWidth">
|
||||
<number>3</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
|
|
|
@ -465,6 +465,8 @@ void PDFDiff::performCompare(const std::vector<PDFDiffPageContext>& leftPrepared
|
|||
using AlgorithmLCS = PDFAlgorithmLongestCommonSubsequenceBase;
|
||||
|
||||
auto modifiedRanges = AlgorithmLCS::getModifiedRanges(pageSequence);
|
||||
PDFDiffResult::PageSequence resultPageSequence;
|
||||
resultPageSequence.reserve(pageSequence.size());
|
||||
|
||||
// First find all moved pages
|
||||
for (const AlgorithmLCS::SequenceItem& item : pageSequence)
|
||||
|
@ -480,7 +482,21 @@ void PDFDiff::performCompare(const std::vector<PDFDiffPageContext>& leftPrepared
|
|||
{
|
||||
result.addPageMoved(leftPreparedPages[item.index1].pageIndex, rightPreparedPages[item.index2].pageIndex);
|
||||
}
|
||||
|
||||
PDFDiffResult::PageSequenceItem pageSequenceItem;
|
||||
if (item.isLeftValid())
|
||||
{
|
||||
const PDFInteger leftIndex = leftPreparedPages[item.index1].pageIndex;
|
||||
pageSequenceItem.leftPage = leftIndex;
|
||||
}
|
||||
if (item.isRightValid())
|
||||
{
|
||||
const PDFInteger rightIndex = rightPreparedPages[item.index2].pageIndex;
|
||||
pageSequenceItem.rightPage = rightIndex;
|
||||
}
|
||||
resultPageSequence.emplace_back(pageSequenceItem);
|
||||
}
|
||||
result.setPageSequence(std::move(resultPageSequence));
|
||||
|
||||
std::vector<PDFDiffHelper::TextFlowDifferences> textFlowDifferences;
|
||||
|
||||
|
@ -1242,6 +1258,16 @@ void PDFDiffResult::addRectRight(Difference& difference, QRectF rect)
|
|||
m_rects.emplace_back(difference.pageIndex2, rect);
|
||||
}
|
||||
|
||||
const PDFDiffResult::PageSequence& PDFDiffResult::getPageSequence() const
|
||||
{
|
||||
return m_pageSequence;
|
||||
}
|
||||
|
||||
void PDFDiffResult::setPageSequence(PageSequence pageSequence)
|
||||
{
|
||||
m_pageSequence = pageSequence;
|
||||
}
|
||||
|
||||
PDFDiffHelper::Differences PDFDiffHelper::calculateDifferences(const GraphicPieceInfos& left,
|
||||
const GraphicPieceInfos& right,
|
||||
PDFReal epsilon)
|
||||
|
|
|
@ -59,6 +59,14 @@ public:
|
|||
TextRemoved = 0x2000,
|
||||
};
|
||||
|
||||
struct PageSequenceItem
|
||||
{
|
||||
PDFInteger leftPage = -1;
|
||||
PDFInteger rightPage = -1;
|
||||
};
|
||||
|
||||
using PageSequence = std::vector<PageSequenceItem>;
|
||||
|
||||
using RectInfos = std::vector<std::pair<PDFInteger, QRectF>>;
|
||||
|
||||
void setResult(PDFOperationResult result) { m_result = std::move(result); }
|
||||
|
@ -110,6 +118,9 @@ public:
|
|||
bool filterImageDifferences,
|
||||
bool filterShadingDifferences);
|
||||
|
||||
const PageSequence& getPageSequence() const;
|
||||
void setPageSequence(PageSequence pageSequence);
|
||||
|
||||
private:
|
||||
friend class PDFDiff;
|
||||
|
||||
|
@ -180,6 +191,7 @@ private:
|
|||
PDFOperationResult m_result;
|
||||
QStringList m_strings;
|
||||
uint32_t m_typeFlags = 0;
|
||||
PageSequence m_pageSequence;
|
||||
};
|
||||
|
||||
/// Class for result navigation, can go to next, or previous result.
|
||||
|
|
Loading…
Reference in New Issue