Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / sc / inc / colorscale.hxx
blob0ed8a82d14e3d140290031e3b3af146c9688bdeb
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #ifndef INCLUDED_SC_INC_COLORSCALE_HXX
11 #define INCLUDED_SC_INC_COLORSCALE_HXX
13 #include <formula/grammar.hxx>
14 #include <tools/color.hxx>
15 #include "rangelst.hxx"
16 #include "conditio.hxx"
17 #include "document.hxx"
19 #include <memory>
20 #include <vector>
22 //TODO: merge this with conditio.hxx
24 class ScDocument;
25 class ScFormulaCell;
26 class ScTokenArray;
27 struct ScDataBarInfo;
28 class BitmapEx;
30 // don't change the order
31 // they are also used in the dialog to determine the position
32 // in the list box
33 enum ScColorScaleEntryType
35 COLORSCALE_AUTO,
36 COLORSCALE_MIN,
37 COLORSCALE_MAX,
38 COLORSCALE_PERCENTILE,
39 COLORSCALE_VALUE,
40 COLORSCALE_PERCENT,
41 COLORSCALE_FORMULA,
44 class SC_DLLPUBLIC ScColorScaleEntry
46 private:
47 double mnVal;
48 Color maColor;
49 std::unique_ptr<ScFormulaCell> mpCell;
50 std::unique_ptr<ScFormulaListener> mpListener;
51 ScColorScaleEntryType meType;
52 ScConditionalFormat* mpFormat;
54 public:
55 ScColorScaleEntry(double nVal, const Color& rCol);
56 ScColorScaleEntry();
57 ScColorScaleEntry(const ScColorScaleEntry& rEntry);
58 ScColorScaleEntry(ScDocument* pDoc, const ScColorScaleEntry& rEntry);
59 ~ScColorScaleEntry() COVERITY_NOEXCEPT_FALSE;
61 const Color& GetColor() const { return maColor;}
62 void SetColor(const Color&);
63 double GetValue() const;
64 void SetValue(double nValue);
65 void SetFormula(const OUString& rFormula, ScDocument* pDoc, const ScAddress& rAddr,
66 formula::FormulaGrammar::Grammar eGrammar = formula::FormulaGrammar::GRAM_DEFAULT);
68 void UpdateReference( const sc::RefUpdateContext& rCxt );
69 void UpdateInsertTab( const sc::RefUpdateInsertTabContext& rCxt );
70 void UpdateDeleteTab( const sc::RefUpdateDeleteTabContext& rCxt );
71 void UpdateMoveTab( const sc::RefUpdateMoveTabContext& rCxt );
73 const ScTokenArray* GetFormula() const;
74 OUString GetFormula( formula::FormulaGrammar::Grammar eGrammar ) const;
76 ScColorScaleEntryType GetType() const { return meType;}
77 void SetType( ScColorScaleEntryType eType );
79 void SetRepaintCallback(ScConditionalFormat* pParent);
82 namespace databar
85 enum ScAxisPosition
87 NONE,
88 AUTOMATIC,
89 MIDDLE
94 struct SC_DLLPUBLIC ScDataBarFormatData
96 ScDataBarFormatData():
97 maAxisColor(COL_BLACK),
98 mbGradient(true),
99 mbNeg(true),
100 meAxisPosition(databar::AUTOMATIC),
101 mnMinLength(0),
102 mnMaxLength(100),
103 mbOnlyBar(false),
104 mpUpperLimit(new ScColorScaleEntry()),
105 mpLowerLimit(new ScColorScaleEntry())
108 ScDataBarFormatData(const ScDataBarFormatData& r):
109 maPositiveColor(r.maPositiveColor),
110 maAxisColor(r.maAxisColor),
111 mbGradient(r.mbGradient),
112 mbNeg(r.mbNeg),
113 meAxisPosition(r.meAxisPosition),
114 mnMinLength(r.mnMinLength),
115 mnMaxLength(r.mnMaxLength),
116 mbOnlyBar(r.mbOnlyBar)
118 if(r.mpNegativeColor)
119 mpNegativeColor.reset(new Color(*r.mpNegativeColor));
121 if(r.mpLowerLimit)
122 mpLowerLimit.reset( new ScColorScaleEntry(*r.mpLowerLimit));
123 else
124 mpLowerLimit.reset(new ScColorScaleEntry());
125 if(r.mpUpperLimit)
126 mpUpperLimit.reset( new ScColorScaleEntry(*r.mpUpperLimit));
127 else
128 mpUpperLimit.reset(new ScColorScaleEntry());
132 * Color for all Positive Values and if mbNeg == false also for negative ones
134 Color maPositiveColor;
136 * Specifies the color for negative values. This is optional and depends on mbNeg.
138 * Default color is 0xFF0000, this value is not set
140 std::unique_ptr<Color> mpNegativeColor;
142 * Color of the axis if used
143 * Default color is black
145 Color maAxisColor;
147 * Paint the bars with gradient. If this is used the default is to draw with
148 * borders.
150 * Default is true
152 bool mbGradient;
154 * Use different color for negative values. Color is specified in
155 * mpNegativeColor and defaults to 0xFF0000
157 * Default is true
159 bool mbNeg; //differentiate between negative values
161 * Paint negative values into the same direction as positive values
162 * If false we will set the mid point according to the upper and lower limit and negative
163 * values are painted to the left and positive to the right
165 * Default is false
167 databar::ScAxisPosition meAxisPosition;
169 * Minimal length of a databar in percent of cell length
170 * Value has to be in the range [0, 100)
172 double mnMinLength;
174 * Maximal length of a databar in percent of cell length
175 * Value has to be in the range (0, 100]
177 double mnMaxLength;
180 * If TRUE we only show the bar and not the value
182 bool mbOnlyBar;
184 std::unique_ptr<ScColorScaleEntry> mpUpperLimit;
185 std::unique_ptr<ScColorScaleEntry> mpLowerLimit;
188 enum ScIconSetType
190 IconSet_3Arrows,
191 IconSet_3ArrowsGray,
192 IconSet_3Flags,
193 IconSet_3TrafficLights1,
194 IconSet_3TrafficLights2,
195 IconSet_3Signs,
196 IconSet_3Symbols,
197 IconSet_3Symbols2,
198 IconSet_3Smilies,
199 IconSet_3Stars,
200 IconSet_3Triangles,
201 IconSet_3ColorSmilies,
202 IconSet_4Arrows,
203 IconSet_4ArrowsGray,
204 IconSet_4RedToBlack,
205 IconSet_4Rating,
206 IconSet_4TrafficLights,
207 IconSet_5Arrows,
208 IconSet_5ArrowsGray,
209 IconSet_5Ratings,
210 IconSet_5Quarters,
211 IconSet_5Boxes
214 struct ScIconSetMap {
215 const char* pName;
216 ScIconSetType eType;
217 sal_Int32 nElements;
220 class SC_DLLPUBLIC ScColorFormat : public ScFormatEntry
222 public:
223 ScColorFormat(ScDocument* pDoc);
224 virtual ~ScColorFormat() override;
226 const ScRangeList& GetRange() const;
228 virtual void SetParent(ScConditionalFormat* pParent) override;
230 virtual void startRendering() override;
231 virtual void endRendering() override;
233 protected:
234 std::vector<double>& getValues() const;
236 double getMinValue() const;
237 double getMaxValue() const;
239 ScConditionalFormat* mpParent;
241 private:
243 struct ScColorFormatCache
245 std::vector<double> maValues;
247 mutable std::unique_ptr<ScColorFormatCache> mpCache;
250 typedef std::vector<std::unique_ptr<ScColorScaleEntry>> ScColorScaleEntries;
252 class SC_DLLPUBLIC ScColorScaleFormat : public ScColorFormat
254 private:
255 ScColorScaleEntries maColorScales;
257 double GetMinValue() const;
258 double GetMaxValue() const;
260 void calcMinMax(double& nMin, double& nMax) const;
261 double CalcValue(double nMin, double nMax, const ScColorScaleEntries::const_iterator& rItr) const;
262 public:
263 ScColorScaleFormat(ScDocument* pDoc);
264 ScColorScaleFormat(ScDocument* pDoc, const ScColorScaleFormat& rFormat);
265 virtual ~ScColorScaleFormat() override;
266 virtual ScColorFormat* Clone(ScDocument* pDoc) const override;
268 virtual void SetParent(ScConditionalFormat* pParent) override;
270 Color* GetColor(const ScAddress& rAddr) const;
271 void AddEntry(ScColorScaleEntry* pEntry);
273 virtual void UpdateReference( sc::RefUpdateContext& rCxt ) override;
274 virtual void UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt ) override;
275 virtual void UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt ) override;
276 virtual void UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt ) override;
278 virtual Type GetType() const override;
279 ScColorScaleEntries::iterator begin();
280 ScColorScaleEntries::const_iterator begin() const;
281 ScColorScaleEntries::iterator end();
282 ScColorScaleEntries::const_iterator end() const;
284 ScColorScaleEntry* GetEntry(size_t nPos);
285 const ScColorScaleEntry* GetEntry(size_t nPos) const;
287 size_t size() const;
290 * Makes sure that the maColorScales contain at least 2 entries.
291 * Should be called when it is not sure that the format is valid.
293 void EnsureSize();
296 class SC_DLLPUBLIC ScDataBarFormat : public ScColorFormat
298 public:
299 ScDataBarFormat(ScDocument* pDoc);
300 ScDataBarFormat(ScDocument* pDoc, const ScDataBarFormat& rFormat);
301 virtual ScColorFormat* Clone(ScDocument* pDoc) const override;
303 virtual void SetParent(ScConditionalFormat* pParent) override;
305 ScDataBarInfo* GetDataBarInfo(const ScAddress& rAddr) const;
307 void SetDataBarData( ScDataBarFormatData* pData );
308 const ScDataBarFormatData* GetDataBarData() const;
309 ScDataBarFormatData* GetDataBarData();
311 virtual void UpdateReference( sc::RefUpdateContext& rCxt ) override;
312 virtual void UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt ) override;
313 virtual void UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt ) override;
314 virtual void UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt ) override;
316 virtual Type GetType() const override;
319 * Makes sure that the mpFormatData does not contain valid entries.
320 * Should be called when it is not sure that the format is valid.
322 void EnsureSize();
324 private:
325 double getMin(double nMin, double nMax) const;
326 double getMax(double nMin, double nMax) const;
328 std::unique_ptr<ScDataBarFormatData> mpFormatData;
331 struct ScIconSetFormatData
333 ScIconSetType eIconSetType;
334 bool mbShowValue;
336 * Specifies whether the icons should be shown in reverse order
338 bool mbReverse;
339 typedef std::vector<std::unique_ptr<ScColorScaleEntry>> Entries_t;
340 Entries_t m_Entries;
341 bool mbCustom;
342 // the std::pair points to exactly one image
343 // std..pair::second == -1 means no image
344 std::vector<std::pair<ScIconSetType, sal_Int32> > maCustomVector;
346 ScIconSetFormatData():
347 eIconSetType(IconSet_3Arrows),
348 mbShowValue(true),
349 mbReverse(false),
350 mbCustom(false)
353 ScIconSetFormatData(ScIconSetFormatData const&);
354 ScIconSetFormatData& operator=(ScIconSetFormatData const&) = delete; //TODO?
357 class SC_DLLPUBLIC ScIconSetFormat : public ScColorFormat
359 public:
360 ScIconSetFormat(ScDocument* pDoc);
361 ScIconSetFormat(ScDocument* pDoc, const ScIconSetFormat& rFormat);
363 virtual ScColorFormat* Clone(ScDocument* pDoc) const override;
365 virtual void SetParent(ScConditionalFormat* pParent) override;
367 ScIconSetInfo* GetIconSetInfo(const ScAddress& rAddr) const;
369 void SetIconSetData( ScIconSetFormatData* pData );
370 const ScIconSetFormatData* GetIconSetData() const;
371 ScIconSetFormatData* GetIconSetData();
373 virtual void UpdateReference( sc::RefUpdateContext& rCxt ) override;
374 virtual void UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt ) override;
375 virtual void UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt ) override;
376 virtual void UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt ) override;
378 virtual Type GetType() const override;
380 static const ScIconSetMap g_IconSetMap[];
381 static BitmapEx& getBitmap(sc::IconSetBitmapMap& rBitmapMap, ScIconSetType eType, sal_Int32 nIndex);
383 typedef ScIconSetFormatData::Entries_t::iterator iterator;
384 typedef ScIconSetFormatData::Entries_t::const_iterator const_iterator;
386 iterator begin();
387 const_iterator begin() const;
388 iterator end();
389 const_iterator end() const;
391 size_t size() const;
394 * Makes sure that the mpFormatData does not contain valid entries.
395 * Should be called when it is not sure that the format is valid.
397 void EnsureSize();
399 private:
401 double GetMinValue() const;
402 double GetMaxValue() const;
403 double CalcValue(double nMin, double nMax, const ScIconSetFormat::const_iterator& itr) const;
405 std::unique_ptr<ScIconSetFormatData> mpFormatData;
408 #endif
410 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */