diff --git a/Pdf4QtLib/sources/pdfwidgettool.cpp b/Pdf4QtLib/sources/pdfwidgettool.cpp index 28ef995..ce9ea78 100644 --- a/Pdf4QtLib/sources/pdfwidgettool.cpp +++ b/Pdf4QtLib/sources/pdfwidgettool.cpp @@ -1373,7 +1373,8 @@ PDFSelectTableTool::PDFSelectTableTool(PDFDrawWidgetProxy* proxy, QAction* actio BaseClass(proxy, action, parent), m_pickTool(nullptr), m_pageIndex(-1), - m_isTransposed(false) + m_isTransposed(false), + m_rotation(PageRotation::None) { m_pickTool = new PDFPickTool(proxy, PDFPickTool::Mode::Rectangles, this); connect(m_pickTool, &PDFPickTool::rectanglePicked, this, &PDFSelectTableTool::onRectanglePicked); @@ -1568,7 +1569,7 @@ void PDFSelectTableTool::keyPressEvent(QWidget* widget, QKeyEvent* event) cell.column = columnIndex; cell.rectangle = QRectF(left, top, width, height); - PDFTextSelection textSelection = m_textLayout.createTextSelection(m_pageIndex, cell.rectangle.topLeft(), cell.rectangle.bottomRight(), Qt::yellow, true); + PDFTextSelection textSelection = m_textLayout.createTextSelection(m_pageIndex, cell.rectangle.bottomLeft(), cell.rectangle.topRight(), Qt::yellow, true); cell.text = m_textLayout.getTextFromSelection(textSelection, m_pageIndex).trimmed(); cell.text = cell.text.remove(QChar('\n')); @@ -1576,6 +1577,21 @@ void PDFSelectTableTool::keyPressEvent(QWidget* widget, QKeyEvent* event) } } + switch (m_rotation) + { + case PageRotation::None: + { + for (TableCell& cell : tableCells) + { + cell.row = verticalBreaks.size() - cell.row; + } + break; + } + + default: + break; + } + if (m_isTransposed) { auto comparator = [](const TableCell& left, const TableCell right) @@ -1584,6 +1600,14 @@ void PDFSelectTableTool::keyPressEvent(QWidget* widget, QKeyEvent* event) }; std::sort(tableCells.begin(), tableCells.end(), comparator); } + else + { + auto comparator = [](const TableCell& left, const TableCell right) + { + return std::make_pair(left.row, left.column) < std::make_pair(right.row, right.column); + }; + std::sort(tableCells.begin(), tableCells.end(), comparator); + } // Make CSV string QString string; @@ -1634,6 +1658,7 @@ void PDFSelectTableTool::setActiveImpl(bool active) m_isTransposed = false; m_horizontalBreaks.clear(); m_verticalBreaks.clear(); + m_rotation = PageRotation::None; if (getTopToolstackTool()) { @@ -1669,6 +1694,7 @@ void PDFSelectTableTool::onRectanglePicked(PDFInteger pageIndex, QRectF pageRect break; } + m_rotation = rotation; autodetectTableGeometry(); Q_EMIT messageDisplayRequest(tr("Table region was selected. Use left/right mouse buttons to add/remove rows/columns, then use Enter key to copy the table."), 5000); diff --git a/Pdf4QtLib/sources/pdfwidgettool.h b/Pdf4QtLib/sources/pdfwidgettool.h index 7502eaf..cc13e27 100644 --- a/Pdf4QtLib/sources/pdfwidgettool.h +++ b/Pdf4QtLib/sources/pdfwidgettool.h @@ -421,6 +421,7 @@ private: bool m_isTransposed; std::vector m_horizontalBreaks; std::vector m_verticalBreaks; + PageRotation m_rotation; }; /// Tool that makes screenshot of page area and copies it to the clipboard,