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 #ifndef INCLUDED_SC_INC_COLORSCALE_HXX
11 #define INCLUDED_SC_INC_COLORSCALE_HXX
12 
13 #include <formula/grammar.hxx>
14 #include <tools/color.hxx>
15 #include "conditio.hxx"
16 #include "document.hxx"
17 
18 #include <memory>
19 #include <vector>
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* pDoc, 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  if(r.mpNegativeColor)
120  mpNegativeColor.reset(new Color(*r.mpNegativeColor));
121 
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());
130  }
131 
141  std::unique_ptr<Color> mpNegativeColor;
160  bool mbNeg; //differentiate between negative values
173  double mnMinLength;
178  double mnMaxLength;
179 
183  bool mbOnlyBar;
184 
185  std::unique_ptr<ScColorScaleEntry, o3tl::default_delete<ScColorScaleEntry>> mpUpperLimit;
186  std::unique_ptr<ScColorScaleEntry, o3tl::default_delete<ScColorScaleEntry>> mpLowerLimit;
187 };
188 
190 {
213 };
214 
215 struct ScIconSetMap {
216  const char* pName;
218  sal_Int32 nElements;
219 };
220 
222 {
223 public:
224  ScColorFormat(ScDocument* pDoc);
225  virtual ~ScColorFormat() override;
226 
227  const ScRangeList& GetRange() const;
228 
229  virtual void SetParent(ScConditionalFormat* pParent) override;
230 
231  virtual void startRendering() override;
232  virtual void endRendering() override;
233 
234 protected:
235  std::vector<double>& getValues() const;
236 
237  double getMinValue() const;
238  double getMaxValue() const;
239 
241 
242 private:
243 
245  {
246  std::vector<double> maValues;
247  };
248  mutable std::unique_ptr<ScColorFormatCache> mpCache;
249 };
250 
251 typedef std::vector<std::unique_ptr<ScColorScaleEntry, o3tl::default_delete<ScColorScaleEntry>>> ScColorScaleEntries;
252 
254 {
255 private:
256  ScColorScaleEntries maColorScales;
257 
258  double GetMinValue() const;
259  double GetMaxValue() const;
260 
261  void calcMinMax(double& nMin, double& nMax) const;
262  double CalcValue(double nMin, double nMax, const ScColorScaleEntries::const_iterator& rItr) const;
263 public:
265  ScColorScaleFormat(ScDocument* pDoc, const ScColorScaleFormat& rFormat);
266  virtual ~ScColorScaleFormat() override;
267  virtual ScColorFormat* Clone(ScDocument* pDoc) const override;
268 
269  virtual void SetParent(ScConditionalFormat* pParent) override;
270 
271  std::optional<Color> GetColor(const ScAddress& rAddr) const;
272  void AddEntry(ScColorScaleEntry* pEntry);
273 
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;
278 
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;
284 
285  ScColorScaleEntry* GetEntry(size_t nPos);
286  const ScColorScaleEntry* GetEntry(size_t nPos) const;
287 
288  size_t size() const;
289 
294  void EnsureSize();
295 };
296 
298 {
299 public:
301  ScDataBarFormat(ScDocument* pDoc, const ScDataBarFormat& rFormat);
302  virtual ScColorFormat* Clone(ScDocument* pDoc) const override;
303 
304  virtual void SetParent(ScConditionalFormat* pParent) override;
305 
306  std::unique_ptr<ScDataBarInfo> GetDataBarInfo(const ScAddress& rAddr) const;
307 
308  void SetDataBarData( ScDataBarFormatData* pData );
309  const ScDataBarFormatData* GetDataBarData() const;
310  ScDataBarFormatData* GetDataBarData();
311 
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;
316 
317  virtual Type GetType() const override;
318 
323  void EnsureSize();
324 
325 private:
326  double getMin(double nMin, double nMax) const;
327  double getMax(double nMin, double nMax) const;
328 
329  std::unique_ptr<ScDataBarFormatData> mpFormatData;
330 };
331 
333 {
339  bool mbReverse;
340  typedef std::vector<std::unique_ptr<ScColorScaleEntry, o3tl::default_delete<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;
346 
348  eIconSetType(eType),
349  mbShowValue(true),
350  mbReverse(false),
351  mbCustom(false)
352  {}
353 
355  ScIconSetFormatData& operator=(ScIconSetFormatData const&) = delete; //TODO?
356 };
357 
359 {
360 public:
362  ScIconSetFormat(ScDocument* pDoc, const ScIconSetFormat& rFormat);
363 
364  virtual ScColorFormat* Clone(ScDocument* pDoc) const override;
365 
366  virtual void SetParent(ScConditionalFormat* pParent) override;
367 
368  std::unique_ptr<ScIconSetInfo> GetIconSetInfo(const ScAddress& rAddr) const;
369 
370  void SetIconSetData( ScIconSetFormatData* pData );
371  const ScIconSetFormatData* GetIconSetData() const;
372  ScIconSetFormatData* GetIconSetData();
373 
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;
378 
379  virtual Type GetType() const override;
380 
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);
386 
387  typedef ScIconSetFormatData::Entries_t::iterator iterator;
388  typedef ScIconSetFormatData::Entries_t::const_iterator const_iterator;
389 
390  iterator begin();
391  const_iterator begin() const;
392  iterator end();
393  const_iterator end() const;
394 
395  size_t size() const;
396 
401  void EnsureSize();
402 
403 private:
404 
405  double GetMinValue() const;
406  double GetMaxValue() const;
407  double CalcValue(double nMin, double nMax, const ScIconSetFormat::const_iterator& itr) const;
408 
409  std::unique_ptr<ScIconSetFormatData> mpFormatData;
410 };
411 
412 #endif
413 
414 /* 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:178
ScConditionalFormat * mpFormat
Definition: colorscale.hxx:48
constexpr::Color COL_BLACK(0x00, 0x00, 0x00)
std::vector< std::pair< ScIconSetType, sal_Int32 > > maCustomVector
Definition: colorscale.hxx:345
ScIconSetFormatData::Entries_t::iterator iterator
Definition: colorscale.hxx:387
ScColorScaleEntryType meType
Definition: colorscale.hxx:50
std::unique_ptr< ContentProperties > pData
std::string GetValue
std::vector< double > maValues
Definition: colorscale.hxx:246
bool mbReverse
Specifies whether the icons should be shown in reverse order.
Definition: colorscale.hxx:339
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:173
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:183
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:248
ScIconSetType eIconSetType
Definition: colorscale.hxx:334
ScColorScaleEntryType GetType() const
Definition: colorscale.hxx:76
std::vector< std::unique_ptr< ScColorScaleEntry, o3tl::default_delete< ScColorScaleEntry > > > Entries_t
Definition: colorscale.hxx:340
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:135
virtual void SetParent(ScConditionalFormat *pNew)=0
Color maAxisColor
Color of the axis if used Default color is black.
Definition: colorscale.hxx:146
DocumentType eType
ScColorScaleEntryType
Definition: colorscale.hxx:31
virtual void UpdateReference(sc::RefUpdateContext &rCxt)=0
bool mbGradient
Paint the bars with gradient.
Definition: colorscale.hxx:153
std::unique_ptr< ScDataBarFormatData > mpFormatData
Definition: colorscale.hxx:329
virtual void SetParent(ScConditionalFormat *pParent) override
Definition: colorscale.cxx:364
size
virtual ScFormatEntry * Clone(ScDocument *pDoc) const =0
ScIconSetType eType
Definition: colorscale.hxx:217
ScIconSetFormatData::Entries_t::const_iterator const_iterator
Definition: colorscale.hxx:388
ScIconSetFormatData(ScIconSetType eType=IconSet_3Arrows)
Definition: colorscale.hxx:347
std::vector< std::unique_ptr< ScColorScaleEntry, o3tl::default_delete< ScColorScaleEntry > > > ScColorScaleEntries
Definition: colorscale.hxx:251
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:168
std::unique_ptr< Color > mpNegativeColor
Specifies the color for negative values.
Definition: colorscale.hxx:141
std::unique_ptr< ScColorScaleEntry, o3tl::default_delete< ScColorScaleEntry > > mpUpperLimit
Definition: colorscale.hxx:185
virtual void UpdateDeleteTab(sc::RefUpdateDeleteTabContext &rCxt)=0
const char * pName
Definition: colorscale.hxx:216
virtual void startRendering()
Definition: conditio.cxx:68
ScIconSetType
Definition: colorscale.hxx:189
ScColorScaleEntries maColorScales
Definition: colorscale.hxx:256
virtual Type GetType() const =0
std::unique_ptr< ScColorScaleEntry, o3tl::default_delete< ScColorScaleEntry > > mpLowerLimit
Definition: colorscale.hxx:186
ScConditionalFormat * mpParent
Definition: colorscale.hxx:240
#define SC_DLLPUBLIC
Definition: scdllapi.h:28
bool mbNeg
Use different color for negative values.
Definition: colorscale.hxx:160
AUTOMATIC
sal_Int32 nElements
Definition: colorscale.hxx:218
std::unique_ptr< ScIconSetFormatData > mpFormatData
Definition: colorscale.hxx:409