LCOV - code coverage report
Current view: top level - libreoffice/sc/inc - colorscale.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 16 0.0 %
Date: 2012-12-27 Functions: 0 12 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * Version: MPL 1.1 / GPLv3+ / LGPLv3+
       4             :  *
       5             :  * The contents of this file are subject to the Mozilla Public License Version
       6             :  * 1.1 (the "License"); you may not use this file except in compliance with
       7             :  * the License or as specified alternatively below. You may obtain a copy of
       8             :  * the License at http://www.mozilla.org/MPL/
       9             :  *
      10             :  * Software distributed under the License is distributed on an "AS IS" basis,
      11             :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12             :  * for the specific language governing rights and limitations under the
      13             :  * License.
      14             :  *
      15             :  * Major Contributor(s):
      16             :  * Copyright (C) 2012 Markus Mohrhard <markus.mohrhard@googlemail.com> (initial developer)
      17             :  *
      18             :  * All Rights Reserved.
      19             :  *
      20             :  * For minor contributions see the git repository.
      21             :  *
      22             :  * Alternatively, the contents of this file may be used under the terms of
      23             :  * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
      24             :  * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
      25             :  * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
      26             :  * instead of those above.
      27             :  */
      28             : 
      29             : #ifndef SC_COLORSCALE_HXX
      30             : #define SC_COLORSCALE_HXX
      31             : 
      32             : #include <boost/ptr_container/ptr_vector.hpp>
      33             : #include <boost/scoped_ptr.hpp>
      34             : #include <formula/grammar.hxx>
      35             : #include <tools/color.hxx>
      36             : #include <rangelst.hxx>
      37             : #include "conditio.hxx"
      38             : 
      39             : #include <vector>
      40             : 
      41             : //TODO: merge this with conditio.hxx
      42             : 
      43             : class ScDocument;
      44             : class ScFormulaCell;
      45             : class ScTokenArray;
      46             : struct ScDataBarInfo;
      47             : class BitmapEx;
      48             : 
      49             : // don't change the order
      50             : // they are also used in the dialog to determine the position
      51             : // in the list box
      52             : enum ScColorScaleEntryType
      53             : {
      54             :     COLORSCALE_AUTO,
      55             :     COLORSCALE_MIN,
      56             :     COLORSCALE_MAX,
      57             :     COLORSCALE_PERCENTILE,
      58             :     COLORSCALE_VALUE,
      59             :     COLORSCALE_PERCENT,
      60             :     COLORSCALE_FORMULA,
      61             : };
      62             : 
      63             : class SC_DLLPUBLIC ScColorScaleEntry
      64             : {
      65             : private:
      66             :     double mnVal;
      67             :     Color maColor;
      68             :     boost::scoped_ptr<ScFormulaCell> mpCell;
      69             :     ScColorScaleEntryType meType;
      70             : 
      71             : public:
      72             :     ScColorScaleEntry(double nVal, const Color& rCol);
      73             :     ScColorScaleEntry();
      74             :     ScColorScaleEntry(const ScColorScaleEntry& rEntry);
      75             :     ScColorScaleEntry(ScDocument* pDoc, const ScColorScaleEntry& rEntry);
      76             :     ~ScColorScaleEntry();
      77             : 
      78             :     const Color& GetColor() const;
      79             :     void SetColor(const Color&);
      80             :     double GetValue() const;
      81             :     void SetValue(double nValue);
      82             :     void SetFormula(const rtl::OUString& rFormula, ScDocument* pDoc, const ScAddress& rAddr, formula::FormulaGrammar::Grammar eGrammar = formula::FormulaGrammar::GRAM_DEFAULT);
      83             :     void UpdateMoveTab(SCTAB nOldTab, SCTAB nNewTab, SCTAB nTabNo);
      84             :     void UpdateReference( UpdateRefMode eUpdateRefMode,
      85             :             const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
      86             : 
      87             :     const ScTokenArray* GetFormula() const;
      88             :     rtl::OUString GetFormula( formula::FormulaGrammar::Grammar eGrammar ) const;
      89             : 
      90             :     ScColorScaleEntryType GetType() const;
      91             :     void SetType( ScColorScaleEntryType eType );
      92             : 
      93             : #if DUMP_FORMAT_INFO
      94             :     void dumpInfo(rtl::OUStringBuffer& rBuf) const;
      95             : #endif
      96             : };
      97             : 
      98             : namespace databar
      99             : {
     100             : 
     101             : enum ScAxisPostion
     102             : {
     103             :     NONE,
     104             :     AUTOMATIC,
     105             :     MIDDLE
     106             : };
     107             : 
     108             : }
     109             : 
     110           0 : struct SC_DLLPUBLIC ScDataBarFormatData
     111             : {
     112           0 :     ScDataBarFormatData():
     113             :         maAxisColor(COL_BLACK),
     114             :         mbGradient(true),
     115             :         mbNeg(true),
     116             :         meAxisPosition(databar::AUTOMATIC),
     117           0 :         mbOnlyBar(false){}
     118             : 
     119           0 :     ScDataBarFormatData(const ScDataBarFormatData& r):
     120             :         maPositiveColor(r.maPositiveColor),
     121             :         maAxisColor(r.maAxisColor),
     122             :         mbGradient(r.mbGradient),
     123             :         mbNeg(r.mbNeg),
     124             :         meAxisPosition(r.meAxisPosition),
     125           0 :         mbOnlyBar(r.mbOnlyBar)
     126             :     {
     127           0 :         if(r.mpNegativeColor)
     128           0 :             mpNegativeColor.reset(new Color(*r.mpNegativeColor));
     129             : 
     130           0 :         if(r.mpLowerLimit)
     131           0 :             mpLowerLimit.reset( new ScColorScaleEntry(*r.mpLowerLimit));
     132           0 :         if(r.mpUpperLimit)
     133           0 :             mpUpperLimit.reset( new ScColorScaleEntry(*r.mpUpperLimit));
     134           0 :     }
     135             : 
     136             :     /**
     137             :      * Color for all Positive Values and if mbNeg == false also for negative ones
     138             :      */
     139             :     Color maPositiveColor;
     140             :     /**
     141             :      * Specifies the color for negative values. This is optional and depends on mbNeg.
     142             :      *
     143             :      * Default color is 0xFF0000, this value is not set
     144             :      */
     145             :     boost::scoped_ptr<Color> mpNegativeColor;
     146             :     /**
     147             :      * Color of the axis if used
     148             :      * Default color is black
     149             :      */
     150             :     Color maAxisColor;
     151             :     /**
     152             :      * Paint the bars with gradient. If this is used the default is to draw with
     153             :      * borders.
     154             :      *
     155             :      * Default is true
     156             :      */
     157             :     bool mbGradient;
     158             :     /**
     159             :      * Use different color for negative values. Color is specified in
     160             :      * mpNegativeColor and defaults to 0xFF0000
     161             :      *
     162             :      * Default is true
     163             :      */
     164             :     bool mbNeg; //differentiate between negative values
     165             :     /**
     166             :      * Paint negative values into the same direction as positive values
     167             :      * If false we will set the mid point according to the upper and lower limit and negative
     168             :      * values are painted to the left and positive to the right
     169             :      *
     170             :      * Default is false
     171             :      */
     172             :     databar::ScAxisPostion meAxisPosition;
     173             : 
     174             :     /**
     175             :      * If TRUE we only show the bar and not the value
     176             :      */
     177             :     bool mbOnlyBar;
     178             : 
     179             :     boost::scoped_ptr<ScColorScaleEntry> mpUpperLimit;
     180             :     boost::scoped_ptr<ScColorScaleEntry> mpLowerLimit;
     181             : };
     182             : 
     183             : enum ScIconSetType
     184             : {
     185             :     IconSet_3Arrows,
     186             :     IconSet_3ArrowsGray,
     187             :     IconSet_3Flags,
     188             :     IconSet_3TrafficLights1,
     189             :     IconSet_3TrafficLights2,
     190             :     IconSet_3Signs,
     191             :     IconSet_3Symbols,
     192             :     IconSet_3Symbols2,
     193             :     IconSet_4Arrows,
     194             :     IconSet_4ArrowsGray,
     195             :     IconSet_4RedToBlack,
     196             :     IconSet_4Rating,
     197             :     IconSet_4TrafficLights,
     198             :     IconSet_5Arrows,
     199             :     IconSet_5ArrowsGray,
     200             :     IconSet_5Ratings,
     201             :     IconSet_5Quarters
     202             : };
     203             : 
     204             : struct ScIconSetMap {
     205             :     const char* pName;
     206             :     ScIconSetType eType;
     207             :     sal_Int32 nElements;
     208             : };
     209             : 
     210             : class SC_DLLPUBLIC ScColorFormat : public ScFormatEntry
     211             : {
     212             : public:
     213             :     ScColorFormat(ScDocument* pDoc);
     214             :     virtual ~ScColorFormat();
     215             : 
     216             :     void SetRange(const ScRangeList& rList);
     217             :     const ScRangeList& GetRange() const;
     218             : 
     219             :     virtual void DataChanged(const ScRange& rRange) = 0;
     220             :     virtual void SetParent(ScConditionalFormat* pParent);
     221             : 
     222             :     virtual void startRendering();
     223             :     virtual void endRendering();
     224             : 
     225             : protected:
     226             :     std::vector<double>& getValues() const;
     227             : 
     228             :     double getMinValue() const;
     229             :     double getMaxValue() const;
     230             : 
     231             :     ScConditionalFormat* mpParent;
     232             : 
     233             : private:
     234             : 
     235           0 :     struct ScColorFormatCache
     236             :     {
     237             :         std::vector<double> maValues;
     238             :     };
     239             :     mutable boost::scoped_ptr<ScColorFormatCache> mpCache;
     240             : };
     241             : 
     242             : class SC_DLLPUBLIC ScColorScaleFormat : public ScColorFormat
     243             : {
     244             : private:
     245             :     typedef boost::ptr_vector<ScColorScaleEntry> ColorScaleEntries;
     246             :     ColorScaleEntries maColorScales;
     247             : 
     248             :     double GetMinValue() const;
     249             :     double GetMaxValue() const;
     250             : 
     251             :     void calcMinMax(double& nMin, double& nMax) const;
     252             :     bool CheckEntriesForRel(const ScRange& rRange) const;
     253             :     double CalcValue(double nMin, double nMax, ColorScaleEntries::const_iterator& rItr) const;
     254             : public:
     255             :     ScColorScaleFormat(ScDocument* pDoc);
     256             :     ScColorScaleFormat(ScDocument* pDoc, const ScColorScaleFormat& rFormat);
     257             :     virtual ~ScColorScaleFormat();
     258             :     virtual ScColorFormat* Clone(ScDocument* pDoc = NULL) const;
     259             : 
     260             :     Color* GetColor(const ScAddress& rAddr) const;
     261             :     void AddEntry(ScColorScaleEntry* pEntry);
     262             : 
     263             :     virtual void DataChanged(const ScRange& rRange);
     264             :     virtual void UpdateMoveTab(SCTAB nOldTab, SCTAB nNewTab);
     265             :     virtual void UpdateReference( UpdateRefMode eUpdateRefMode,
     266             :             const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
     267             : 
     268             :     virtual condformat::ScFormatEntryType GetType() const;
     269             :     typedef ColorScaleEntries::iterator iterator;
     270             :     typedef ColorScaleEntries::const_iterator const_iterator;
     271             :     iterator begin();
     272             :     const_iterator begin() const;
     273             :     iterator end();
     274             :     const_iterator end() const;
     275             : 
     276             :     size_t size() const;
     277             : 
     278             : #if DUMP_FORMAT_INFO
     279             :     virtual void dumpInfo(rtl::OUStringBuffer& rBuf) const;
     280             : #endif
     281             : };
     282             : 
     283           0 : class SC_DLLPUBLIC ScDataBarFormat : public ScColorFormat
     284             : {
     285             : public:
     286             :     ScDataBarFormat(ScDocument* pDoc);
     287             :     ScDataBarFormat(ScDocument* pDoc, const ScDataBarFormat& rFormat);
     288             :     virtual ScColorFormat* Clone(ScDocument* pDoc = NULL) const;
     289             : 
     290             :     ScDataBarInfo* GetDataBarInfo(const ScAddress& rAddr) const;
     291             : 
     292             :     void SetDataBarData( ScDataBarFormatData* pData );
     293             :     const ScDataBarFormatData* GetDataBarData() const;
     294             : 
     295             :     virtual void DataChanged(const ScRange& rRange);
     296             :     virtual void UpdateMoveTab(SCTAB nOldTab, SCTAB nNewTab);
     297             :     virtual void UpdateReference( UpdateRefMode eUpdateRefMode,
     298             :             const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
     299             : 
     300             :     virtual condformat::ScFormatEntryType GetType() const;
     301             : 
     302             : #if DUMP_FORMAT_INFO
     303             :     virtual void dumpInfo(rtl::OUStringBuffer& rBuf) const;
     304             : #endif
     305             : private:
     306             :     double getMin(double nMin, double nMax) const;
     307             :     double getMax(double nMin, double nMax) const;
     308             : 
     309             :     boost::scoped_ptr<ScDataBarFormatData> mpFormatData;
     310             : };
     311             : 
     312           0 : struct ScIconSetFormatData
     313             : {
     314             :     ScIconSetType eIconSetType;
     315             :     boost::ptr_vector<ScColorScaleEntry> maEntries;
     316             : };
     317             : 
     318           0 : class SC_DLLPUBLIC ScIconSetFormat : public ScColorFormat
     319             : {
     320             : public:
     321             :     ScIconSetFormat(ScDocument* pDoc);
     322             :     ScIconSetFormat(ScDocument* pDoc, const ScIconSetFormat& rFormat);
     323             : 
     324             :     virtual ScColorFormat* Clone(ScDocument* pDoc = NULL) const;
     325             : 
     326             :     ScIconSetInfo* GetIconSetInfo(const ScAddress& rAddr) const;
     327             : 
     328             :     void SetIconSetData( ScIconSetFormatData* pData );
     329             :     const ScIconSetFormatData* GetIconSetData() const;
     330             : 
     331             :     virtual void DataChanged(const ScRange& rRange);
     332             :     virtual void UpdateMoveTab(SCTAB nOldTab, SCTAB nNewTab);
     333             :     virtual void UpdateReference( UpdateRefMode eUpdateRefMode,
     334             :             const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
     335             : 
     336             :     virtual condformat::ScFormatEntryType GetType() const;
     337             : 
     338             :     static ScIconSetMap* getIconSetMap();
     339             :     static BitmapEx& getBitmap( ScIconSetType eType, sal_Int32 nIndex );
     340             : 
     341             :     typedef boost::ptr_vector<ScColorScaleEntry>::iterator iterator;
     342             :     typedef boost::ptr_vector<ScColorScaleEntry>::const_iterator const_iterator;
     343             : 
     344             :     iterator begin();
     345             :     const_iterator begin() const;
     346             :     iterator end();
     347             :     const_iterator end() const;
     348             : 
     349             : #if DUMP_FORMAT_INFO
     350             :     virtual void dumpInfo(rtl::OUStringBuffer& rBuf) const;
     351             : #endif
     352             : private:
     353             : 
     354             :     double GetMinValue() const;
     355             :     double GetMaxValue() const;
     356             :     double CalcValue(double nMin, double nMax, ScIconSetFormat::const_iterator& itr) const;
     357             : 
     358             :     boost::scoped_ptr<ScIconSetFormatData> mpFormatData;
     359             : };
     360             : 
     361             : #endif
     362             : 
     363             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10