[Libreoffice-commits] .: 3 commits - sc/inc sc/source

Markus Mohrhard mmohrhard at kemper.freedesktop.org
Thu May 10 21:50:02 PDT 2012


 sc/inc/colorscale.hxx                     |   11 ++++++++
 sc/source/core/data/colorscale.cxx        |   41 ++++++++++++++++++++++++++----
 sc/source/filter/inc/condformatbuffer.hxx |    3 +-
 sc/source/filter/oox/condformatbuffer.cxx |   15 +++++++++-
 4 files changed, 62 insertions(+), 8 deletions(-)

New commits:
commit cdd36980f1e9517280d579a2467f46f87fec8237
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Fri May 11 06:47:37 2012 +0200

    repaint for every change when using formulas in color scales
    
    Change-Id: I1eb42ac75228dee00079c86e7c378efb72f16e28

diff --git a/sc/inc/colorscale.hxx b/sc/inc/colorscale.hxx
index a95eec6..8a5b203 100644
--- a/sc/inc/colorscale.hxx
+++ b/sc/inc/colorscale.hxx
@@ -59,6 +59,7 @@ public:
     bool GetMin() const;
     bool GetMax() const;
     bool GetPercent() const;
+    bool HasFormula() const;
     void SetMin(bool bMin);
     void SetMax(bool bMax);
     void SetPercent(bool bPercent);
diff --git a/sc/source/core/data/colorscale.cxx b/sc/source/core/data/colorscale.cxx
index c24fc35..33aff61 100644
--- a/sc/source/core/data/colorscale.cxx
+++ b/sc/source/core/data/colorscale.cxx
@@ -104,6 +104,11 @@ bool ScColorScaleEntry::GetPercent() const
     return mbPercent;
 }
 
+bool ScColorScaleEntry::HasFormula() const
+{
+    return mpCell;
+}
+
 void ScColorScaleEntry::SetMin(bool bMin)
 {
     mbMin = bMin;
@@ -369,7 +374,13 @@ bool ScColorScaleFormat::CheckEntriesForRel(const ScRange& rRange) const
     for(const_iterator itr = begin(); itr != end(); ++itr)
     {
         if(itr->GetMin() || itr->GetMax())
+        {
             bNeedUpdate = true;
+            break;
+        }
+
+        if(itr->HasFormula())
+            return true;
     }
 
     // TODO: check also if the changed value is the new min/max
commit fc48c494347124dffddccca7d75707a22ca65f75
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Fri May 11 06:38:57 2012 +0200

    import formulas for color scales from xlsx
    
    Change-Id: If19c6486c95cab0106bf04a4ec68359f7a4ed220

diff --git a/sc/source/filter/inc/condformatbuffer.hxx b/sc/source/filter/inc/condformatbuffer.hxx
index 7eb6342..b8b2d65 100644
--- a/sc/source/filter/inc/condformatbuffer.hxx
+++ b/sc/source/filter/inc/condformatbuffer.hxx
@@ -84,6 +84,7 @@ struct ColorScaleRuleModelEntry
     bool mbMin;
     bool mbMax;
     bool mbPercent;
+    rtl::OUString maFormula;
 
     ColorScaleRuleModelEntry():
         maColor(),
@@ -101,7 +102,7 @@ public:
     void importCfvo( const AttributeList& rAttribs );
     void importColor( const AttributeList& rAttribs );
 
-    void AddEntries( ScColorScaleFormat* pFormat );
+    void AddEntries( ScColorScaleFormat* pFormat, ScDocument* pDoc, const ScAddress& rAddr );
 
 private:
     const CondFormat& mrCondFormat;
diff --git a/sc/source/filter/oox/condformatbuffer.cxx b/sc/source/filter/oox/condformatbuffer.cxx
index bce9ed4..dd6150f 100644
--- a/sc/source/filter/oox/condformatbuffer.cxx
+++ b/sc/source/filter/oox/condformatbuffer.cxx
@@ -182,6 +182,11 @@ void ColorScaleRule::importCfvo( const AttributeList& rAttribs )
         // between percent and percentile should be when calculating colors
         maColorScaleRuleEntries[mnCfvo].mbPercent = true;
     }
+    else if( aType == "formula" )
+    {
+        rtl::OUString aFormula = rAttribs.getString( XML_val, rtl::OUString() );
+        maColorScaleRuleEntries[mnCfvo].maFormula = aFormula;
+    }
 
     ++mnCfvo;
 }
@@ -212,7 +217,7 @@ void ColorScaleRule::importColor( const AttributeList& rAttribs )
     ++mnCol;
 }
 
-void ColorScaleRule::AddEntries( ScColorScaleFormat* pFormat )
+void ColorScaleRule::AddEntries( ScColorScaleFormat* pFormat, ScDocument* pDoc, const ScAddress& rAddr )
 {
     //assume that both vectors contain the same entries
     // TODO: check it
@@ -228,6 +233,9 @@ void ColorScaleRule::AddEntries( ScColorScaleFormat* pFormat )
         if(rEntry.mbPercent)
             pEntry->SetPercent(true);
 
+        if(!rEntry.maFormula.isEmpty())
+            pEntry->SetFormula(rEntry.maFormula, pDoc, rAddr, formula::FormulaGrammar::GRAM_ENGLISH_XL_A1);
+
         pFormat->AddEntry( pEntry );
     }
 }
