sw/qa/extras/indexing/IndexingExportTest.cxx | 64 +++++++++++++++++++ sw/qa/extras/indexing/data/IndexingExport_Tables.odt |binary sw/source/filter/indexing/IndexingExport.cxx | 34 ++++++++++ 3 files changed, 98 insertions(+)
New commits: commit b3a62ab0a43510cf43c88aa4d6e145e46db7e7e5 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Fri Jun 18 20:21:20 2021 +0900 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Sat Jun 19 11:14:31 2021 +0200 indexing: indexing tables for the IndexingExport Adds handling of tables to the IndexingExport and also handling of the end node (as table node is also a start node), so we know which paragraphs belong to a table. Change-Id: I624ce12a3e810797a37ae2efe5baa552828f75dc Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117450 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/sw/qa/extras/indexing/IndexingExportTest.cxx b/sw/qa/extras/indexing/IndexingExportTest.cxx index 350e75c3d49f..fbc2c9d0ece2 100644 --- a/sw/qa/extras/indexing/IndexingExportTest.cxx +++ b/sw/qa/extras/indexing/IndexingExportTest.cxx @@ -30,12 +30,14 @@ public: void testIndexingExport_Images(); void testIndexingExport_OLE(); void testIndexingExport_Shapes(); + void testIndexingExport_Tables(); CPPUNIT_TEST_SUITE(IndexingExportTest); CPPUNIT_TEST(testIndexingExport_Paragraphs); CPPUNIT_TEST(testIndexingExport_Images); CPPUNIT_TEST(testIndexingExport_OLE); CPPUNIT_TEST(testIndexingExport_Shapes); + CPPUNIT_TEST(testIndexingExport_Tables); CPPUNIT_TEST_SUITE_END(); }; @@ -150,6 +152,68 @@ void IndexingExportTest::testIndexingExport_Shapes() assertXPathContent(pXmlDoc, "/indexing/shape[3]/paragraph[3]", "Para3"); } +void IndexingExportTest::testIndexingExport_Tables() +{ + SwDoc* pDoc = createDoc("IndexingExport_Tables.odt"); + CPPUNIT_ASSERT(pDoc); + + SvMemoryStream aMemoryStream; + sw::IndexingExport aIndexingExport(aMemoryStream, pDoc); + aIndexingExport.runExport(); + aMemoryStream.Seek(0); + + xmlDocUniquePtr pXmlDoc = parseXmlStream(&aMemoryStream); + CPPUNIT_ASSERT(pXmlDoc); + + assertXPath(pXmlDoc, "/indexing"); + + assertXPath(pXmlDoc, "/indexing/table[1]", "name", "Table1"); + assertXPathContent(pXmlDoc, "/indexing/table[1]/paragraph[1]", "A"); + assertXPathContent(pXmlDoc, "/indexing/table[1]/paragraph[2]", "B"); + assertXPathContent(pXmlDoc, "/indexing/table[1]/paragraph[3]", "1"); + assertXPathContent(pXmlDoc, "/indexing/table[1]/paragraph[4]", "2"); + + assertXPath(pXmlDoc, "/indexing/table[2]", "name", "Table2"); + assertXPathContent(pXmlDoc, "/indexing/table[2]/paragraph[1]", "A"); + assertXPathContent(pXmlDoc, "/indexing/table[2]/paragraph[2]", "B"); + assertXPathContent(pXmlDoc, "/indexing/table[2]/paragraph[3]", "C"); + assertXPathContent(pXmlDoc, "/indexing/table[2]/paragraph[4]", "1"); + assertXPathContent(pXmlDoc, "/indexing/table[2]/paragraph[5]", "10"); + assertXPathContent(pXmlDoc, "/indexing/table[2]/paragraph[6]", "100"); + assertXPathContent(pXmlDoc, "/indexing/table[2]/paragraph[7]", "2"); + assertXPathContent(pXmlDoc, "/indexing/table[2]/paragraph[8]", "20"); + assertXPathContent(pXmlDoc, "/indexing/table[2]/paragraph[9]", "200"); + assertXPathContent(pXmlDoc, "/indexing/table[2]/paragraph[10]", "3"); + assertXPathContent(pXmlDoc, "/indexing/table[2]/paragraph[11]", "30"); + assertXPathContent(pXmlDoc, "/indexing/table[2]/paragraph[12]", "300"); + assertXPathContent(pXmlDoc, "/indexing/table[2]/paragraph[13]", "4"); + assertXPathContent(pXmlDoc, "/indexing/table[2]/paragraph[14]", "40"); + assertXPathContent(pXmlDoc, "/indexing/table[2]/paragraph[15]", "400"); + + assertXPath(pXmlDoc, "/indexing/table[3]", "name", "WeirdTable"); + assertXPathContent(pXmlDoc, "/indexing/table[3]/paragraph[1]", "A1"); + assertXPathContent(pXmlDoc, "/indexing/table[3]/paragraph[2]", "B1"); + assertXPathContent(pXmlDoc, "/indexing/table[3]/paragraph[3]", "C1"); + assertXPathContent(pXmlDoc, "/indexing/table[3]/paragraph[4]", "D1"); + assertXPathContent(pXmlDoc, "/indexing/table[3]/paragraph[5]", "A2B2"); + assertXPathContent(pXmlDoc, "/indexing/table[3]/paragraph[6]", "C2D2"); + assertXPathContent(pXmlDoc, "/indexing/table[3]/paragraph[7]", "A3B3C3D3"); + assertXPathContent(pXmlDoc, "/indexing/table[3]/paragraph[8]", "A4-1"); + assertXPathContent(pXmlDoc, "/indexing/table[3]/paragraph[9]", "A4-2"); + assertXPathContent(pXmlDoc, "/indexing/table[3]/paragraph[10]", "B4-1"); + assertXPathContent(pXmlDoc, "/indexing/table[3]/paragraph[11]", "C4-1"); + assertXPathContent(pXmlDoc, "/indexing/table[3]/paragraph[12]", "D4-1"); + assertXPathContent(pXmlDoc, "/indexing/table[3]/paragraph[13]", "D4-2"); + assertXPathContent(pXmlDoc, "/indexing/table[3]/paragraph[14]", ""); + assertXPathContent(pXmlDoc, "/indexing/table[3]/paragraph[15]", ""); + assertXPathContent(pXmlDoc, "/indexing/table[3]/paragraph[16]", "B4-2"); + assertXPathContent(pXmlDoc, "/indexing/table[3]/paragraph[17]", "C4-2"); + assertXPathContent(pXmlDoc, "/indexing/table[3]/paragraph[18]", ""); + assertXPathContent(pXmlDoc, "/indexing/table[3]/paragraph[19]", ""); + assertXPathContent(pXmlDoc, "/indexing/table[3]/paragraph[20]", "A5B5C5"); + assertXPathContent(pXmlDoc, "/indexing/table[3]/paragraph[21]", "D5"); +} + CPPUNIT_TEST_SUITE_REGISTRATION(IndexingExportTest); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/qa/extras/indexing/data/IndexingExport_Tables.odt b/sw/qa/extras/indexing/data/IndexingExport_Tables.odt new file mode 100644 index 000000000000..a15acc7de309 Binary files /dev/null and b/sw/qa/extras/indexing/data/IndexingExport_Tables.odt differ diff --git a/sw/source/filter/indexing/IndexingExport.cxx b/sw/source/filter/indexing/IndexingExport.cxx index 3ec39c1d338c..83bac26fc51d 100644 --- a/sw/source/filter/indexing/IndexingExport.cxx +++ b/sw/source/filter/indexing/IndexingExport.cxx @@ -18,6 +18,8 @@ #include <svx/svdotext.hxx> #include <editeng/outlobj.hxx> #include <editeng/editobj.hxx> +#include <swtable.hxx> +#include <deque> namespace sw { @@ -28,6 +30,8 @@ class IndexingNodeHandler : public ModelTraverseHandler private: tools::XmlWriter& m_rXmlWriter; + std::deque<SwNode*> maNodeStack; + public: IndexingNodeHandler(tools::XmlWriter& rXmlWriter) : m_rXmlWriter(rXmlWriter) @@ -48,6 +52,15 @@ public: { handleTextNode(pNode->GetTextNode()); } + else if (pNode->IsTableNode()) + { + handleTableNode(pNode->GetTableNode()); + } + + if (pNode->IsEndNode()) + { + handleEndNode(pNode->GetEndNode()); + } } void handleOLENode(SwOLENode* pOleNode) @@ -105,6 +118,27 @@ public: m_rXmlWriter.endElement(); } + + void handleTableNode(SwTableNode* pTableNode) + { + const SwTableFormat* pFormat = pTableNode->GetTable().GetFrameFormat(); + OUString sName = pFormat->GetName(); + + m_rXmlWriter.startElement("table"); + m_rXmlWriter.attribute("index", pTableNode->GetIndex()); + m_rXmlWriter.attribute("name", sName); + + maNodeStack.push_back(pTableNode); + } + + void handleEndNode(SwEndNode* pEndNode) + { + if (!maNodeStack.empty() && pEndNode->StartOfSectionNode() == maNodeStack.back()) + { + maNodeStack.pop_back(); + m_rXmlWriter.endElement(); + } + } }; } // end anonymous namespace _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits