DocDiff application: finish display of differences

This commit is contained in:
Jakub Melka 2021-10-16 16:05:55 +02:00
parent ddbc6a344d
commit 4243d6d9a9
3 changed files with 61 additions and 0 deletions

View File

@ -305,6 +305,8 @@ void DifferencesDrawInterface::drawPage(QPainter* painter,
const pdf::PDFInteger leftPageIndex = m_mapper->getLeftPageIndex(pageIndex); const pdf::PDFInteger leftPageIndex = m_mapper->getLeftPageIndex(pageIndex);
const pdf::PDFInteger rightPageIndex = m_mapper->getRightPageIndex(pageIndex); const pdf::PDFInteger rightPageIndex = m_mapper->getRightPageIndex(pageIndex);
std::optional<size_t> pageMoveIndex;
if (leftPageIndex != -1) if (leftPageIndex != -1)
{ {
for (size_t i = 0; i < differencesCount; ++i) for (size_t i = 0; i < differencesCount; ++i)
@ -320,6 +322,11 @@ void DifferencesDrawInterface::drawPage(QPainter* painter,
drawMarker(painter, pagePointToDevicePointMatrix, item.second, color, true); drawMarker(painter, pagePointToDevicePointMatrix, item.second, color, true);
} }
} }
if (m_diffResult->isPageMoveAddRemoveDifference(i) && m_diffResult->getLeftPage(i) == leftPageIndex)
{
pageMoveIndex = i;
}
} }
} }
@ -338,8 +345,41 @@ void DifferencesDrawInterface::drawPage(QPainter* painter,
drawMarker(painter, pagePointToDevicePointMatrix, item.second, color, false); drawMarker(painter, pagePointToDevicePointMatrix, item.second, color, false);
} }
} }
if (m_diffResult->isPageMoveAddRemoveDifference(i) && m_diffResult->getRightPage(i) == rightPageIndex)
{
pageMoveIndex = i;
}
} }
} }
if (pageMoveIndex)
{
QString text;
switch (m_diffResult->getType(*pageMoveIndex))
{
case pdf::PDFDiffResult::Type::PageAdded:
text = " + ";
break;
case pdf::PDFDiffResult::Type::PageRemoved:
text = " - ";
break;
case pdf::PDFDiffResult::Type::PageMoved:
text = QString("%1🠖%2").arg(m_diffResult->getLeftPage(*pageMoveIndex) + 1).arg(m_diffResult->getRightPage(*pageMoveIndex) + 1);
break;
default:
Q_ASSERT(false);
break;
}
QColor color = getColorForIndex(*pageMoveIndex);
QPointF targetPoint = pagePointToDevicePointMatrix.map(QPointF(5, 5));
pdf::PDFPainterHelper::drawBubble(painter, targetPoint.toPoint(), color, text, Qt::AlignRight | Qt::AlignTop);
}
} }
QColor DifferencesDrawInterface::getColorForIndex(size_t index) const QColor DifferencesDrawInterface::getColorForIndex(size_t index) const

View File