@@ -699,7 +707,6 @@ void CondFormatRule::finalizeImport( const Reference< XSheetConditionalEntries >
         ScDocument& rDoc = getScDocument();
         ScColorScaleFormat* pFormat = new ScColorScaleFormat(&rDoc);
 
-        mpColor->AddEntries( pFormat );
         sal_Int32 nIndex = rDoc.AddColorScaleFormat(pFormat);
 
         ScRangeList aList;
@@ -720,6 +727,10 @@ void CondFormatRule::finalizeImport( const Reference< XSheetConditionalEntries >
             aList.Append(aRange);
         }
         pFormat->SetRange(aList);
+        if(aList.size())
+            mpColor->AddEntries( pFormat, &rDoc, aList.front()->aStart );
+        else
+            mpColor->AddEntries( pFormat, &rDoc, ScAddress() );
     }
 }
 
commit caa7f3f564cbf2ee695e806916041b2694710b6b
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Fri May 11 06:01:48 2012 +0200

    add formula input to color scales
    
    Change-Id: I I7f0a46cf5aea2eb1aa8bc9415d9761cc197b0c23

diff --git a/sc/inc/colorscale.hxx b/sc/inc/colorscale.hxx
index a34c50c..a95eec6 100644
--- a/sc/inc/colorscale.hxx
+++ b/sc/inc/colorscale.hxx
@@ -27,18 +27,22 @@
  */
 
 #include <boost/ptr_container/ptr_vector.hpp>
+#include <boost/scoped_ptr.hpp>
+#include <formula/grammar.hxx>
 #include <tools/color.hxx>
 #include <rangelst.hxx>
 
 //TODO: merge this with conditio.hxx
 
 class ScDocument;
+class ScFormulaCell;
 
 class SC_DLLPUBLIC ScColorScaleEntry
 {
 private:
     double mnVal;
     Color maColor;
+    boost::scoped_ptr<ScFormulaCell> mpCell;
 
     bool mbMin;
     bool mbMax;
@@ -46,9 +50,11 @@ private:
 public:
     ScColorScaleEntry(double nVal, const Color& rCol);
     ScColorScaleEntry(const ScColorScaleEntry& rEntry);
+    ~ScColorScaleEntry();
 
     const Color& GetColor() const;
     double GetValue() const;
+    void SetFormula(const rtl::OUString& rFormula, ScDocument* pDoc, const ScAddress& rAddr, formula::FormulaGrammar::Grammar eGrammar = formula::FormulaGrammar::GRAM_DEFAULT);
 
     bool GetMin() const;
     bool GetMax() const;
@@ -80,6 +86,8 @@ public:
 
     void DataChanged(const ScRange& rRange);
     void UpdateMoveTab(SCTAB nOldTab, SCTAB nNewTab);
+    void UpdateReference( UpdateRefMode eUpdateRefMode,
+            const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
 
     typedef ColorScaleEntries::iterator iterator;
     typedef ColorScaleEntries::const_iterator const_iterator;
@@ -105,6 +113,8 @@ public:
 
     void DataChanged(const ScRange& rRange);
     void UpdateMoveTab(SCTAB nOldTab, SCTAB nNewTab);
+    void UpdateReference( UpdateRefMode eUpdateRefMode,
+            const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
 
     iterator begin();
     const_iterator begin() const;
diff --git a/sc/source/core/data/colorscale.cxx b/sc/source/core/data/colorscale.cxx
index c14251d..c24fc35 100644
--- a/sc/source/core/data/colorscale.cxx
+++ b/sc/source/core/data/colorscale.cxx
@@ -33,24 +33,44 @@
 ScColorScaleEntry::ScColorScaleEntry(double nVal, const Color& rCol):
     mnVal(nVal),
     maColor(rCol),
+    mpCell(NULL),
     mbMin(false),
     mbMax(false),
-    mbPercent(false){
-
+    mbPercent(false)
+{
 }
 
 ScColorScaleEntry::ScColorScaleEntry(const ScColorScaleEntry& rEntry):
     mnVal(rEntry.mnVal),
     maColor(rEntry.maColor),
-    mbMin(false),
-    mbMax(false),
-    mbPercent(false)
+    mpCell(NULL),
+    mbMin(rEntry.mbMin),
+    mbMax(rEntry.mbMax),
+    mbPercent(rEntry.mbPercent)
 {
+}
 
+ScColorScaleEntry::~ScColorScaleEntry()
+{
+}
+
+void ScColorScaleEntry::SetFormula( const rtl::OUString& rFormula, ScDocument* pDoc, const ScAddress& rAddr, formula::FormulaGrammar::Grammar eGrammar )
+{
+    mpCell.reset(new ScFormulaCell( pDoc, rAddr, rFormula, eGrammar ));
+    mpCell->StartListeningTo( pDoc );
 }
 
 double ScColorScaleEntry::GetValue() const
 {
+    if(mpCell)
+    {
+        mpCell->Interpret();
+        if(mpCell->IsValue())
+            return mpCell->GetValue();
+
+        return std::numeric_limits<double>::max();
+    }
+
     return mnVal;
 }
 


More information about the Libreoffice-commits mailing list