[Libreoffice-commits] core.git: Branch 'libreoffice-5-4-0' - sc/inc sc/source

Markus Mohrhard markus.mohrhard at googlemail.com
Fri Jul 21 09:36:17 UTC 2017


 sc/inc/colorscale.hxx                  |   18 ++++++++-
 sc/source/core/data/colorscale.cxx     |   65 ++++++++++++++++++++++++++++++---
 sc/source/filter/xml/xmlcondformat.cxx |   13 +++++-
 sc/source/filter/xml/xmlcondformat.hxx |    1 
 4 files changed, 88 insertions(+), 9 deletions(-)

New commits:
commit 3aa9933caa929e454b68e6efc1f21d485c483932
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Thu Mar 16 22:43:43 2017 +0100

    repaint whole range for range based cond formats, tdf#105696
    
    The range based cond formats need to be repainted across the whole
    range. This ensures that a change in condition which affects all cells
    causes a repaint.
    
    Change-Id: Ie6dd10088a1c11c1bafd1faa9c429a35a6469ff2
    Reviewed-on: https://gerrit.libreoffice.org/35302
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Markus Mohrhard <markus.mohrhard at googlemail.com>
    (cherry picked from commit 49922897d68835ae4e5c850b3c55107157fe7548)
    Reviewed-on: https://gerrit.libreoffice.org/39713
    Reviewed-by: Eike Rathke <erack at redhat.com>
    (cherry picked from commit 6ed7a3085216caf29f9066154fccc6ee2f1b953d)
    Reviewed-on: https://gerrit.libreoffice.org/39925
    Reviewed-by: Dennis Francis <dennis.francis at collabora.co.uk>
    Reviewed-by: Michael Meeks <michael.meeks at collabora.com>
    Tested-by: Eike Rathke <erack at redhat.com>

diff --git a/sc/inc/colorscale.hxx b/sc/inc/colorscale.hxx
index 840b6824963d..ab94b22a34d3 100644
--- a/sc/inc/colorscale.hxx
+++ b/sc/inc/colorscale.hxx
@@ -49,6 +49,7 @@ private:
     std::unique_ptr<ScFormulaCell> mpCell;
     std::unique_ptr<ScFormulaListener> mpListener;
     ScColorScaleEntryType meType;
+    ScConditionalFormat* mpFormat;
 
 public:
     ScColorScaleEntry(double nVal, const Color& rCol);
@@ -74,6 +75,8 @@ public:
 
     ScColorScaleEntryType GetType() const { return meType;}
     void SetType( ScColorScaleEntryType eType );
+
+    void SetRepaintCallback(ScConditionalFormat* pParent);
 };
 
 namespace databar
@@ -97,7 +100,10 @@ struct SC_DLLPUBLIC ScDataBarFormatData
         meAxisPosition(databar::AUTOMATIC),
         mnMinLength(0),
         mnMaxLength(100),
-        mbOnlyBar(false){}
+        mbOnlyBar(false),
+        mpUpperLimit(new ScColorScaleEntry()),
+        mpLowerLimit(new ScColorScaleEntry())
+    {}
 
     ScDataBarFormatData(const ScDataBarFormatData& r):
         maPositiveColor(r.maPositiveColor),
@@ -114,8 +120,12 @@ struct SC_DLLPUBLIC ScDataBarFormatData
 
         if(r.mpLowerLimit)
             mpLowerLimit.reset( new ScColorScaleEntry(*r.mpLowerLimit));
+        else
+            mpLowerLimit.reset(new ScColorScaleEntry());
         if(r.mpUpperLimit)
             mpUpperLimit.reset( new ScColorScaleEntry(*r.mpUpperLimit));
