Bump version to 6.4-15
[LibreOffice.git] / sc / inc / colorscale.hxx
blob8a6639de636c511bb985831b7c9ea505a78f8d23
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 "conditio.hxx"
16 #include "document.hxx"
18 #include <memory>
19 #include <vector>
21 //TODO: merge this with conditio.hxx
23 class ScFormulaCell;
24 class ScTokenArray;
25 struct ScDataBarInfo;
26 class BitmapEx;
28 // don't change the order
29 // they are also used in the dialog to determine the position
30 // in the list box
31 enum ScColorScaleEntryType
33 COLORSCALE_AUTO,
34 COLORSCALE_MIN,
35 COLORSCALE_MAX,
36 COLORSCALE_PERCENTILE,
37 COLORSCALE_VALUE,
38 COLORSCALE_PERCENT,
39 COLORSCALE_FORMULA,
42 class SC_DLLPUBLIC ScColorScaleEntry
44 private:
45 double mnVal;
46 std::unique_ptr<ScFormulaCell> mpCell;
47 std::unique_ptr<ScFormulaListener> mpListener;
48 ScConditionalFormat* mpFormat;
49 Color maColor;
50 ScColorScaleEntryType meType;
52 void setListener();
54 public:
55 ScColorScaleEntry(double nVal, const Color& rCol, ScColorScaleEntryType eType = COLORSCALE_VALUE);
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);
80 void SetRepaintCallback(const std::function<void()>& func);
83 namespace databar
86 enum ScAxisPosition
88 NONE,
89 AUTOMATIC,
90 MIDDLE
95 struct SC_DLLPUBLIC ScDataBarFormatData
97 ScDataBarFormatData():
98 maAxisColor(COL_BLACK),
99 mbGradient(true),
100 mbNeg(true),
101 meAxisPosition(databar::AUTOMATIC),
102 mnMinLength(0),
103 mnMaxLength(100),
104 mbOnlyBar(false),
105 mpUpperLimit(new ScColorScaleEntry()),
106 mpLowerLimit(new ScColorScaleEntry())
109 ScDataBarFormatData(const ScDataBarFormatData& r):
110 maPositiveColor(r.maPositiveColor),
111 maAxisColor(r.maAxisColor),
112 mbGradient(r.mbGradient),
113 mbNeg(r.mbNeg),
114 meAxisPosition(r.meAxisPosition),
115 mnMinLength(r.mnMinLength),
116 mnMaxLength(r.mnMaxLength),
117 mbOnlyBar(r.mbOnlyBar)
119 if(r.mpNegativeColor)
120 mpNegativeColor.reset(new Color(*r.mpNegativeColor));
122 if(r.mpLowerLimit)
123 mpLowerLimit.reset( new ScColorScaleEntry(*r.mpLowerLimit));
124 else
125 mpLowerLimit.reset(new ScColorScaleEntry());
126 if(r.mpUpperLimit)
127 mpUpperLimit.reset( new ScColorScaleEntry(*r.mpUpperLimit));
128 else
129 mpUpperLimit.reset(new ScColorScaleEntry());
133 * Color for all Positive Values and if mbNeg == false also for negative ones
135 Color maPositiveColor;
137 * Specifies the color for negative values. This is optional and depends on mbNeg.
139 * Default color is 0xFF0000, this value is not set
141 std::unique_ptr<Color> mpNegativeColor;
143 * Color of the axis if used
144 * Default color is black
146 Color maAxisColor;
148 * Paint the bars with gradient. If this is used the default is to draw with
149 * borders.
151 * Default is true
153 bool mbGradient;
155 * Use different color for negative values. Color is specified in
156 * mpNegativeColor and defaults to 0xFF0000
158 * Default is true
160 bool mbNeg; //differentiate between negative values
162 * Paint negative values into the same direction as positive values
163 * If false we will set the mid point according to the upper and lower limit and negative
164 * values are painted to the left and positive to the right
166 * Default is false
168 databar::ScAxisPosition meAxisPosition;
170 * Minimal length of a databar in percent of cell length
171 * Value has to be in the range [0, 100)
173 double mnMinLength;
175 * Maximal length of a databar in percent of cell length
176 * Value has to be in the range (0, 100]
178 double mnMaxLength;
181 * If TRUE we only show the bar and not the value
183 bool mbOnlyBar;
185 std::unique_ptr<ScColorScaleEntry> mpUpperLimit;
186 std::unique_ptr<ScColorScaleEntry> mpLowerLimit;
189 enum ScIconSetType
191 IconSet_3Arrows,
192 IconSet_3ArrowsGray,
193 IconSet_3Flags,
194 IconSet_3TrafficLights1,
195 IconSet_3TrafficLights2,
196 IconSet_3Signs,
197 IconSet_3Symbols,
198 IconSet_3Symbols2,
199 IconSet_3Smilies,
200 IconSet_3Stars,
201 IconSet_3Triangles,
202 IconSet_3ColorSmilies,
203 IconSet_4Arrows,
204 IconSet_4ArrowsGray,
205 IconSet_4RedToBlack,
206 IconSet_4Rating,
207 IconSet_4TrafficLights,
208 IconSet_5Arrows,
209 IconSet_5ArrowsGray,
210 IconSet_5Ratings,
211 IconSet_5Quarters,
212 IconSet_5Boxes
215 struct ScIconSetMap {
216 const char* pName;
217 ScIconSetType const eType;
218 sal_Int32 const nElements;
221 class SC_DLLPUBLIC ScColorFormat : public ScFormatEntry
223 public:
224 ScColorFormat(ScDocument* pDoc);
225 virtual ~ScColorFormat() override;
227 const ScRangeList& GetRange() const;
229 virtual void SetParent(ScConditionalFormat* pParent) override;
231 virtual void startRendering() override;
232 virtual void endRendering() override;
234 protected:
235 std::vector<double>& getValues() const;
237 double getMinValue() const;
238 double getMaxValue() const;
240 ScConditionalFormat* mpParent;
242 private:
244 struct ScColorFormatCache
246 std::vector<double> maValues;
248 mutable std::unique_ptr<ScColorFormatCache> mpCache;
251 typedef std::vector<std::unique_ptr<ScColorScaleEntry>> ScColorScaleEntries;
253 class SC_DLLPUBLIC ScColorScaleFormat final : public ScColorFormat
255 private:
256 ScColorScaleEntries maColorScales;
258 double GetMinValue() const;
259 double GetMaxValue() const;
261 void calcMinMax(double& nMin, double& nMax) const;
262 double CalcValue(double nMin, double nMax, const ScColorScaleEntries::const_iterator& rItr) const;
263 public:
264 ScColorScaleFormat(ScDocument* pDoc);
265 ScColorScaleFormat(ScDocument* pDoc, const ScColorScaleFormat& rFormat);
266 virtual ~ScColorScaleFormat() override;
267 virtual ScColorFormat* Clone(ScDocument* pDoc) const override;
269 virtual void SetParent(ScConditionalFormat* pParent) override;
271 boost::optional<Color> GetColor(const ScAddress& rAddr) const;
272 void AddEntry(ScColorScaleEntry* pEntry);
274 virtual void UpdateReference( sc::RefUpdateContext& rCxt ) override;
275 virtual void UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt ) override;
276 virtual void UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt ) override;
277 virtual void UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt ) override;
279 virtual Type GetType() const override;
280 ScColorScaleEntries::iterator begin();
281 ScColorScaleEntries::const_iterator begin() const;
282 ScColorScaleEntries::iterator end();
283 ScColorScaleEntries::const_iterator end() const;
285 ScColorScaleEntry* GetEntry(size_t nPos);
286 const ScColorScaleEntry* GetEntry(size_t nPos) const;
288 size_t size() const;
291 * Makes sure that the maColorScales contain at least 2 entries.
292 * Should be called when it is not sure that the format is valid.
294 void EnsureSize();
297 class SC_DLLPUBLIC ScDataBarFormat final : public ScColorFormat
299 public:
300 ScDataBarFormat(ScDocument* pDoc);
301 ScDataBarFormat(ScDocument* pDoc, const ScDataBarFormat& rFormat);
302 virtual ScColorFormat* Clone(ScDocument* pDoc) const override;
304 virtual void SetParent(ScConditionalFormat* pParent) override;
306 std::unique_ptr<ScDataBarInfo> GetDataBarInfo(const ScAddress& rAddr) const;
308 void SetDataBarData( ScDataBarFormatData* pData );
309 const ScDataBarFormatData* GetDataBarData() const;
310 ScDataBarFormatData* GetDataBarData();
312 virtual void UpdateReference( sc::RefUpdateContext& rCxt ) override;
313 virtual void UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt ) override;
314 virtual void UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt ) override;
315 virtual void UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt ) override;
317 virtual Type GetType() const override;
320 * Makes sure that the mpFormatData does not contain valid entries.
321 * Should be called when it is not sure that the format is valid.
323 void EnsureSize();
325 private:
326 double getMin(double nMin, double nMax) const;
327 double getMax(double nMin, double nMax) const;
329 std::unique_ptr<ScDataBarFormatData> mpFormatData;
332 struct ScIconSetFormatData
334 ScIconSetType eIconSetType;
335 bool mbShowValue;
337 * Specifies whether the icons should be shown in reverse order
339 bool mbReverse;
340 typedef std::vector<std::unique_ptr<ScColorScaleEntry>> Entries_t;
341 Entries_t m_Entries;
342 bool mbCustom;
343 // the std::pair points to exactly one image
344 // std..pair::second == -1 means no image
345 std::vector<std::pair<ScIconSetType, sal_Int32> > maCustomVector;
347 ScIconSetFormatData(ScIconSetType eType = IconSet_3Arrows):
348 eIconSetType(eType),
349 mbShowValue(true),
350 mbReverse(false),
351 mbCustom(false)
354 ScIconSetFormatData(ScIconSetFormatData const&);
355 ScIconSetFormatData& operator=(ScIconSetFormatData const&) = delete; //TODO?
358 class SC_DLLPUBLIC ScIconSetFormat final : public ScColorFormat
360 public:
361 ScIconSetFormat(ScDocument* pDoc);
362 ScIconSetFormat(ScDocument* pDoc, const ScIconSetFormat& rFormat);
364 virtual ScColorFormat* Clone(ScDocument* pDoc) const override;
366 virtual void SetParent(ScConditionalFormat* pParent) override;
368 std::unique_ptr<ScIconSetInfo> GetIconSetInfo(const ScAddress& rAddr) const;
370 void SetIconSetData( ScIconSetFormatData* pData );
371 const ScIconSetFormatData* GetIconSetData() const;
372 ScIconSetFormatData* GetIconSetData();
374 virtual void UpdateReference( sc::RefUpdateContext& rCxt ) override;
375 virtual void UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt ) override;
376 virtual void UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt ) override;
377 virtual void UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt ) override;
379 virtual Type GetType() const override;
381 static const ScIconSetMap g_IconSetMap[];
382 static const char* getIconSetName( ScIconSetType eType );
383 static sal_Int32 getIconSetElements( ScIconSetType eType );
384 static OUString getIconName(ScIconSetType eType, sal_Int32 nIndex);
385 static BitmapEx& getBitmap(sc::IconSetBitmapMap& rBitmapMap, ScIconSetType eType, sal_Int32 nIndex);
387 typedef ScIconSetFormatData::Entries_t::iterator iterator;
388 typedef ScIconSetFormatData::Entries_t::const_iterator const_iterator;
390 iterator begin();
391 const_iterator begin() const;
392 iterator end();
393 const_iterator end() const;
395 size_t size() const;
398 * Makes sure that the mpFormatData does not contain valid entries.
399 * Should be called when it is not sure that the format is valid.
401 void EnsureSize();
403 private:
405 double GetMinValue() const;
406 double GetMaxValue() const;
407 double CalcValue(double nMin, double nMax, const ScIconSetFormat::const_iterator& itr) const;
409 std::unique_ptr<ScIconSetFormatData> mpFormatData;
412 #endif
414 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */