[Libreoffice-commits] core.git: sc/inc sc/source

Markus Mohrhard markus.mohrhard at googlemail.com
Wed Jun 28 02:33:35 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 49922897d68835ae4e5c850b3c55107157fe7548
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>

diff --git a/sc/inc/colorscale.hxx b/sc/inc/colorscale.hxx
index bdf0148268cf..ad702f6980a6 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 25a029024e28..4bc29e669006 100644
--- a/sc/source/core/data/colorscale.cxx
+++ b/sc/source/core/data/colorscale.cxx
@@ -155,21 +155,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)
     {
@@ -183,13 +186,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();});
     }
 }
 
@@ -204,6 +210,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
@@ -254,6 +262,7 @@ void ScColorScaleEntry::UpdateReference( sc::RefUpdateContext& rCxt )
 
     mpCell->UpdateReference(rCxt);
     mpListener.reset(new ScFormulaListener(mpCell.get()));
+    SetRepaintCallback(mpFormat);
 }
 
 void ScColorScaleEntry::UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt )
@@ -263,6 +272,7 @@ void ScColorScaleEntry::UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt )
 
     mpCell->UpdateInsertTab(rCxt);
     mpListener.reset(new ScFormulaListener(mpCell.get()));
+    SetRepaintCallback(mpFormat);
 }
 
 void ScColorScaleEntry::UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt )
@@ -272,6 +282,7 @@ void ScColorScaleEntry::UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt )
 
     mpCell->UpdateDeleteTab(rCxt);
     mpListener.reset(new ScFormulaListener(mpCell.get()));
+    SetRepaintCallback(mpFormat);
 }
 
 void ScColorScaleEntry::UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt )
@@ -282,6 +293,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)
@@ -289,6 +301,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)
@@ -327,9 +346,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 )
@@ -644,7 +673,8 @@ void ScColorScaleFormat::EnsureSize()
 }
 
 ScDataBarFormat::ScDataBarFormat(ScDocument* pDoc):
-    ScColorFormat(pDoc)
+    ScColorFormat(pDoc),
+    mpFormatData(new ScDataBarFormatData())
 {
 }
 
@@ -657,6 +687,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()
@@ -674,6 +709,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;
@@ -920,9 +965,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