@ -1180,6 +1180,16 @@ PDFInteger PDFDiffResult::getRightPage(size_t index) const
return m_differences[index].pageIndex2; return m_differences[index].pageIndex2;
} }
PDFDiffResult::Type PDFDiffResult::getType(size_t index) const
{
if (index >= m_differences.size())
{
return Type::Invalid;
}
return m_differences[index].type;
}
std::pair<PDFDiffResult::RectInfosIt, PDFDiffResult::RectInfosIt> PDFDiffResult::getLeftRectangles(size_t index) const std::pair<PDFDiffResult::RectInfosIt, PDFDiffResult::RectInfosIt> PDFDiffResult::getLeftRectangles(size_t index) const
{ {
if (index >= m_differences.size()) if (index >= m_differences.size())
@ -1216,6 +1226,11 @@ std::pair<PDFDiffResult::RectInfosIt, PDFDiffResult::RectInfosIt> PDFDiffResult:
return std::make_pair(m_rects.cend(), m_rects.cend()); return std::make_pair(m_rects.cend(), m_rects.cend());
} }
bool PDFDiffResult::isPageMoveAddRemoveDifference(size_t index) const
{
return getTypeFlags(index) & FLAGS_TYPE_PAGE_MOVE_ADD_REMOVE;
}
bool PDFDiffResult::isPageMoveDifference(size_t index) const bool PDFDiffResult::isPageMoveDifference(size_t index) const
{ {
return getTypeFlags(index) & FLAGS_TYPE_PAGE_MOVE; return getTypeFlags(index) & FLAGS_TYPE_PAGE_MOVE;

View File

@ -96,12 +96,17 @@ public:
/// \param index Index /// \param index Index
PDFInteger getRightPage(size_t index) const; PDFInteger getRightPage(size_t index) const;
/// Return type of difference
/// \param index Index
Type getType(size_t index) const;
/// Returns iterator range for rectangles of "left" pages of an item /// Returns iterator range for rectangles of "left" pages of an item
std::pair<RectInfosIt, RectInfosIt> getLeftRectangles(size_t index) const; std::pair<RectInfosIt, RectInfosIt> getLeftRectangles(size_t index) const;
/// Returns iterator range for rectangles of "right" pages of an item /// Returns iterator range for rectangles of "right" pages of an item
std::pair<RectInfosIt, RectInfosIt> getRightRectangles(size_t index) const; std::pair<RectInfosIt, RectInfosIt> getRightRectangles(size_t index) const;
bool isPageMoveAddRemoveDifference(size_t index) const;
bool isPageMoveDifference(size_t index) const; bool isPageMoveDifference(size_t index) const;
bool isAddDifference(size_t index) const; bool isAddDifference(size_t index) const;
bool isRemoveDifference(size_t index) const; bool isRemoveDifference(size_t index) const;
@ -144,6 +149,7 @@ private:
static constexpr uint32_t FLAGS_SHADING = uint32_t(Type::RemovedShadingContent) | uint32_t(Type::AddedShadingContent); static constexpr uint32_t FLAGS_SHADING = uint32_t(Type::RemovedShadingContent) | uint32_t(Type::AddedShadingContent);
static constexpr uint32_t FLAGS_TYPE_PAGE_MOVE = uint32_t(Type::PageMoved); static constexpr uint32_t FLAGS_TYPE_PAGE_MOVE = uint32_t(Type::PageMoved);
static constexpr uint32_t FLAGS_TYPE_PAGE_MOVE_ADD_REMOVE = uint32_t(Type::PageMoved) | uint32_t(Type::PageAdded) | uint32_t(Type::PageRemoved);
static constexpr uint32_t FLAGS_TYPE_ADD = uint32_t(Type::PageAdded) | uint32_t(Type::AddedTextCharContent) | uint32_t(Type::AddedVectorGraphicContent) | uint32_t(Type::AddedImageContent) | uint32_t(Type::AddedShadingContent) | uint32_t(Type::TextAdded); static constexpr uint32_t FLAGS_TYPE_ADD = uint32_t(Type::PageAdded) | uint32_t(Type::AddedTextCharContent) | uint32_t(Type::AddedVectorGraphicContent) | uint32_t(Type::AddedImageContent) | uint32_t(Type::AddedShadingContent) | uint32_t(Type::TextAdded);
static constexpr uint32_t FLAGS_TYPE_REMOVE = uint32_t(Type::PageRemoved) | uint32_t(Type::RemovedTextCharContent) | uint32_t(Type::RemovedVectorGraphicContent) | uint32_t(Type::RemovedImageContent) | uint32_t(Type::RemovedShadingContent) | uint32_t(Type::TextRemoved); static constexpr uint32_t FLAGS_TYPE_REMOVE = uint32_t(Type::PageRemoved) | uint32_t(Type::RemovedTextCharContent) | uint32_t(Type::RemovedVectorGraphicContent) | uint32_t(Type::RemovedImageContent) | uint32_t(Type::RemovedShadingContent) | uint32_t(Type::TextRemoved);
static constexpr uint32_t FLAGS_TYPE_REPLACE = uint32_t(Type::TextReplaced); static constexpr uint32_t FLAGS_TYPE_REPLACE = uint32_t(Type::TextReplaced);