sc/source/filter/inc/condformatbuffer.hxx | 4 ++++ sc/source/filter/oox/condformatbuffer.cxx | 25 +++++++++++++++++++++++++ sc/source/filter/oox/condformatcontext.cxx | 4 +++- 3 files changed, 32 insertions(+), 1 deletion(-)
New commits: commit 7f733ff497a2ac1731229b3963602f1feb3ef88e Author: Henry Castro <hcas...@collabora.com> AuthorDate: Tue Mar 28 18:03:21 2023 -0400 Commit: Henry Castro <hcas...@collabora.com> CommitDate: Fri Jun 16 22:49:05 2023 +0200 sc: filter: oox: fix conditional color scale same range Otherwise, the condition color scale the priority order will be lost. <conditionalFormatting sqref="G1:G5"> <cfRule type="colorScale" priority="5"> <colorScale> <cfvo type="min" val=""""/> <cfvo type="max" val=""""/> <color theme="5" tint="-0.249977111117893"/> <color rgb="FF92D050"/> </colorScale> </cfRule> </conditionalFormatting> <conditionalFormatting sqref="G1:G5"> <cfRule type="colorScale" priority="1"> <colorScale> <cfvo type="min" val=""""/> <cfvo type="max" val=""""/> <color theme="0" tint="0"/> <color theme="0" tint="0"/> </colorScale> </cfRule> </conditionalFormatting> Signed-off-by: Henry Castro <hcas...@collabora.com> Change-Id: I33fa73bfe8f0bada1cf79bc07be2e43495a4290c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149721 Reviewed-by: Andras Timar <andras.ti...@collabora.com> Tested-by: Andras Timar <andras.ti...@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151979 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153182 Tested-by: Jenkins diff --git a/sc/source/filter/inc/condformatbuffer.hxx b/sc/source/filter/inc/condformatbuffer.hxx index a1cc7bb81381..81961151beb8 100644 --- a/sc/source/filter/inc/condformatbuffer.hxx +++ b/sc/source/filter/inc/condformatbuffer.hxx @@ -148,6 +148,7 @@ private: /** Represents a single rule in a conditional formatting. */ class CondFormatRule final : public WorksheetHelper { +friend class CondFormatBuffer; public: explicit CondFormatRule( const CondFormat& rCondFormat, ScConditionalFormat* pFormat ); @@ -167,6 +168,7 @@ public: /** Returns the priority of this rule. */ sal_Int32 getPriority() const { return maModel.mnPriority; } + ColorScaleRule* getCurColorScale() const { return mpColor.get(); } ColorScaleRule* getColorScale(); DataBarRule* getDataBar(); @@ -310,6 +312,8 @@ public: static sal_Int32 convertToApiOperator( sal_Int32 nToken ); static ScConditionMode convertToInternalOperator( sal_Int32 nToken ); void finalizeImport(); + bool insertColorScale(CondFormatRef const & xCondFmt, CondFormatRuleRef const & xRule); + private: CondFormatRef createCondFormat(); void updateImport(const ScDataBarFormatData* pTarget); diff --git a/sc/source/filter/oox/condformatbuffer.cxx b/sc/source/filter/oox/condformatbuffer.cxx index 4ce1ca7fc257..d049534d2f6a 100644 --- a/sc/source/filter/oox/condformatbuffer.cxx +++ b/sc/source/filter/oox/condformatbuffer.cxx @@ -1208,6 +1208,31 @@ void CondFormatBuffer::updateImport(const ScDataBarFormatData* pTarget) } } +bool CondFormatBuffer::insertColorScale(CondFormatRef const & xCondFmt, CondFormatRuleRef const & xRule) +{ + CondFormatRef xFoundFmt; + ScRangeList aRanges = xCondFmt->getRanges(); + + for (auto& rCondFmt : maCondFormats) + { + if (xCondFmt == rCondFmt) + continue; + + if (aRanges == rCondFmt->getRanges()) + { + xFoundFmt = rCondFmt; + break; + } + } + + if (xFoundFmt) + { + xRule->mpFormat = xFoundFmt->mpFormat; + xFoundFmt->insertRule(xRule); + } + + return static_cast<bool>(xFoundFmt); +} void CondFormatBuffer::finalizeImport() { diff --git a/sc/source/filter/oox/condformatcontext.cxx b/sc/source/filter/oox/condformatcontext.cxx index 845d105b7605..a28b7b12453d 100644 --- a/sc/source/filter/oox/condformatcontext.cxx +++ b/sc/source/filter/oox/condformatcontext.cxx @@ -205,7 +205,9 @@ void CondFormatContext::onEndElement() case XLS_TOKEN( cfRule ): if (mxCondFmt && mxRule) { - mxCondFmt->insertRule(mxRule); + if (!mxRule->getCurColorScale() || + !getCondFormats().insertColorScale(mxCondFmt, mxRule)) + mxCondFmt->insertRule(mxRule); } break; }