diff options
author | Attila Szűcs <attila.szucs@collabora.com> | 2024-07-25 06:21:35 +0200 |
---|---|---|
committer | Caolán McNamara <caolan.mcnamara@collabora.com> | 2024-10-18 12:49:41 +0200 |
commit | 599365d293bb0c0fcc2b5b1183e50fa9b93a8e3f (patch) | |
tree | 8d91ace1459c3691f38ad926272dcc44ea49e899 /sw/qa | |
parent | 9cb748847f63f73a7a0bbd63d34a5f3ebf789919 (diff) |
SW: extract transform charts (using dialog code)
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 <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175121
Tested-by: Jenkins
Diffstat (limited to 'sw/qa')
-rw-r--r-- | sw/qa/uibase/shells/data/docStructureChartExampleOriginal.odt | bin | 0 -> 35081 bytes | |||
-rw-r--r-- | sw/qa/uibase/shells/shells.cxx | 196 |
2 files changed, 196 insertions, 0 deletions
diff --git a/sw/qa/uibase/shells/data/docStructureChartExampleOriginal.odt b/sw/qa/uibase/shells/data/docStructureChartExampleOriginal.odt Binary files differnew file mode 100644 index 000000000000..da775ecf4aaa --- /dev/null +++ b/sw/qa/uibase/shells/data/docStructureChartExampleOriginal.odt 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 <com/sun/star/packages/zip/ZipFileAccess.hpp> #include <com/sun/star/text/BibliographyDataType.hpp> #include <com/sun/star/text/XTextDocument.hpp> +#include <com/sun/star/text/XTextEmbeddedObjectsSupplier.hpp> +#include <com/sun/star/chart2/XChartDocument.hpp> +#include <com/sun/star/chart/XChartDataArray.hpp> #include <sfx2/dispatch.hxx> #include <sfx2/viewfrm.hxx> @@ -41,6 +44,8 @@ #include <ndtxt.hxx> #include <ftnidx.hxx> #include <txtftn.hxx> +#include <unotxdoc.hxx> +#include <tools/json_writer.hxx> /// Covers sw/source/uibase/shells/ fixes. class SwUibaseShellsTest : public SwModelTestBase @@ -583,6 +588,197 @@ CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testInsertFieldmarkReadonly) CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(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<css::beans::PropertyValue> 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<text::XTextEmbeddedObjectsSupplier> xEOS(mxComponent, uno::UNO_QUERY); + CPPUNIT_ASSERT(xEOS.is()); + uno::Reference<container::XIndexAccess> xEmbeddeds(xEOS->getEmbeddedObjects(), + uno::UNO_QUERY); + CPPUNIT_ASSERT(xEmbeddeds.is()); + + uno::Reference<beans::XPropertySet> xShapeProps(xEmbeddeds->getByIndex(nShape), + uno::UNO_QUERY); + CPPUNIT_ASSERT(xShapeProps.is()); + + uno::Reference<frame::XModel> xDocModel; + xShapeProps->getPropertyValue(u"Model"_ustr) >>= xDocModel; + CPPUNIT_ASSERT(xDocModel.is()); + + uno::Reference<chart2::XChartDocument> xChartDoc(xDocModel, uno::UNO_QUERY); + CPPUNIT_ASSERT(xChartDoc.is()); + + uno::Reference<chart::XChartDataArray> xDataArray(xChartDoc->getDataProvider(), + uno::UNO_QUERY); + CPPUNIT_ASSERT(xDataArray.is()); + + switch (nShape) + { + case 0: + { + std::vector<std::vector<double>> 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<OUString> aRowDescsValues + = { u"Paul"_ustr, u"Mary"_ustr, u"Barbara"_ustr, + u"David"_ustr, u"Elizabeth"_ustr, u"William"_ustr }; + // ColumnDescriptions + std::vector<OUString> aColDescsValues + = { u"c0"_ustr, u"2022"_ustr, u"c2"_ustr, u"c4"_ustr }; + + uno::Sequence<uno::Sequence<double>> 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<OUString> aColDescs = xDataArray->getColumnDescriptions(); + for (size_t i = 0; i < aColDescsValues.size(); i++) + { + CPPUNIT_ASSERT_EQUAL(aColDescs[i], aColDescsValues[i]); + } + uno::Sequence<OUString> aRowDescs = xDataArray->getRowDescriptions(); + for (size_t i = 0; i < aRowDescsValues.size(); i++) + { + CPPUNIT_ASSERT_EQUAL(aRowDescs[i], aRowDescsValues[i]); + } + } + break; + case 1: + { + uno::Sequence<uno::Sequence<double>> aData = xDataArray->getData(); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(18), aData.getLength()); + uno::Sequence<double>* pRows = aData.getArray(); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(6), pRows[0].getLength()); + } + break; + case 2: + { + uno::Sequence<uno::Sequence<double>> aData = xDataArray->getData(); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(12), aData.getLength()); + uno::Sequence<double>* pRows = aData.getArray(); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(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<SwXTextDocument*>(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: |