Branch data 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 : :
48 : : enum ScColorScaleEntryType
49 : : {
50 : : COLORSCALE_VALUE,
51 : : COLORSCALE_MIN,
52 : : COLORSCALE_MAX,
53 : : COLORSCALE_PERCENT,
54 : : COLORSCALE_PERCENTILE,
55 : : COLORSCALE_FORMULA,
56 : : COLORSCALE_AUTOMIN,
57 : : COLORSCALE_AUTOMAX
58 : : };
59 : :
60 : : class SC_DLLPUBLIC ScColorScaleEntry
61 : : {
62 : : private:
63 : : double mnVal;
64 : : Color maColor;
65 : : boost::scoped_ptr<ScFormulaCell> mpCell;
66 : : ScColorScaleEntryType meType;
67 : :
68 : : public:
69 : : ScColorScaleEntry(double nVal, const Color& rCol);
70 : : ScColorScaleEntry();
71 : : ScColorScaleEntry(const ScColorScaleEntry& rEntry);
72 : : ScColorScaleEntry(ScDocument* pDoc, const ScColorScaleEntry& rEntry);
73 : : ~ScColorScaleEntry();
74 : :
75 : : const Color& GetColor() const;
76 : : void SetColor(const Color&);
77 : : double GetValue() const;
78 : : void SetValue(double nValue);
79 : : void SetFormula(const rtl::OUString& rFormula, ScDocument* pDoc, const ScAddress& rAddr, formula::FormulaGrammar::Grammar eGrammar = formula::FormulaGrammar::GRAM_DEFAULT);
80 : : void UpdateMoveTab(SCTAB nOldTab, SCTAB nNewTab, SCTAB nTabNo);
81 : : void UpdateReference( UpdateRefMode eUpdateRefMode,
82 : : const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
83 : :
84 : : const ScTokenArray* GetFormula() const;
85 : : rtl::OUString GetFormula( formula::FormulaGrammar::Grammar eGrammar ) const;
86 : :
87 : : ScColorScaleEntryType GetType() const;
88 : : void SetType( ScColorScaleEntryType eType );
89 : : };
90 : :
91 : : namespace databar
92 : : {
93 : :
94 : : enum ScAxisPostion
95 : : {
96 : : NONE,
97 : : AUTOMATIC,
98 : : MIDDLE
99 : : };
100 : :
101 : : }
102 : :
103 [ # # ][ # # ]: 0 : struct SC_DLLPUBLIC ScDataBarFormatData
104 : : {
105 : 0 : ScDataBarFormatData():
106 : : maAxisColor(COL_BLACK),
107 : : mbGradient(true),
108 : : mbNeg(true),
109 : : meAxisPosition(databar::AUTOMATIC),
110 : 0 : mbOnlyBar(false){}
111 : :
112 : 0 : ScDataBarFormatData(const ScDataBarFormatData& r):
113 : : maPositiveColor(r.maPositiveColor),
114 : : maAxisColor(r.maAxisColor),
115 : : mbGradient(r.mbGradient),
116 : : mbNeg(r.mbNeg),
117 : : meAxisPosition(r.meAxisPosition),
118 : 0 : mbOnlyBar(r.mbOnlyBar)
119 : : {
120 [ # # ]: 0 : if(r.mpNegativeColor)
121 [ # # ][ # # ]: 0 : mpNegativeColor.reset(new Color(*r.mpNegativeColor));
122 : :
123 [ # # ]: 0 : if(r.mpLowerLimit)
124 [ # # ][ # # ]: 0 : mpLowerLimit.reset( new ScColorScaleEntry(*r.mpLowerLimit));
[ # # ]
125 [ # # ]: 0 : if(r.mpUpperLimit)
126 [ # # ][ # # ]: 0 : mpUpperLimit.reset( new ScColorScaleEntry(*r.mpUpperLimit));
[ # # ]
127 : 0 : }
128 : :
129 : : /**
130 : : * Color for all Positive Values and if mbNeg == false also for negative ones
131 : : */
132 : : Color maPositiveColor;
133 : : /**
134 : : * Specifies the color for negative values. This is optional and depends on mbNeg.
135 : : *
136 : : * Default color is 0xFF0000, this value is not set
137 : : */
138 : : boost::scoped_ptr<Color> mpNegativeColor;
139 : : /**
140 : : * Color of the axis if used
141 : : * Default color is black
142 : : */
143 : : Color maAxisColor;
144 : : /**
145 : : * Paint the bars with gradient. If this is used the default is to draw with
146 : : * borders.
147 : : *
148 : : * Default is true
149 : : */
150 : : bool mbGradient;
151 : : /**
152 : : * Use different color for negative values. Color is specified in
153 : : * mpNegativeColor and defaults to 0xFF0000
154 : : *
155 : : * Default is true
156 : : */
157 : : bool mbNeg; //differentiate between negative values
158 : : /**
159 : : * Paint negative values into the same direction as positive values
160 : : * If false we will set the mid point according to the upper and lower limit and negative
161 : : * values are painted to the left and positive to the right
162 : : *
163 : : * Default is false
164 : : */
165 : : databar::ScAxisPostion meAxisPosition;
166 : :
167 : : /**
168 : : * If TRUE we only show the bar and not the value
169 : : */
170 : : bool mbOnlyBar;
171 : :
172 : : boost::scoped_ptr<ScColorScaleEntry> mpUpperLimit;
173 : : boost::scoped_ptr<ScColorScaleEntry> mpLowerLimit;
174 : : };
175 : :
176 : : class SC_DLLPUBLIC ScColorFormat : public ScFormatEntry
177 : : {
178 : : public:
179 : : ScColorFormat(ScDocument* pDoc);
180 : : virtual ~ScColorFormat();
181 : :
182 : : void SetRange(const ScRangeList& rList);
183 : : const ScRangeList& GetRange() const;
184 : :
185 : : virtual void DataChanged(const ScRange& rRange) = 0;
186 : : virtual void SetParent(ScConditionalFormat* pParent);
187 : :
188 : : protected:
189 : : void getValues( std::vector<double>& rValues ) const;
190 : :
191 : : ScConditionalFormat* mpParent;
192 : : };
193 : :
194 : : class SC_DLLPUBLIC ScColorScaleFormat : public ScColorFormat
195 : : {
196 : : private:
197 : : typedef boost::ptr_vector<ScColorScaleEntry> ColorScaleEntries;
198 : : ColorScaleEntries maColorScales;
199 : :
200 : : double GetMinValue() const;
201 : : double GetMaxValue() const;
202 : :
203 : : void calcMinMax(double& nMin, double& nMax) const;
204 : : bool CheckEntriesForRel(const ScRange& rRange) const;
205 : : double CalcValue(double nMin, double nMax, ColorScaleEntries::const_iterator& rItr) const;
206 : : public:
207 : : ScColorScaleFormat(ScDocument* pDoc);
208 : : ScColorScaleFormat(ScDocument* pDoc, const ScColorScaleFormat& rFormat);
209 : : virtual ~ScColorScaleFormat();
210 : : virtual ScColorFormat* Clone(ScDocument* pDoc = NULL) const;
211 : :
212 : : Color* GetColor(const ScAddress& rAddr) const;
213 : : void AddEntry(ScColorScaleEntry* pEntry);
214 : :
215 : : virtual void DataChanged(const ScRange& rRange);
216 : : virtual void UpdateMoveTab(SCTAB nOldTab, SCTAB nNewTab);
217 : : virtual void UpdateReference( UpdateRefMode eUpdateRefMode,
218 : : const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
219 : :
220 : : virtual condformat::ScFormatEntryType GetType() const;
221 : : typedef ColorScaleEntries::iterator iterator;
222 : : typedef ColorScaleEntries::const_iterator const_iterator;
223 : : iterator begin();
224 : : const_iterator begin() const;
225 : : iterator end();
226 : : const_iterator end() const;
227 : :
228 : : size_t size() const;
229 : :
230 : : #if DUMP_FORMAT_INFO
231 : : virtual void dumpInfo() const;
232 : : #endif
233 : : };
234 : :
235 [ # # ][ # # ]: 0 : class SC_DLLPUBLIC ScDataBarFormat : public ScColorFormat
236 : : {
237 : : public:
238 : : ScDataBarFormat(ScDocument* pDoc);
239 : : ScDataBarFormat(ScDocument* pDoc, const ScDataBarFormat& rFormat);
240 : : virtual ScColorFormat* Clone(ScDocument* pDoc = NULL) const;
241 : :
242 : : ScDataBarInfo* GetDataBarInfo(const ScAddress& rAddr) const;
243 : :
244 : : void SetDataBarData( ScDataBarFormatData* pData );
245 : : const ScDataBarFormatData* GetDataBarData() const;
246 : :
247 : : virtual void DataChanged(const ScRange& rRange);
248 : : virtual void UpdateMoveTab(SCTAB nOldTab, SCTAB nNewTab);
249 : : virtual void UpdateReference( UpdateRefMode eUpdateRefMode,
250 : : const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
251 : :
252 : : virtual condformat::ScFormatEntryType GetType() const;
253 : :
254 : : #if DUMP_FORMAT_INFO
255 : : virtual void dumpInfo() const;
256 : : #endif
257 : : private:
258 : : double getMin(double nMin, double nMax) const;
259 : : double getMax(double nMin, double nMax) const;
260 : :
261 : : boost::scoped_ptr<ScDataBarFormatData> mpFormatData;
262 : : };
263 : :
264 : : #endif
265 : :
266 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|