From 599365d293bb0c0fcc2b5b1183e50fa9b93a8e3f Mon Sep 17 00:00:00 2001 From: Attila Szűcs Date: Thu, 25 Jul 2024 06:21:35 +0200 Subject: SW: extract transform charts (using dialog code) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implemented chart data extraction, and transformation added insert/delete/modify row/column, and the ability to set resize data table setcolumndesc / setrowdesc .. for 1 descriptor, or with multiple descriptor to set set 1 cell value, or set the whole table cells values. it will resize the table, but you can still use partial arrays like "data": [ [ 1,2,3,4 ], [ 2,3,4,5 ], [ 3 ], [ 4,5,6,7 ], [ 2,2,1 ], [ 5,6,7,8 ] ], that means the 3. row 2,3,4th cell will not be overwritten. for insert column, it call codes from DataBrowserModel. (used by dialog code) added tests, fixed a contentcontrol date problem 2. commit (made by Caolan) squashed into 1. commit: WIP hack this to link move stuff from chartcontroller to chartcore and adjust visibility until it links at least Change-Id: I5529f4da33f046eef7e947d755e29486fa966274 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172849 Tested-by: Jenkins CollaboraOffice Reviewed-by: Caolán McNamara Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175121 Tested-by: Jenkins --- .../data/docStructureChartExampleOriginal.odt | Bin 0 -> 35081 bytes sw/qa/uibase/shells/shells.cxx | 196 +++++++++++++++++++++ 2 files changed, 196 insertions(+) create mode 100644 sw/qa/uibase/shells/data/docStructureChartExampleOriginal.odt (limited to 'sw/qa') diff --git a/sw/qa/uibase/shells/data/docStructureChartExampleOriginal.odt b/sw/qa/uibase/shells/data/docStructureChartExampleOriginal.odt new file mode 100644 index 000000000000..da775ecf4aaa Binary files /dev/null and b/sw/qa/uibase/shells/data/docStructureChartExampleOriginal.odt differ diff --git a/sw/qa/uibase/shells/shells.cxx b/sw/qa/uibase/shells/shells.cxx index e4ed7367fc29..28a31a50ed28 100644 --- a/sw/qa/uibase/shells/shells.cxx +++ b/sw/qa/uibase/shells/shells.cxx @@ -13,6 +13,9 @@ #include #include #include +#include +#include +#include #include #include @@ -41,6 +44,8 @@ #include #include #include +#include +#include /// Covers sw/source/uibase/shells/ fixes. class SwUibaseShellsTest : public SwModelTestBase @@ -583,6 +588,197 @@ CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testInsertFieldmarkReadonly) CPPUNIT_ASSERT_EQUAL(static_cast(1), rIDMA.getFieldmarksCount()); } +CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testDocumentStructureTransformChart) +{ + createSwDoc("docStructureChartExampleOriginal.odt"); + OString aJson = R"json( +{ + "Transforms": { + "Charts.ByEmbedIndex.0": { + "modifyrow.1": [ 19, 15 ], + "datayx.3.1": 37, + "deleterow.0": "", + "deleterow.1": "", + "insertrow.0": [ 15, 17 ], + "setrowdesc.0": "Paul", + "insertrow.2": [ 19, 22 ], + "setrowdesc.2": "Barbara", + "insertrow.4": [ 29, 27 ], + "setrowdesc.4": "Elizabeth", + "insertrow.5": [ 14, 26 ], + "setrowdesc.5": "William", + "insertcolumn.1": [ 1,2,3,4,5,6 ], + "insertcolumn.0": [ 2,1,2,1,2,1 ], + "insertcolumn.4": [ 7,7,7,7,7,7 ], + "setcolumndesc.4": "c4", + "setcolumndesc.0": "c0", + "setcolumndesc.2": "c2" + }, + "Charts.BySubTitle.Subtitle2": { + "deletecolumn.3": "" + }, + "Charts.ByEmbedName.Object3": { + "resize": [ 12, 3 ], + "setrowdesc": + [ + "United Kingdom", + "United States of America", + "Canada", + "Brazil", + "Germany", + "India", + "Japan", + "Sudan", + "Norway", + "Italy", + "France", + "Egypt" + ], + "modifycolumn.0": [ 12, 9, 8, 5, 5, 4, 3, 3, 2, 2, 1, 1], + "resize": [ 12, 2 ] + }, + "Charts.ByTitle.Fixed issues": { + "data": [ [ 3,1,2 ], + [ 2,0,1 ], + [ 3,2,0 ], + [ 2,1,1 ], + [ 4,2,2 ], + [ 2,2,1 ], + [ 3,2,0,0 ], + [ 3,1,2,1 ], + [ 3,3,1,0,1 ], + [ 2,1,0,1,2 ], + [ 4,2,1,2,2,3 ], + [ 2,1,0,0,1,4 ], + [ 3,2,2,1,3,2 ], + [ 4,2,1,1,2,3 ], + [ 3,3,2,0,3,5 ], + [ 3,3,1,2,2,3 ], + [ 5,1,1,1,1,4 ], + [ 2,2,2,1,2,3 ] ], + "setrowdesc": ["2023.01",".02",".03",".04",".05",".06",".07",".08",".09",".10",".11",".12","2023.01",".02",".03",".04",".05",".06"], + "setcolumndesc": ["Jennifer", "Charles", "Thomas", "Maria", "Lisa", "Daniel"] + } + } +} +)json"_ostr; + + //transform + uno::Sequence aArgs = { + comphelper::makePropertyValue(u"DataJson"_ustr, + uno::Any(OStringToOUString(aJson, RTL_TEXTENCODING_UTF8))), + }; + dispatchCommand(mxComponent, u".uno:TransformDocumentStructure"_ustr, aArgs); + + // Check transformed values of the 3 chart + for (int nShape = 0; nShape < 3; nShape++) + { + uno::Reference xEOS(mxComponent, uno::UNO_QUERY); + CPPUNIT_ASSERT(xEOS.is()); + uno::Reference xEmbeddeds(xEOS->getEmbeddedObjects(), + uno::UNO_QUERY); + CPPUNIT_ASSERT(xEmbeddeds.is()); + + uno::Reference xShapeProps(xEmbeddeds->getByIndex(nShape), + uno::UNO_QUERY); + CPPUNIT_ASSERT(xShapeProps.is()); + + uno::Reference xDocModel; + xShapeProps->getPropertyValue(u"Model"_ustr) >>= xDocModel; + CPPUNIT_ASSERT(xDocModel.is()); + + uno::Reference xChartDoc(xDocModel, uno::UNO_QUERY); + CPPUNIT_ASSERT(xChartDoc.is()); + + uno::Reference xDataArray(xChartDoc->getDataProvider(), + uno::UNO_QUERY); + CPPUNIT_ASSERT(xDataArray.is()); + + switch (nShape) + { + case 0: + { + std::vector> aValues = { + { 2, 15, 1, 7 }, { 1, 19, 2, 7 }, { 2, 19, 3, 7 }, + { 1, 25, 4, 7 }, { 2, 29, 5, 7 }, { 1, 14, 6, 7 }, + }; + // RowDescriptions + std::vector aRowDescsValues + = { u"Paul"_ustr, u"Mary"_ustr, u"Barbara"_ustr, + u"David"_ustr, u"Elizabeth"_ustr, u"William"_ustr }; + // ColumnDescriptions + std::vector aColDescsValues + = { u"c0"_ustr, u"2022"_ustr, u"c2"_ustr, u"c4"_ustr }; + + uno::Sequence> aData = xDataArray->getData(); + for (size_t nY = 0; nY < aValues.size(); nY++) + { + for (size_t nX = 0; nX < aValues[nY].size(); nX++) + { + CPPUNIT_ASSERT_EQUAL(aData[nY][nX], aValues[nY][nX]); + } + } + + uno::Sequence aColDescs = xDataArray->getColumnDescriptions(); + for (size_t i = 0; i < aColDescsValues.size(); i++) + { + CPPUNIT_ASSERT_EQUAL(aColDescs[i], aColDescsValues[i]); + } + uno::Sequence aRowDescs = xDataArray->getRowDescriptions(); + for (size_t i = 0; i < aRowDescsValues.size(); i++) + { + CPPUNIT_ASSERT_EQUAL(aRowDescs[i], aRowDescsValues[i]); + } + } + break; + case 1: + { + uno::Sequence> aData = xDataArray->getData(); + CPPUNIT_ASSERT_EQUAL(static_cast(18), aData.getLength()); + uno::Sequence* pRows = aData.getArray(); + CPPUNIT_ASSERT_EQUAL(static_cast(6), pRows[0].getLength()); + } + break; + case 2: + { + uno::Sequence> aData = xDataArray->getData(); + CPPUNIT_ASSERT_EQUAL(static_cast(12), aData.getLength()); + uno::Sequence* pRows = aData.getArray(); + CPPUNIT_ASSERT_EQUAL(static_cast(2), pRows[0].getLength()); + } + break; + default: + break; + } + } +} + +CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testDocumentStructureExtractChart) +{ + createSwDoc("docStructureChartExampleOriginal.odt"); + + //extract + tools::JsonWriter aJsonWriter; + std::string_view aCommand(".uno:ExtractDocumentStructure"); + auto pXTextDocument = dynamic_cast(mxComponent.get()); + pXTextDocument->getCommandValues(aJsonWriter, aCommand); + + OString aExpectedStr + = "{ \"DocStructure\": { \"Charts.ByEmbedIndex.0\": { \"name\": \"Object1\", \"title\": " + "\"Paid leave days\", \"subtitle\": \"Subtitle2\", \"RowDescriptions\": [ \"James\", " + "\"Mary\", \"Patricia\", \"David\"], \"ColumnDescriptions\": [ \"2022\", \"2023\"], " + "\"DataValues\": [ \"Row.0\": [ \"22\", \"24\"], \"Row.1\": [ \"18\", \"16\"], " + "\"Row.2\": [ \"32\", \"32\"], \"Row.3\": [ \"25\", \"23\"]]}, " + "\"Charts.ByEmbedIndex.1\": { \"name\": \"Object2\", \"title\": \"Fixed issues\", " + "\"subtitle\": \"Subtitle1\", \"RowDescriptions\": [ \"\"], \"ColumnDescriptions\": [ \" " + "\"], \"DataValues\": [ \"Row.0\": [ \"NaN\"]]}, \"Charts.ByEmbedIndex.2\": { \"name\": " + "\"Object3\", \"title\": \"Employees from countries\", \"subtitle\": \"Subtitle3\", " + "\"RowDescriptions\": [ \"\"], \"ColumnDescriptions\": [ \"Column 1\"], \"DataValues\": " + "[ \"Row.0\": [ \"NaN\"]]}}}"_ostr; + + CPPUNIT_ASSERT_EQUAL(aExpectedStr, aJsonWriter.finishAndGetAsOString()); +} + CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testUpdateRefmarks) { // Given a document with two refmarks, one is not interesting the other is a citation: -- cgit