+        else
+            mpUpperLimit.reset(new ScColorScaleEntry());
     }
 
     /**
@@ -255,6 +265,8 @@ public:
     virtual ~ScColorScaleFormat() override;
     virtual ScColorFormat* Clone(ScDocument* pDoc) const override;
 
+    virtual void SetParent(ScConditionalFormat* pParent) override;
+
     Color* GetColor(const ScAddress& rAddr) const;
     void AddEntry(ScColorScaleEntry* pEntry);
 
@@ -288,6 +300,8 @@ public:
     ScDataBarFormat(ScDocument* pDoc, const ScDataBarFormat& rFormat);
     virtual ScColorFormat* Clone(ScDocument* pDoc) const override;
 
+    virtual void SetParent(ScConditionalFormat* pParent) override;
+
     ScDataBarInfo* GetDataBarInfo(const ScAddress& rAddr) const;
 
     void SetDataBarData( ScDataBarFormatData* pData );
@@ -348,6 +362,8 @@ public:
 
     virtual ScColorFormat* Clone(ScDocument* pDoc) const override;
 
+    virtual void SetParent(ScConditionalFormat* pParent) override;
+
     ScIconSetInfo* GetIconSetInfo(const ScAddress& rAddr) const;
 
     void SetIconSetData( ScIconSetFormatData* pData );
diff --git a/sc/source/core/data/colorscale.cxx b/sc/source/core/data/colorscale.cxx
index cfa93309ec63..a3b1290a2652 100644
--- a/sc/source/core/data/colorscale.cxx
+++ b/sc/source/core/data/colorscale.cxx
@@ -156,21 +156,24 @@ bool ScFormulaListener::NeedsRepaint() const
 
 ScColorScaleEntry::ScColorScaleEntry():
     mnVal(0),
-    meType(COLORSCALE_VALUE)
+    meType(COLORSCALE_VALUE),
+    mpFormat(nullptr)
 {
 }
 
 ScColorScaleEntry::ScColorScaleEntry(double nVal, const Color& rCol):
     mnVal(nVal),
     maColor(rCol),
-    meType(COLORSCALE_VALUE)
+    meType(COLORSCALE_VALUE),
+    mpFormat(nullptr)
 {
 }
 
 ScColorScaleEntry::ScColorScaleEntry(const ScColorScaleEntry& rEntry):
     mnVal(rEntry.mnVal),
     maColor(rEntry.maColor),
-    meType(rEntry.meType)
+    meType(rEntry.meType),
+    mpFormat(rEntry.mpFormat)
 {
     if(rEntry.mpCell)
     {
@@ -184,13 +187,16 @@ ScColorScaleEntry::ScColorScaleEntry(ScDocument* pDoc, const ScColorScaleEntry&
     mnVal(rEntry.mnVal),
     maColor(rEntry.maColor),
     mpCell(),
-    meType(rEntry.meType)
+    meType(rEntry.meType),
+    mpFormat(rEntry.mpFormat)
 {
     if(rEntry.mpCell)
     {
         mpCell.reset(new ScFormulaCell(*rEntry.mpCell, *rEntry.mpCell->GetDocument(), rEntry.mpCell->aPos, ScCloneFlags::NoMakeAbsExternal));
         mpCell->StartListeningTo( pDoc );
         mpListener.reset(new ScFormulaListener(mpCell.get()));
+        if (mpFormat)
+            mpListener->setCallback([&]() { mpFormat->DoRepaint();});
     }
 }
 
@@ -205,6 +211,8 @@ void ScColorScaleEntry::SetFormula( const OUString& rFormula, ScDocument* pDoc,
     mpCell.reset(new ScFormulaCell( pDoc, rAddr, rFormula, eGrammar ));
     mpCell->StartListeningTo( pDoc );
     mpListener.reset(new ScFormulaListener(mpCell.get()));
+    if (mpFormat)
+        mpListener->setCallback([&]() { mpFormat->DoRepaint();});
 }
 
 const ScTokenArray* ScColorScaleEntry::GetFormula() const
@@ -255,6 +263,7 @@ void ScColorScaleEntry::UpdateReference( sc::RefUpdateContext& rCxt )
 
     mpCell->UpdateReference(rCxt);
     mpListener.reset(new ScFormulaListener(mpCell.get()));
+    SetRepaintCallback(mpFormat);
 }
 
 void ScColorScaleEntry::UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt )
@@ -264,6 +273,7 @@ void ScColorScaleEntry::UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt )
 
     mpCell->UpdateInsertTab(rCxt);
     mpListener.reset(new ScFormulaListener(mpCell.get()));
+    SetRepaintCallback(mpFormat);
 }
 
 void ScColorScaleEntry::UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt )
@@ -273,6 +283,7 @@ void ScColorScaleEntry::UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt )
 
     mpCell->UpdateDeleteTab(rCxt);
     mpListener.reset(new ScFormulaListener(mpCell.get()));
+    SetRepaintCallback(mpFormat);
 }
 
 void ScColorScaleEntry::UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt )
@@ -283,6 +294,7 @@ void ScColorScaleEntry::UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt )
     SCTAB nTabNo = rCxt.getNewTab(mpCell->aPos.Tab());
     mpCell->UpdateMoveTab(rCxt, nTabNo);
     mpListener.reset(new ScFormulaListener(mpCell.get()));
+    SetRepaintCallback(mpFormat);
 }
 
 void ScColorScaleEntry::SetColor(const Color& rColor)
@@ -290,6 +302,13 @@ void ScColorScaleEntry::SetColor(const Color& rColor)
     maColor = rColor;
 }
 
+void ScColorScaleEntry::SetRepaintCallback(ScConditionalFormat* pFormat)
+{
+    mpFormat = pFormat;
+    if (mpFormat && mpListener)
+        mpListener->setCallback([&]() { mpFormat->DoRepaint();});
+}
+
 ScColorFormat::ScColorFormat(ScDocument* pDoc)
     : ScFormatEntry(pDoc)
     , mpParent(nullptr)
@@ -328,9 +347,19 @@ ScColorScaleFormat::~ScColorScaleFormat()
 {
 }
 
+void ScColorScaleFormat::SetParent(ScConditionalFormat* pFormat)
+{
+    for (auto itr = begin(), itrEnd = end(); itr != itrEnd; ++itr)
+    {
+        (*itr)->SetRepaintCallback(pFormat);
+    }
+    ScColorFormat::SetParent(pFormat);
+}
+
 void ScColorScaleFormat::AddEntry( ScColorScaleEntry* pEntry )
 {
     maColorScales.push_back(std::unique_ptr<ScColorScaleEntry>( pEntry ));
+    maColorScales.back()->SetRepaintCallback(mpParent);
 }
 
 void ScColorScaleEntry::SetType( ScColorScaleEntryType eType )
@@ -645,7 +674,8 @@ void ScColorScaleFormat::EnsureSize()
 }
 
 ScDataBarFormat::ScDataBarFormat(ScDocument* pDoc):
-    ScColorFormat(pDoc)
+    ScColorFormat(pDoc),
+    mpFormatData(new ScDataBarFormatData())
 {
 }
 
@@ -658,6 +688,11 @@ ScDataBarFormat::ScDataBarFormat(ScDocument* pDoc, const ScDataBarFormat& rForma
 void ScDataBarFormat::SetDataBarData( ScDataBarFormatData* pData )
 {
     mpFormatData.reset(pData);
+    if (mpParent)
+    {
+        mpFormatData->mpUpperLimit->SetRepaintCallback(mpParent);
+        mpFormatData->mpLowerLimit->SetRepaintCallback(mpParent);
+    }
 }
 
 ScDataBarFormatData* ScDataBarFormat::GetDataBarData()
@@ -675,6 +710,16 @@ ScColorFormat* ScDataBarFormat::Clone(ScDocument* pDoc) const
     return new ScDataBarFormat(pDoc, *this);
 }
 
+void ScDataBarFormat::SetParent(ScConditionalFormat* pFormat)
+{
+    if (mpFormatData)
+    {
+        mpFormatData->mpUpperLimit->SetRepaintCallback(pFormat);
+        mpFormatData->mpLowerLimit->SetRepaintCallback(pFormat);
+    }
+    ScColorFormat::SetParent(pFormat);
+}
+
 condformat::ScFormatEntryType ScDataBarFormat::GetType() const
 {
     return condformat::DATABAR;
@@ -921,9 +966,19 @@ ScColorFormat* ScIconSetFormat::Clone( ScDocument* pDoc ) const
     return new ScIconSetFormat(pDoc, *this);
 }
 
+void ScIconSetFormat::SetParent(ScConditionalFormat* pFormat)
+{
+    for(iterator itr = begin(); itr != end(); ++itr)
+    {
+        (*itr)->SetRepaintCallback(pFormat);
+    }
+    ScColorFormat::SetParent(pFormat);
+}
+
 void ScIconSetFormat::SetIconSetData( ScIconSetFormatData* pFormatData )
 {
     mpFormatData.reset( pFormatData );
+    SetParent(mpParent);
 }
 
 ScIconSetFormatData* ScIconSetFormat::GetIconSetData()
diff --git a/sc/source/filter/xml/xmlcondformat.cxx b/sc/source/filter/xml/xmlcondformat.cxx
index 95ac3fc6848b..91b0d6e7e5c1 100644
--- a/sc/source/filter/xml/xmlcondformat.cxx
+++ b/sc/source/filter/xml/xmlcondformat.cxx
@@ -170,7 +170,8 @@ ScXMLDataBarFormatContext::ScXMLDataBarFormatContext( ScXMLImport& rImport, sal_
                         ScConditionalFormat* pFormat):
     ScXMLImportContext( rImport, nPrfx, rLName ),
     mpDataBarFormat(nullptr),
-    mpFormatData(nullptr)
+    mpFormatData(nullptr),
+    mnIndex(0)
 {
     OUString sPositiveColor;
     OUString sNegativeColor;
@@ -302,14 +303,20 @@ SvXMLImportContext* ScXMLDataBarFormatContext::CreateChildContext( sal_uInt16 nP
         {
             ScColorScaleEntry* pEntry(nullptr);
             pContext = new ScXMLFormattingEntryContext( GetScImport(), nPrefix, rLocalName, xAttrList, pEntry );
-            if(mpFormatData->mpLowerLimit)
+            if(mnIndex == 0)
+            {
+                mpFormatData->mpLowerLimit.reset(pEntry);
+            }
+            else if (mnIndex == 1)
             {
                 mpFormatData->mpUpperLimit.reset(pEntry);
             }
             else
             {
-                mpFormatData->mpLowerLimit.reset(pEntry);
+                // data bars only support 2 entries
+                assert(false);
             }
+            ++mnIndex;
         }
         break;
         default:
diff --git a/sc/source/filter/xml/xmlcondformat.hxx b/sc/source/filter/xml/xmlcondformat.hxx
index 4975b5b086ae..593d65f45b55 100644
--- a/sc/source/filter/xml/xmlcondformat.hxx
+++ b/sc/source/filter/xml/xmlcondformat.hxx
@@ -86,6 +86,7 @@ private:
     ScDataBarFormat* mpDataBarFormat;
     ScDataBarFormatData* mpFormatData;
 
+    sal_Int32 mnIndex;
 };
 
 class ScXMLIconSetFormatContext : public ScXMLImportContext


More information about the Libreoffice-commits mailing list