diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2024-04-11 16:31:32 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2024-04-12 08:21:19 +0200 |
commit | c379168711858664baabe7fa482a4c7dd3bc7891 (patch) | |
tree | 3e3e76c680dd7fe0b43c90131a915e29ce402547 /sc/qa | |
parent | 1dbe90cb078bddaf8bbd333823762744158c92bb (diff) |
pivot: PivotTableFormatOutput to resolve and set PT cell format
This adds the PivotTableFormatOutput, which main responsibility
is to resolve the reference for which the pivot table format is
set to. It first prepares the format data into such a structure
that it is easier to match with the pivot table fields and data.
Then the pivot table data is filled during the output, where we
remember the cell positions of the pivot table output. The last
step is to resolve the pivot table format references with the
filled data, where the cell formats are applied to the output.
PivotTableFormatsImportExport was added to test the correctnes of
the functionality.
Change-Id: Ie67ea15b3aa74739f15937800d03d256b8f68277
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165992
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'sc/qa')
-rw-r--r-- | sc/qa/unit/PivotTableFormatsImportExport.cxx | 161 | ||||
-rw-r--r-- | sc/qa/unit/data/xlsx/pivot-table/PivotTableCellFormatsTest_1_DataFieldInRow_RowLabelColor.xlsx | bin | 0 -> 16366 bytes | |||
-rw-r--r-- | sc/qa/unit/data/xlsx/pivot-table/PivotTableCellFormatsTest_2_DataFieldInRow_ColumnLabelColor.xlsx | bin | 0 -> 16579 bytes | |||
-rw-r--r-- | sc/qa/unit/data/xlsx/pivot-table/PivotTableCellFormatsTest_3_DataFieldInColumn_ColumnLabelColor.xlsx | bin | 0 -> 16305 bytes | |||
-rw-r--r-- | sc/qa/unit/data/xlsx/pivot-table/PivotTableCellFormatsTest_4_DataFieldInColumn_DataColor.xlsx | bin | 0 -> 16310 bytes | |||
-rw-r--r-- | sc/qa/unit/data/xlsx/pivot-table/PivotTableCellFormatsTest_5_DataFieldInColumnAndTwoRowFields_DataColor.xlsx | bin | 0 -> 16841 bytes | |||
-rw-r--r-- | sc/qa/unit/data/xlsx/pivot-table/PivotTableCellFormatsTest_6_SingleDataFieldInColumn_DataColor.xlsx | bin | 0 -> 17015 bytes | |||
-rw-r--r-- | sc/qa/unit/data/xlsx/pivot-table/PivotTableCellFormatsTest_7_TwoRowTwoColumnFields_DataColor.xlsx | bin | 0 -> 17354 bytes |
8 files changed, 161 insertions, 0 deletions
diff --git a/sc/qa/unit/PivotTableFormatsImportExport.cxx b/sc/qa/unit/PivotTableFormatsImportExport.cxx new file mode 100644 index 000000000000..3cffe8cbc510 --- /dev/null +++ b/sc/qa/unit/PivotTableFormatsImportExport.cxx @@ -0,0 +1,161 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <sal/config.h> + +#include "helper/qahelper.hxx" + +#include <patattr.hxx> +#include <scitems.hxx> +#include <document.hxx> +#include <generalfunction.hxx> +#include <dpcache.hxx> +#include <dpobject.hxx> +#include <dpsave.hxx> +#include <dputil.hxx> +#include <attrib.hxx> +#include <dpshttab.hxx> +#include <globstr.hrc> +#include <scresid.hxx> +#include <queryentry.hxx> +#include <queryparam.hxx> +#include <rtl/string.hxx> +#include <editeng/brushitem.hxx> +#include <editeng/colritem.hxx> + +using namespace css; + +class ScPivotTableFormatsImportExport : public ScModelTestBase +{ +public: + ScPivotTableFormatsImportExport(); +}; + +ScPivotTableFormatsImportExport::ScPivotTableFormatsImportExport() + : ScModelTestBase("sc/qa/unit/data") +{ +} + +namespace +{ +Color getBackgroundColor(ScDocument& rDoc, OUString const& rAddressString) +{ + ScAddress aAddress; + aAddress.Parse(rAddressString, rDoc); + const ScPatternAttr* pPattern = rDoc.GetPattern(aAddress); + const SvxBrushItem& rItem = pPattern->GetItem(ATTR_BACKGROUND); + return rItem.GetColor(); +} + +Color getFontColor(ScDocument& rDoc, OUString const& rAddressString) +{ + ScAddress aAddress; + aAddress.Parse(rAddressString, rDoc); + const ScPatternAttr* pPattern = rDoc.GetPattern(aAddress); + const SvxColorItem& rItem = pPattern->GetItem(ATTR_FONT_COLOR); + return rItem.getColor(); +} +} // end anonymous namespace + +CPPUNIT_TEST_FIXTURE(ScPivotTableFormatsImportExport, + testPivotTableCellFormat_1_DataFieldInRow_RowLabelColor) +{ + auto assertDocument = [](ScDocument& rDoc) { + CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"G6"_ustr)); + CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, getFontColor(rDoc, u"G7"_ustr)); + }; + + createScDoc("xlsx/pivot-table/PivotTableCellFormatsTest_1_DataFieldInRow_RowLabelColor.xlsx"); + assertDocument(*getScDoc()); +} + +CPPUNIT_TEST_FIXTURE(ScPivotTableFormatsImportExport, + PivotTableCellFormatsTest_2_DataFieldInRow_ColumnLabelColor) +{ + auto assertDocument = [](ScDocument& rDoc) { + CPPUNIT_ASSERT_EQUAL(Color(0x00B050), getBackgroundColor(rDoc, u"H5"_ustr)); + }; + + createScDoc( + "xlsx/pivot-table/PivotTableCellFormatsTest_2_DataFieldInRow_ColumnLabelColor.xlsx"); + assertDocument(*getScDoc()); +} + +CPPUNIT_TEST_FIXTURE(ScPivotTableFormatsImportExport, + PivotTableCellFormatsTest_3_DataFieldInColumn_ColumnLabelColor) +{ + auto assertDocument = [](ScDocument& rDoc) { + CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, getFontColor(rDoc, u"H5"_ustr)); + CPPUNIT_ASSERT_EQUAL(Color(0x92D050), getBackgroundColor(rDoc, u"I5"_ustr)); + }; + + createScDoc( + "xlsx/pivot-table/PivotTableCellFormatsTest_3_DataFieldInColumn_ColumnLabelColor.xlsx"); + assertDocument(*getScDoc()); +} + +CPPUNIT_TEST_FIXTURE(ScPivotTableFormatsImportExport, + PivotTableCellFormatsTest_4_DataFieldInColumn_DataColor) +{ + auto assertDocument = [](ScDocument& rDoc) { + CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, getFontColor(rDoc, u"H7"_ustr)); + CPPUNIT_ASSERT_EQUAL(Color(0x92D050), getBackgroundColor(rDoc, u"I9"_ustr)); + }; + + createScDoc("xlsx/pivot-table/PivotTableCellFormatsTest_4_DataFieldInColumn_DataColor.xlsx"); + assertDocument(*getScDoc()); +} + +CPPUNIT_TEST_FIXTURE(ScPivotTableFormatsImportExport, + PivotTableCellFormatsTest_5_DataFieldInColumnAndTwoRowFields_DataColor) +{ + auto assertDocument = [](ScDocument& rDoc) { + CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"I8"_ustr)); + CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, getBackgroundColor(rDoc, u"I11"_ustr)); + CPPUNIT_ASSERT_EQUAL(Color(0x0070C0), getBackgroundColor(rDoc, u"J13"_ustr)); + }; + + createScDoc("xlsx/pivot-table//" + "PivotTableCellFormatsTest_5_DataFieldInColumnAndTwoRowFields_DataColor.xlsx"); + assertDocument(*getScDoc()); +} + +CPPUNIT_TEST_FIXTURE(ScPivotTableFormatsImportExport, + PivotTableCellFormatsTest_6_SingleDataFieldInColumn_DataColor) +{ + auto assertDocument = [](ScDocument& rDoc) { + CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"J8"_ustr)); + CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, getBackgroundColor(rDoc, u"J12"_ustr)); + }; + + createScDoc( + "xlsx/pivot-table//PivotTableCellFormatsTest_6_SingleDataFieldInColumn_DataColor.xlsx"); + assertDocument(*getScDoc()); +} + +CPPUNIT_TEST_FIXTURE(ScPivotTableFormatsImportExport, + PivotTableCellFormatsTest_7_TwoRowTwoColumnFields_DataColor) +{ + auto assertDocument = [](ScDocument& rDoc) { + CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"I7"_ustr)); + CPPUNIT_ASSERT_EQUAL(Color(0xFFC000), getBackgroundColor(rDoc, u"J8"_ustr)); + CPPUNIT_ASSERT_EQUAL(Color(0x0070C0), getBackgroundColor(rDoc, u"J9"_ustr)); + CPPUNIT_ASSERT_EQUAL(Color(0x00B0F0), getBackgroundColor(rDoc, u"J13"_ustr)); + CPPUNIT_ASSERT_EQUAL(Color(0x92D050), getBackgroundColor(rDoc, u"K12"_ustr)); + CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, getBackgroundColor(rDoc, u"L14"_ustr)); + }; + + createScDoc( + "xlsx/pivot-table//PivotTableCellFormatsTest_7_TwoRowTwoColumnFields_DataColor.xlsx"); + assertDocument(*getScDoc()); +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/unit/data/xlsx/pivot-table/PivotTableCellFormatsTest_1_DataFieldInRow_RowLabelColor.xlsx b/sc/qa/unit/data/xlsx/pivot-table/PivotTableCellFormatsTest_1_DataFieldInRow_RowLabelColor.xlsx Binary files differnew file mode 100644 index 000000000000..cd1b66f7cd06 --- /dev/null +++ b/sc/qa/unit/data/xlsx/pivot-table/PivotTableCellFormatsTest_1_DataFieldInRow_RowLabelColor.xlsx diff --git a/sc/qa/unit/data/xlsx/pivot-table/PivotTableCellFormatsTest_2_DataFieldInRow_ColumnLabelColor.xlsx b/sc/qa/unit/data/xlsx/pivot-table/PivotTableCellFormatsTest_2_DataFieldInRow_ColumnLabelColor.xlsx Binary files differnew file mode 100644 index 000000000000..e156cad5e041 --- /dev/null +++ b/sc/qa/unit/data/xlsx/pivot-table/PivotTableCellFormatsTest_2_DataFieldInRow_ColumnLabelColor.xlsx diff --git a/sc/qa/unit/data/xlsx/pivot-table/PivotTableCellFormatsTest_3_DataFieldInColumn_ColumnLabelColor.xlsx b/sc/qa/unit/data/xlsx/pivot-table/PivotTableCellFormatsTest_3_DataFieldInColumn_ColumnLabelColor.xlsx Binary files differnew file mode 100644 index 000000000000..462f6d1219e6 --- /dev/null +++ b/sc/qa/unit/data/xlsx/pivot-table/PivotTableCellFormatsTest_3_DataFieldInColumn_ColumnLabelColor.xlsx diff --git a/sc/qa/unit/data/xlsx/pivot-table/PivotTableCellFormatsTest_4_DataFieldInColumn_DataColor.xlsx b/sc/qa/unit/data/xlsx/pivot-table/PivotTableCellFormatsTest_4_DataFieldInColumn_DataColor.xlsx Binary files differnew file mode 100644 index 000000000000..e3eaf72b3ebf --- /dev/null +++ b/sc/qa/unit/data/xlsx/pivot-table/PivotTableCellFormatsTest_4_DataFieldInColumn_DataColor.xlsx diff --git a/sc/qa/unit/data/xlsx/pivot-table/PivotTableCellFormatsTest_5_DataFieldInColumnAndTwoRowFields_DataColor.xlsx b/sc/qa/unit/data/xlsx/pivot-table/PivotTableCellFormatsTest_5_DataFieldInColumnAndTwoRowFields_DataColor.xlsx Binary files differnew file mode 100644 index 000000000000..2e1d3c62296e --- /dev/null +++ b/sc/qa/unit/data/xlsx/pivot-table/PivotTableCellFormatsTest_5_DataFieldInColumnAndTwoRowFields_DataColor.xlsx diff --git a/sc/qa/unit/data/xlsx/pivot-table/PivotTableCellFormatsTest_6_SingleDataFieldInColumn_DataColor.xlsx b/sc/qa/unit/data/xlsx/pivot-table/PivotTableCellFormatsTest_6_SingleDataFieldInColumn_DataColor.xlsx Binary files differnew file mode 100644 index 000000000000..4e82b47ec1e5 --- /dev/null +++ b/sc/qa/unit/data/xlsx/pivot-table/PivotTableCellFormatsTest_6_SingleDataFieldInColumn_DataColor.xlsx diff --git a/sc/qa/unit/data/xlsx/pivot-table/PivotTableCellFormatsTest_7_TwoRowTwoColumnFields_DataColor.xlsx b/sc/qa/unit/data/xlsx/pivot-table/PivotTableCellFormatsTest_7_TwoRowTwoColumnFields_DataColor.xlsx Binary files differnew file mode 100644 index 000000000000..798e3bf82772 --- /dev/null +++ b/sc/qa/unit/data/xlsx/pivot-table/PivotTableCellFormatsTest_7_TwoRowTwoColumnFields_DataColor.xlsx |