sc/qa/unit/ucalc_condformat.cxx | 52 +++++++++++++++++++++++++++++++++++++++ sc/source/core/data/fillinfo.cxx | 20 +++++++++++++++ 2 files changed, 72 insertions(+)
New commits: commit 83ead6e42f82c03f807cb4b003fcac35135de459 Author: Tibor Nagy <nagy.tib...@nisz.hu> AuthorDate: Wed Jul 12 17:17:10 2023 +0200 Commit: László Németh <nem...@numbertext.org> CommitDate: Wed Jul 26 11:04:27 2023 +0200 tdf#155322 sc: fix conditional format color scale in merged cells Only first cell of a merged range got coloring, now all of them. See also commit f142b3e84f97ae678bd0a94614e867d369680458 "tdf#131471 sc: fix background color of conditional formatting style". Change-Id: I0e95bf49369de219e659295643aaf2659dd3de48 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154362 Tested-by: László Németh <nem...@numbertext.org> Reviewed-by: László Németh <nem...@numbertext.org> (cherry picked from commit ee4bd745be5dee15b68ca483f7f7771957ae3b3e) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154865 diff --git a/sc/qa/unit/ucalc_condformat.cxx b/sc/qa/unit/ucalc_condformat.cxx index 78978daec33a..634373b58ccc 100644 --- a/sc/qa/unit/ucalc_condformat.cxx +++ b/sc/qa/unit/ucalc_condformat.cxx @@ -319,6 +319,58 @@ CPPUNIT_TEST_FIXTURE(TestCondformat, testDataBarCondCopyPaste) m_pDoc->DeleteTab(0); } +CPPUNIT_TEST_FIXTURE(TestCondformat, testColorScaleInMergedCell) +{ + m_pDoc->InsertTab(0, "Test"); + m_pDoc->SetValue(ScAddress(0, 0, 0), 1.0); + + // Add a conditional format to A1. + auto pFormat = std::make_unique<ScConditionalFormat>(1, m_pDoc); + pFormat->SetRange(ScRange(0, 0, 0, 0, 0, 0)); + auto pFormatTmp = pFormat.get(); + sal_uLong nKey = m_pDoc->AddCondFormat(std::move(pFormat), 0); + + // Add color scale entries. + // The coloring is based on the value. (BLUE (x <= 0), GREEN (x == 1), RED (x >= 2)) + ScColorScaleFormat* pColorScaleFormat = new ScColorScaleFormat(m_pDoc); + ScColorScaleEntry* pEntryBlue = new ScColorScaleEntry(0, COL_BLUE); + ScColorScaleEntry* pEntryGreen = new ScColorScaleEntry(1, COL_GREEN); + ScColorScaleEntry* pEntryRed = new ScColorScaleEntry(2, COL_RED); + pColorScaleFormat->AddEntry(pEntryBlue); + pColorScaleFormat->AddEntry(pEntryGreen); + pColorScaleFormat->AddEntry(pEntryRed); + + pFormatTmp->AddEntry(pColorScaleFormat); + + // Apply the format to the range. + m_pDoc->AddCondFormatData(pFormatTmp->GetRange(), 0, nKey); + + m_pDoc->DoMerge(0, 0, 0, 1, 0); // A1:A2 + CPPUNIT_ASSERT(m_pDoc->IsMerged(ScAddress(0, 0, 0))); + + ScTableInfo aTabInfo; + m_pDoc->FillInfo(aTabInfo, 0, 0, 0, 1, 0, 1, 1, false, false); + RowInfo* pRowInfo = aTabInfo.mpRowInfo.get(); + + RowInfo* pRowInfoA1 = &pRowInfo[1]; + ScCellInfo* pCellInfoA1 = &pRowInfoA1->cellInfo(0); + // Check if there is a color scale in A1. + CPPUNIT_ASSERT_EQUAL_MESSAGE("There is no color scale in cell A1!", true, + pCellInfoA1->mxColorScale.has_value()); + + RowInfo* pRowInfoA2 = &pRowInfo[2]; + ScCellInfo* pCellInfoA2 = &pRowInfoA2->cellInfo(0); + // Check if there is a color scale in A2. + CPPUNIT_ASSERT_EQUAL_MESSAGE("There is no color scale in cell A2!", true, + pCellInfoA2->mxColorScale.has_value()); + + // Check that cells A1 and A2 have the same color scale. (GREEN) + CPPUNIT_ASSERT(pCellInfoA1->mxColorScale.value().IsRGBEqual(pCellInfoA2->mxColorScale.value())); + + m_pDoc->DeleteTab(0); +} + + CPPUNIT_TEST_FIXTURE(TestCondformat, testColorScaleCondCopyPaste) { m_pDoc->InsertTab(0, "Test"); diff --git a/sc/source/core/data/fillinfo.cxx b/sc/source/core/data/fillinfo.cxx index 7c95701e9705..db9eadc671ad 100644 --- a/sc/source/core/data/fillinfo.cxx +++ b/sc/source/core/data/fillinfo.cxx @@ -743,6 +743,26 @@ void ScDocument::FillInfo( pInfo->pShadowAttr = pShadowItem; if (pInfo->pShadowAttr != pDefShadow) bAnyShadow = true; + + const ScCondFormatIndexes& rCondFormatIndex + = pStartPattern->GetItem(ATTR_CONDITIONAL).GetCondFormatData(); + + if (pCondFormList && !pStartCond && !rCondFormatIndex.empty()) + { + for (const auto& rItem : rCondFormatIndex) + { + const ScConditionalFormat* pCondForm = pCondFormList->GetFormat(rItem); + if (pCondForm) + { + ScCondFormatData aData = pCondForm->GetData( + pInfo->maCell, ScAddress(nStartX, nStartY, nTab)); + + // Color scale + if (aData.mxColorScale && !pInfo->mxColorScale) + pInfo->mxColorScale = aData.mxColorScale; + } + } + } } } }