sc/inc/colorscale.hxx | 3 +++ sc/inc/conditio.hxx | 5 +++++ sc/source/core/data/colorscale.cxx | 21 +++++++++++++++++++++ sc/source/core/data/conditio.cxx | 20 ++++++++++++++++++++ sc/source/core/data/table2.cxx | 3 +++ sc/source/filter/html/htmlexp.cxx | 23 ++++++++++++++++++++++- 6 files changed, 74 insertions(+), 1 deletion(-)
New commits: commit 11be07a66dee9f324850cfbdf7d92a4c6774902d Author: Henry Castro <[email protected]> AuthorDate: Thu May 11 16:29:55 2023 -0400 Commit: Andras Timar <[email protected]> CommitDate: Wed Jun 14 14:31:25 2023 +0200 tdf#154477: sc: filter: html: fix missing color scale conditional format When copying a range cell to an external application that request html data, the color scale conditional format does not have an associate a set attribute. Signed-off-by: Henry Castro <[email protected]> Change-Id: I82b466a2100abc5070e92f844dc706d9b015c2e1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151837 Tested-by: Jenkins (cherry picked from commit 604c27f7c382bdd6baea73e60eed6525b9bfbd3d) diff --git a/sc/source/filter/html/htmlexp.cxx b/sc/source/filter/html/htmlexp.cxx index 9c9f8745fac0..1f9edb6b5a3d 100644 --- a/sc/source/filter/html/htmlexp.cxx +++ b/sc/source/filter/html/htmlexp.cxx @@ -64,6 +64,8 @@ #include <editutil.hxx> #include <ftools.hxx> #include <cellvalue.hxx> +#include <conditio.hxx> +#include <colorscale.hxx> #include <mtvelements.hxx> #include <editeng/flditem.hxx> @@ -880,10 +882,27 @@ void ScHTMLExport::WriteTables() void ScHTMLExport::WriteCell( sc::ColumnBlockPosition& rBlockPos, SCCOL nCol, SCROW nRow, SCTAB nTab ) { + std::optional<Color> aColorScale; ScAddress aPos( nCol, nRow, nTab ); ScRefCellValue aCell(*pDoc, aPos, rBlockPos); const ScPatternAttr* pAttr = pDoc->GetPattern( nCol, nRow, nTab ); const SfxItemSet* pCondItemSet = pDoc->GetCondResult( nCol, nRow, nTab, &aCell ); + if (!pCondItemSet) + { + ScConditionalFormatList* pCondList = pDoc->GetCondFormList(nTab); + const ScCondFormatItem& rCondItem = pAttr->GetItem(ATTR_CONDITIONAL); + const ScCondFormatIndexes& rCondIndex = rCondItem.GetCondFormatData(); + if (rCondIndex.size() > 0) + { + ScConditionalFormat* pCondFmt = pCondList->GetFormat(rCondIndex[0]); + if (pCondFmt) + { + const ScColorScaleFormat* pEntry = dynamic_cast<const ScColorScaleFormat*>(pCondFmt->GetEntry(0)); + if (pEntry) + aColorScale = pEntry->GetColor(aPos); + } + } + } const ScMergeFlagAttr& rMergeFlagAttr = pAttr->GetItem( ATTR_MERGE_FLAG, pCondItemSet ); if ( rMergeFlagAttr.IsOverlapped() ) @@ -1022,7 +1041,9 @@ void ScHTMLExport::WriteCell( sc::ColumnBlockPosition& rBlockPos, SCCOL nCol, SC ATTR_BACKGROUND, pCondItemSet ); Color aBgColor; - if ( rBrushItem.GetColor().GetAlpha() == 0 ) + if ( aColorScale ) + aBgColor = *aColorScale; + else if ( rBrushItem.GetColor().GetAlpha() == 0 ) aBgColor = aHTMLStyle.aBackgroundColor; // No unwanted background color else aBgColor = rBrushItem.GetColor(); commit bea5434e280f20568de50c9c90c946259c7d3db3 Author: Henry Castro <[email protected]> AuthorDate: Thu May 11 16:23:03 2023 -0400 Commit: Andras Timar <[email protected]> CommitDate: Wed Jun 14 14:31:09 2023 +0200 tdf#154477: sc: copy cache values when clone color conditional format When clone a conditional format list, also copy the cache values that hold the min and max values, otherwise if clone occurs when copying to the clipboard the values have wrong data due to limiting range cells copied. Signed-off-by: Henry Castro <[email protected]> Change-Id: Id9085a1488a3bde24842e0d2e062c9b425074157 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151836 Tested-by: Jenkins (cherry picked from commit c85255fd7a62bec9342fa6f2a79d1395979d54be) diff --git a/sc/inc/colorscale.hxx b/sc/inc/colorscale.hxx index 9923eac4c572..fc5c34dda287 100644 --- a/sc/inc/colorscale.hxx +++ b/sc/inc/colorscale.hxx @@ -224,6 +224,8 @@ public: virtual ~ScColorFormat() override; const ScRangeList& GetRange() const; + void SetCache(const std::vector<double>& aValues); + std::vector<double> GetCache() const; virtual void SetParent(ScConditionalFormat* pParent) override; diff --git a/sc/source/core/data/colorscale.cxx b/sc/source/core/data/colorscale.cxx index 33880848d5fc..246541b78a68 100644 --- a/sc/source/core/data/colorscale.cxx +++ b/sc/source/core/data/colorscale.cxx @@ -378,6 +378,9 @@ ScColorScaleFormat::ScColorScaleFormat(ScDocument* pDoc, const ScColorScaleForma { maColorScales.emplace_back(new ScColorScaleEntry(pDoc, *rxEntry)); } + + auto aCache = rFormat.GetCache(); + SetCache(aCache); } ScColorFormat* ScColorScaleFormat::Clone(ScDocument* pDoc) const @@ -439,6 +442,18 @@ const ScRangeList& ScColorFormat::GetRange() const return mpParent->GetRange(); } +std::vector<double> ScColorFormat::GetCache() const +{ + std::vector<double> empty; + return mpCache ? mpCache->maValues : empty; +} + +void ScColorFormat::SetCache(const std::vector<double>& aValues) +{ + mpCache.reset(new ScColorFormatCache); + mpCache->maValues = aValues; +} + std::vector<double>& ScColorFormat::getValues() const { if(!mpCache) commit b81ccbf6d48c6c2e79929332f5574ac5e6f48d6d Author: Henry Castro <[email protected]> AuthorDate: Thu May 11 16:07:10 2023 -0400 Commit: Andras Timar <[email protected]> CommitDate: Wed Jun 14 14:30:48 2023 +0200 tdf#154477: sc: add "updateValues" method to conditional format list When copying a range cells to a clipboard, if exists a color scale conditional format from different ranges, it should update the min and max values, otherwise the color scale conditional format could not calculate min and max values due to limiting range cell copied. Signed-off-by: Henry Castro <[email protected]> Change-Id: I660e18090a60b99ddf2b55ce1f713fd41121290e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151835 Tested-by: Jenkins (cherry picked from commit fcb348da642f7e5c41fe495cf6289f9992bfa1b9) diff --git a/sc/inc/colorscale.hxx b/sc/inc/colorscale.hxx index de74030dbc85..9923eac4c572 100644 --- a/sc/inc/colorscale.hxx +++ b/sc/inc/colorscale.hxx @@ -229,6 +229,7 @@ public: virtual void startRendering() override; virtual void endRendering() override; + virtual void updateValues() override; protected: std::vector<double>& getValues() const; diff --git a/sc/inc/conditio.hxx b/sc/inc/conditio.hxx index d47b841b0880..ed4c196c2066 100644 --- a/sc/inc/conditio.hxx +++ b/sc/inc/conditio.hxx @@ -251,6 +251,7 @@ public: virtual void startRendering(); virtual void endRendering(); + virtual void updateValues(); protected: ScDocument* mpDoc; @@ -598,6 +599,8 @@ public: void startRendering(); void endRendering(); + void updateValues(); + // Forced recalculation for formulas void CalcAll(); }; @@ -683,6 +686,8 @@ public: void startRendering(); void endRendering(); + void updateValues(); + sal_uInt32 getMaxKey() const; /// Forced recalculation of formulas diff --git a/sc/source/core/data/colorscale.cxx b/sc/source/core/data/colorscale.cxx index 0a357828c61e..33880848d5fc 100644 --- a/sc/source/core/data/colorscale.cxx +++ b/sc/source/core/data/colorscale.cxx @@ -511,6 +511,12 @@ void ScColorFormat::endRendering() mpCache.reset(); } +void ScColorFormat::updateValues() +{ + getMinValue(); + getMaxValue(); +} + namespace { sal_uInt8 GetColorValue( double nVal, double nVal1, sal_uInt8 nColVal1, double nVal2, sal_uInt8 nColVal2 ) diff --git a/sc/source/core/data/conditio.cxx b/sc/source/core/data/conditio.cxx index dae08455b0e9..a9ac1f45fd00 100644 --- a/sc/source/core/data/conditio.cxx +++ b/sc/source/core/data/conditio.cxx @@ -73,6 +73,10 @@ void ScFormatEntry::endRendering() { } +void ScFormatEntry::updateValues() +{ +} + static bool lcl_HasRelRef( ScDocument* pDoc, const ScTokenArray* pFormula, sal_uInt16 nRecursion = 0 ) { if (pFormula) @@ -2057,6 +2061,14 @@ void ScConditionalFormat::endRendering() } } +void ScConditionalFormat::updateValues() +{ + for(auto& rxEntry : maEntries) + { + rxEntry->updateValues(); + } +} + void ScConditionalFormat::CalcAll() { for(const auto& rxEntry : maEntries) @@ -2304,6 +2316,14 @@ void ScConditionalFormatList::endRendering() } } +void ScConditionalFormatList::updateValues() +{ + for (auto const& it : m_ConditionalFormats) + { + it->updateValues(); + } +} + void ScConditionalFormatList::clear() { m_ConditionalFormats.clear(); diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx index 713be792ac19..a424a0a8308d 100644 --- a/sc/source/core/data/table2.cxx +++ b/sc/source/core/data/table2.cxx @@ -529,7 +529,10 @@ void ScTable::CopyToClip( for (SCCOL i = nCol1; i <= nCol2; i++) pTable->aCol[i].RemoveProtected(nRow1, nRow2); + mpCondFormatList->startRendering(); + mpCondFormatList->updateValues(); pTable->mpCondFormatList.reset(new ScConditionalFormatList(pTable->rDocument, *mpCondFormatList)); + mpCondFormatList->endRendering(); } void ScTable::CopyToClip(
