diff options
author | Henry Castro <hcastro@collabora.com> | 2023-11-23 11:49:15 -0400 |
---|---|---|
committer | Henry Castro <hcastro@collabora.com> | 2023-11-29 12:05:25 +0100 |
commit | 8b2369236dea7d6863c2df3d4ce5e356c9c8010c (patch) | |
tree | 080f8143548a56788f85e2492d39b33fcf0750ec /sc | |
parent | 05f60be48a51a64ce99a7a7b62ae030002b16a14 (diff) |
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 <hcastro@collabora.com>
Change-Id: I372db48d2399f62712f642eefdbfea8885b09f58
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159864
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
(cherry picked from commit 826eae46095b2184554565bab1792e96964a720f)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159905
Tested-by: Jenkins
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/column.hxx | 2 | ||||
-rw-r--r-- | sc/source/core/data/column3.cxx | 60 | ||||
-rw-r--r-- | sc/source/core/data/table3.cxx | 6 |
3 files changed, 68 insertions, 0 deletions
diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx index 26ef79da2e6d..cefd03fd388e 100644 --- a/sc/inc/column.hxx +++ b/sc/inc/column.hxx @@ -599,6 +599,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 054e334edb06..a0b0c639a003 100644 --- a/sc/source/core/data/column3.cxx +++ b/sc/source/core/data/column3.cxx @@ -2701,6 +2701,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 71cf80bcef38..359cc5dcc4f5 100644 --- a/sc/source/core/data/table3.cxx +++ b/sc/source/core/data/table3.cxx @@ -3018,6 +3018,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( |