LibreOffice Module sc (master)  1
colorscale.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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  */
9 
10 #pragma once
11 
12 #include <formula/grammar.hxx>
13 #include <tools/color.hxx>
14 #include "conditio.hxx"
15 #include "document.hxx"
16 
17 #include <memory>
18 #include <vector>
19 #include <optional>
20 
21 //TODO: merge this with conditio.hxx
22 
23 class ScFormulaCell;
24 class ScTokenArray;
25 struct ScDataBarInfo;
26 class BitmapEx;
27 
28 // don't change the order
29 // they are also used in the dialog to determine the position
30 // in the list box
32 {
40 };
41 
43 {
44 private:
45  double mnVal;
46  std::unique_ptr<ScFormulaCell> mpCell;
47  std::unique_ptr<ScFormulaListener> mpListener;
51 
52  void setListener();
53 
54 public:
55  ScColorScaleEntry(double nVal, const Color& rCol, ScColorScaleEntryType eType = COLORSCALE_VALUE);
57  ScColorScaleEntry(const ScColorScaleEntry& rEntry);
58  ScColorScaleEntry(ScDocument* pDoc, const ScColorScaleEntry& rEntry);
59  ~ScColorScaleEntry() COVERITY_NOEXCEPT_FALSE;
60 
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& rDoc, const ScAddress& rAddr,
67 
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 );
72 
73  const ScTokenArray* GetFormula() const;
74  OUString GetFormula( formula::FormulaGrammar::Grammar eGrammar ) const;
75 
76  ScColorScaleEntryType GetType() const { return meType;}
77  void SetType( ScColorScaleEntryType eType );
78 
79  void SetRepaintCallback(ScConditionalFormat* pParent);
80  void SetRepaintCallback(const std::function<void()>& func);
81 };
82 
83 namespace databar
84 {
85 
87 {
91 };
92 
93 }
94 
96 {
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())
107  {}
108 
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)
118  {
119  mxNegativeColor = r.mxNegativeColor;
120 
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());
129  }
130 
140  std::optional<Color> mxNegativeColor;
159  bool mbNeg; //differentiate between negative values
172  double mnMinLength;
177  double mnMaxLength;
178 
182  bool mbOnlyBar;
183 
184  std::unique_ptr<ScColorScaleEntry, o3tl::default_delete<ScColorScaleEntry>> mpUpperLimit;
185  std::unique_ptr<ScColorScaleEntry, o3tl::default_delete<ScColorScaleEntry>> mpLowerLimit;
186 };
187 
189 {
212 };
213 
214 struct ScIconSetMap {
215  const char* pName;
217  sal_Int32 nElements;
218 };
219 
221 {
222 public:
223  ScColorFormat(ScDocument* pDoc);
224  virtual ~ScColorFormat() override;
225 
226  const ScRangeList& GetRange() const;
227 
228  virtual void SetParent(ScConditionalFormat* pParent) override;
229 
230  virtual void startRendering() override;
231  virtual void endRendering() override;
232 
233 protected:
234  std::vector<double>& getValues() const;
235 
236  double getMinValue() const;
237  double getMaxValue() const;
238 
240 
241 private:
242 
244  {
245  std::vector<double> maValues;
246  };
247  mutable std::unique_ptr<ScColorFormatCache> mpCache;
248 };
249 
250 typedef std::vector<std::unique_ptr<ScColorScaleEntry, o3tl::default_delete<ScColorScaleEntry>>> ScColorScaleEntries;
251 
253 {
254 private:
255  ScColorScaleEntries maColorScales;
256 
257  double GetMinValue() const;
258  double GetMaxValue() const;
259 
260  void calcMinMax(double& nMin, double& nMax) const;
261  double CalcValue(double nMin, double nMax, const ScColorScaleEntries::const_iterator& rItr) const;
262 public:
264  ScColorScaleFormat(ScDocument* pDoc, const ScColorScaleFormat& rFormat);
265  virtual ~ScColorScaleFormat() override;
266  virtual ScColorFormat* Clone(ScDocument* pDoc) const override;
267 
268  virtual void SetParent(ScConditionalFormat* pParent) override;
269 
270  std::optional<Color> GetColor(const ScAddress& rAddr) const;
271  void AddEntry(ScColorScaleEntry* pEntry);
272 
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;
277 
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;
283 
284  ScColorScaleEntry* GetEntry(size_t nPos);
285  const ScColorScaleEntry* GetEntry(size_t nPos) const;
286 
287  size_t size() const;
288 
293  void EnsureSize();
294 };
295 
297 {
298 public:
300  ScDataBarFormat(ScDocument* pDoc, const ScDataBarFormat& rFormat);
301  virtual ScColorFormat* Clone(ScDocument* pDoc) const override;
302 
303  virtual void SetParent(ScConditionalFormat* pParent) override;
304 
305  std::unique_ptr<ScDataBarInfo> GetDataBarInfo(const ScAddress& rAddr) const;
306 
307  void SetDataBarData( ScDataBarFormatData* pData );
308  const ScDataBarFormatData* GetDataBarData() const;
309  ScDataBarFormatData* GetDataBarData();
310 
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;
315 
316  virtual Type GetType() const override;
317 
322  void EnsureSize();
323 
324 private:
325  double getMin(double nMin, double nMax) const;
326  double getMax(double nMin, double nMax) const;
327 
328  std::unique_ptr<ScDataBarFormatData> mpFormatData;
329 };
330 
332 {
338  bool mbReverse;
339  typedef std::vector<std::unique_ptr<ScColorScaleEntry, o3tl::default_delete<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;
345 
347  eIconSetType(eType),
348  mbShowValue(true),
349  mbReverse(false),
350  mbCustom(false)
351  {}
352 
354  ScIconSetFormatData& operator=(ScIconSetFormatData const&) = delete; //TODO?
355 };
356 
358 {
359 public:
361  ScIconSetFormat(ScDocument* pDoc, const ScIconSetFormat& rFormat);
362 
363  virtual ScColorFormat* Clone(ScDocument* pDoc) const override;
364 
365  virtual void SetParent(ScConditionalFormat* pParent) override;
366 
367  std::unique_ptr<ScIconSetInfo> GetIconSetInfo(const ScAddress& rAddr) const;
368 
369  void SetIconSetData( ScIconSetFormatData* pData );
370  const ScIconSetFormatData* GetIconSetData() const;
371  ScIconSetFormatData* GetIconSetData();
372 
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;
377 
378  virtual Type GetType() const override;
379 
380  static const ScIconSetMap g_IconSetMap[];
381  static const char* getIconSetName( ScIconSetType eType );
382  static sal_Int32 getIconSetElements( ScIconSetType eType );
383  static OUString getIconName(ScIconSetType eType, sal_Int32 nIndex);
384  static BitmapEx& getBitmap(sc::IconSetBitmapMap& rBitmapMap, ScIconSetType eType, sal_Int32 nIndex);
385 
386  typedef ScIconSetFormatData::Entries_t::iterator iterator;
387  typedef ScIconSetFormatData::Entries_t::const_iterator const_iterator;
388 
389  iterator begin();
390  const_iterator begin() const;
391  iterator end();
392  const_iterator end() const;
393 
394  size_t size() const;
395 
400  void EnsureSize();
401 
402 private:
403 
404  double GetMinValue() const;
405  double GetMaxValue() const;
406  double CalcValue(double nMin, double nMax, const ScIconSetFormat::const_iterator& itr) const;
407 
408  std::unique_ptr<ScIconSetFormatData> mpFormatData;
409 };
410 
411 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScIconSetFormatData & operator=(ScIconSetFormatData const &)=delete
double mnMaxLength
Maximal length of a databar in percent of cell length Value has to be in the range (0...
Definition: colorscale.hxx:177
ScConditionalFormat * mpFormat
Definition: colorscale.hxx:48
std::vector< std::pair< ScIconSetType, sal_Int32 > > maCustomVector
Definition: colorscale.hxx:344
ScIconSetFormatData::Entries_t::iterator iterator
Definition: colorscale.hxx:386
ScColorScaleEntryType meType
Definition: colorscale.hxx:50
std::unique_ptr< ContentProperties > pData
std::string GetValue
std::vector< double > maValues
Definition: colorscale.hxx:245
bool mbReverse
Specifies whether the icons should be shown in reverse order.
Definition: colorscale.hxx:338
Context for reference update during shifting, moving or copying of cell ranges.
ScDataBarFormatData(const ScDataBarFormatData &r)
Definition: colorscale.hxx:109
double mnMinLength
Minimal length of a databar in percent of cell length Value has to be in the range [0...
Definition: colorscale.hxx:172
std::unique_ptr< ScFormulaCell > mpCell
Definition: colorscale.hxx:46
virtual void UpdateMoveTab(sc::RefUpdateMoveTabContext &rCxt)=0
bool mbOnlyBar
If TRUE we only show the bar and not the value.
Definition: colorscale.hxx:182
std::optional< Color > mxNegativeColor
Specifies the color for negative values.
Definition: colorscale.hxx:140
virtual void endRendering()
Definition: conditio.cxx:72
virtual void UpdateInsertTab(sc::RefUpdateInsertTabContext &rCxt)=0
enumrange< T >::Iterator begin(enumrange< T >)
std::unique_ptr< ScFormulaListener > mpListener
Definition: colorscale.hxx:47
std::unique_ptr< ScColorFormatCache > mpCache
Definition: colorscale.hxx:247
ScIconSetType eIconSetType
Definition: colorscale.hxx:333
ScColorScaleEntryType GetType() const
Definition: colorscale.hxx:76
std::vector< std::unique_ptr< ScColorScaleEntry, o3tl::default_delete< ScColorScaleEntry > > > Entries_t
Definition: colorscale.hxx:339
std::map< OUString, BitmapEx > IconSetBitmapMap
Definition: document.hxx:207
Color maPositiveColor
Color for all Positive Values and if mbNeg == false also for negative ones.
Definition: colorscale.hxx:134
virtual void SetParent(ScConditionalFormat *pNew)=0
Color maAxisColor
Color of the axis if used Default color is black.
Definition: colorscale.hxx:145
DocumentType eType
ScColorScaleEntryType
Definition: colorscale.hxx:31
virtual void UpdateReference(sc::RefUpdateContext &rCxt)=0
bool mbGradient
Paint the bars with gradient.
Definition: colorscale.hxx:152
std::unique_ptr< ScDataBarFormatData > mpFormatData
Definition: colorscale.hxx:328
virtual void SetParent(ScConditionalFormat *pParent) override
Definition: colorscale.cxx:365
size
virtual ScFormatEntry * Clone(ScDocument *pDoc) const =0
ScIconSetType eType
Definition: colorscale.hxx:216
ScIconSetFormatData::Entries_t::const_iterator const_iterator
Definition: colorscale.hxx:387
ScIconSetFormatData(ScIconSetType eType=IconSet_3Arrows)
Definition: colorscale.hxx:346
std::vector< std::unique_ptr< ScColorScaleEntry, o3tl::default_delete< ScColorScaleEntry > > > ScColorScaleEntries
Definition: colorscale.hxx:250
enumrange< T >::Iterator end(enumrange< T >)
databar::ScAxisPosition meAxisPosition
Paint negative values into the same direction as positive values If false we will set the mid point a...
Definition: colorscale.hxx:167
std::unique_ptr< ScColorScaleEntry, o3tl::default_delete< ScColorScaleEntry > > mpUpperLimit
Definition: colorscale.hxx:184
const ::std::vector< Color > ImpSvNumberformatScan::StandardColor COL_BLACK
virtual void UpdateDeleteTab(sc::RefUpdateDeleteTabContext &rCxt)=0
const char * pName
Definition: colorscale.hxx:215
virtual void startRendering()
Definition: conditio.cxx:68
ScIconSetType
Definition: colorscale.hxx:188
ScColorScaleEntries maColorScales
Definition: colorscale.hxx:255
virtual Type GetType() const =0
std::unique_ptr< ScColorScaleEntry, o3tl::default_delete< ScColorScaleEntry > > mpLowerLimit
Definition: colorscale.hxx:185
ScConditionalFormat * mpParent
Definition: colorscale.hxx:239
#define SC_DLLPUBLIC
Definition: scdllapi.h:27
bool mbNeg
Use different color for negative values.
Definition: colorscale.hxx:159
AUTOMATIC
sal_Int32 nElements
Definition: colorscale.hxx:217
std::unique_ptr< ScIconSetFormatData > mpFormatData
Definition: colorscale.hxx:408