sc/inc/column.hxx | 2 + sc/qa/unit/subsequent_filters_test2.cxx | 39 ++++++++++++++++++++ sc/source/core/data/column3.cxx | 60 ++++++++++++++++++++++++++++++++ sc/source/core/data/table3.cxx | 6 +++ 4 files changed, 107 insertions(+)
New commits: commit 94d14f1f7aec4931dadee3520ce6b5d99d3d333f Author: Henry Castro <hcas...@collabora.com> AuthorDate: Fri Nov 24 10:00:54 2023 -0400 Commit: Henry Castro <hcas...@collabora.com> CommitDate: Mon Nov 27 13:53:03 2023 +0100 sc: qa: add unit test "testBackColorFilter" Signed-off-by: Henry Castro <hcas...@collabora.com> Change-Id: Icdccd6778d1157bb31f38b510a58562a640bdeae Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159929 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> diff --git a/sc/qa/unit/subsequent_filters_test2.cxx b/sc/qa/unit/subsequent_filters_test2.cxx index dc2c76ef2fb3..4a58bc35d7ca 100644 --- a/sc/qa/unit/subsequent_filters_test2.cxx +++ b/sc/qa/unit/subsequent_filters_test2.cxx @@ -32,6 +32,7 @@ #include <editeng/colritem.hxx> #include <docmodel/color/ComplexColor.hxx> #include <docmodel/theme/ThemeColorType.hxx> +#include <docpool.hxx> #include <dbdata.hxx> #include <validat.hxx> #include <formulacell.hxx> @@ -51,6 +52,7 @@ #include <hints.hxx> #include <detfunc.hxx> #include <scerrors.hxx> +#include <filterentries.hxx> #include <com/sun/star/drawing/XDrawPageSupplier.hpp> #include <com/sun/star/drawing/XControlShape.hpp> @@ -198,6 +200,7 @@ public: void testSingleLine(); void testNamedTableRef(); void testRowImportCellStyleIssue(); + void testBackColorFilter(); CPPUNIT_TEST_SUITE(ScFiltersTest2); @@ -322,6 +325,7 @@ public: CPPUNIT_TEST(testSingleLine); CPPUNIT_TEST(testNamedTableRef); CPPUNIT_TEST(testRowImportCellStyleIssue); + CPPUNIT_TEST(testBackColorFilter); CPPUNIT_TEST_SUITE_END(); }; @@ -3131,6 +3135,41 @@ void ScFiltersTest2::testRowImportCellStyleIssue() } } +void ScFiltersTest2::testBackColorFilter() +{ + Color aBackColor1(0xc99c00); + Color aBackColor2(0x0369a3); + + createScDoc(); + ScDocument* pDoc = getScDoc(); + + ScPatternAttr aPattern1(pDoc->GetPool()); + aPattern1.GetItemSet().Put(SvxBrushItem(aBackColor1, ATTR_BACKGROUND)); + + ScPatternAttr aPattern2(pDoc->GetPool()); + aPattern2.GetItemSet().Put(SvxBrushItem(aBackColor2, ATTR_BACKGROUND)); + + // Apply the pattern to cell A1:A2 + pDoc->ApplyPatternAreaTab(0, 0, 0, 1, 0, aPattern1); + + // Apply the pattern to cell A3:A5 + pDoc->ApplyPatternAreaTab(0, 2, 0, 4, 0, aPattern2); + + { + ScRefCellValue aCell; + aCell.assign(*pDoc, ScAddress(0, 0, 0)); + CPPUNIT_ASSERT_MESSAGE("Cell A1 should be empty.", aCell.isEmpty()); + aCell.assign(*pDoc, ScAddress(0, 2, 0)); + CPPUNIT_ASSERT_MESSAGE("Cell A3 should be empty.", aCell.isEmpty()); + } + + { + ScFilterEntries aFilterEntries; + pDoc->GetFilterEntriesArea(0, 0, 4, 0, true, aFilterEntries); + CPPUNIT_ASSERT_EQUAL(size_t(2), aFilterEntries.getBackgroundColors().size()); + } +} + CPPUNIT_TEST_SUITE_REGISTRATION(ScFiltersTest2); CPPUNIT_PLUGIN_IMPLEMENT(); commit 826eae46095b2184554565bab1792e96964a720f Author: Henry Castro <hcas...@collabora.com> AuthorDate: Thu Nov 23 11:49:15 2023 -0400 Commit: Henry Castro <hcas...@collabora.com> CommitDate: Mon Nov 27 13:52:49 2023 +0100 sc: fix back color filter entries The function "GetFilterEntries" iterates only that contains cell data value entries, the background color filter feature requires to iterate background color attribute which is not stored in multi type vector cells. Signed-off-by: Henry Castro <hcas...@collabora.com> Change-Id: I372db48d2399f62712f642eefdbfea8885b09f58 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159864 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx index cbdf82edecbc..7a2bbc30ade9 100644 --- a/sc/inc/column.hxx +++ b/sc/inc/column.hxx @@ -598,6 +598,8 @@ public: sc::ColumnBlockConstPosition& rBlockPos, SCROW nStartRow, SCROW nEndRow, ScFilterEntries& rFilterEntries, bool bFiltering, bool bFilteredRow ); + void GetBackColorFilterEntries(SCROW nRow1, SCROW nRow2, ScFilterEntries& rFilterEntries ); + bool GetDataEntries( SCROW nRow, std::set<ScTypedStrData>& rStrings) const; void UpdateInsertTabAbs(SCTAB nNewPos); diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx index ca16c49d8de8..2ef0f9aee3df 100644 --- a/sc/source/core/data/column3.cxx +++ b/sc/source/core/data/column3.cxx @@ -2753,6 +2753,66 @@ void ScColumn::GetFilterEntries( sc::ParseAll(rBlockPos.miCellPos, maCells, nStartRow, nEndRow, aFunc, aFunc); } +void ScColumn::GetBackColorFilterEntries(SCROW nRow1, SCROW nRow2, ScFilterEntries& rFilterEntries) +{ + Color aBackColor; + bool bCondBackColor = false; + ScAddress aCell(GetCol(), 0, GetTab()); + ScConditionalFormat* pCondFormat = nullptr; + + const SfxItemSet* pCondSet = nullptr; + const SvxBrushItem* pBrush = nullptr; + const ScPatternAttr* pPattern = nullptr; + const ScColorScaleFormat* pColFormat = nullptr; + + if (!GetDoc().ValidRow(nRow1) || !GetDoc().ValidRow(nRow2)) + return; + + while (nRow1 <= nRow2) + { + aCell.SetRow(nRow1); + pPattern = GetDoc().GetPattern(aCell.Col(), aCell.Row(), aCell.Tab()); + if (pPattern) + { + if (!pPattern->GetItem(ATTR_CONDITIONAL).GetCondFormatData().empty()) + { + pCondSet = GetDoc().GetCondResult(GetCol(), nRow1, GetTab()); + pBrush = &pPattern->GetItem(ATTR_BACKGROUND, pCondSet); + aBackColor = pBrush->GetColor(); + bCondBackColor = true; + } + } + + pCondFormat = GetDoc().GetCondFormat(aCell.Col(), aCell.Row(), aCell.Tab()); + if (pCondFormat) + { + for (size_t nFormat = 0; nFormat < pCondFormat->size(); nFormat++) + { + auto aEntry = pCondFormat->GetEntry(nFormat); + if (aEntry->GetType() == ScFormatEntry::Type::Colorscale) + { + pColFormat = static_cast<const ScColorScaleFormat*>(aEntry); + std::optional<Color> oColor = pColFormat->GetColor(aCell); + if (oColor) + { + aBackColor = *oColor; + bCondBackColor = true; + } + } + } + } + + if (!bCondBackColor) + { + pBrush = GetDoc().GetAttr(aCell, ATTR_BACKGROUND); + aBackColor = pBrush->GetColor(); + } + + rFilterEntries.addBackgroundColor(aBackColor); + nRow1++; + } +} + namespace { /** diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx index bdf16a69aad4..77b66ec0b750 100644 --- a/sc/source/core/data/table3.cxx +++ b/sc/source/core/data/table3.cxx @@ -2963,6 +2963,12 @@ void ScTable::GetFilterEntries( SCCOL nCol, SCROW nRow1, SCROW nRow2, ScFilterEn sc::ColumnBlockConstPosition aBlockPos; aCol[nCol].InitBlockPosition(aBlockPos); aCol[nCol].GetFilterEntries(aBlockPos, nRow1, nRow2, rFilterEntries, bFiltering, false /*bFilteredRow*/); + + SCROW nLastRow = aBlockPos.miCellPos->position; + if (nLastRow < nRow2) + { + aCol[nCol].GetBackColorFilterEntries(nLastRow, nRow2, rFilterEntries); + } } void ScTable::GetFilteredFilterEntries(