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
23class ScFormulaCell;
24class ScTokenArray;
25struct ScDataBarInfo;
26class 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{
44private:
45 double mnVal;
46 std::unique_ptr<ScFormulaCell> mpCell;
47 std::unique_ptr<ScFormulaListener> mpListener;
51
52 void setListener();
53
54public:
55 ScColorScaleEntry(double nVal, const Color& rCol, ScColorScaleEntryType eType = COLORSCALE_VALUE);
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
77 void SetType( ScColorScaleEntryType eType );
78
79 void SetRepaintCallback(ScConditionalFormat* pParent);
80 void SetRepaintCallback(const std::function<void()>& func);
81};
82
83namespace databar
84{
85
87{
90 MIDDLE
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
178
183
184 std::unique_ptr<ScColorScaleEntry, o3tl::default_delete<ScColorScaleEntry>> mpUpperLimit;
185 std::unique_ptr<ScColorScaleEntry, o3tl::default_delete<ScColorScaleEntry>> mpLowerLimit;
186};
187
189{
213
215 const char* pName;
217 sal_Int32 nElements;
218};
219
221{
222public:
224 virtual ~ScColorFormat() override;
225
226 const ScRangeList& GetRange() const;
227 void SetCache(const std::vector<double>& aValues);
228 std::vector<double> GetCache() const;
229
230 virtual void SetParent(ScConditionalFormat* pParent) override;
231
232 virtual void startRendering() override;
233 virtual void endRendering() override;
234 virtual void updateValues() override;
235
236protected:
237 std::vector<double>& getValues() const;
238
239 double getMinValue() const;
240 double getMaxValue() const;
241
243
244private:
245
247 {
248 std::vector<double> maValues;
249 };
250 mutable std::unique_ptr<ScColorFormatCache> mpCache;
251};
252
253typedef std::vector<std::unique_ptr<ScColorScaleEntry, o3tl::default_delete<ScColorScaleEntry>>> ScColorScaleEntries;
254
256{
257private:
259
260 double GetMinValue() const;
261 double GetMaxValue() const;
262
263 void calcMinMax(double& nMin, double& nMax) const;
264 double CalcValue(double nMin, double nMax, const ScColorScaleEntries::const_iterator& rItr) const;
265public:
267 ScColorScaleFormat(ScDocument* pDoc, const ScColorScaleFormat& rFormat);
268 virtual ~ScColorScaleFormat() override;
269 virtual ScColorFormat* Clone(ScDocument* pDoc) const override;
270
271 virtual void SetParent(ScConditionalFormat* pParent) override;
272
273 std::optional<Color> GetColor(const ScAddress& rAddr) const;
274 void AddEntry(ScColorScaleEntry* pEntry);
275
276 bool IsEqual(const ScFormatEntry& r, bool bIgnoreSrcPos) const override;
277
278 virtual void UpdateReference( sc::RefUpdateContext& rCxt ) override;
279 virtual void UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt ) override;
280 virtual void UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt ) override;
281 virtual void UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt ) override;
282
283 virtual Type GetType() const override;
284 ScColorScaleEntries::iterator begin();
285 ScColorScaleEntries::const_iterator begin() const;
286 ScColorScaleEntries::iterator end();
287 ScColorScaleEntries::const_iterator end() const;
288
289 ScColorScaleEntry* GetEntry(size_t nPos);
290 const ScColorScaleEntry* GetEntry(size_t nPos) const;
291
292 size_t size() const;
293
298 void EnsureSize();
299};
300
302{
303public:
305 ScDataBarFormat(ScDocument* pDoc, const ScDataBarFormat& rFormat);
306 virtual ScColorFormat* Clone(ScDocument* pDoc) const override;
307
308 virtual void SetParent(ScConditionalFormat* pParent) override;
309
310 std::unique_ptr<ScDataBarInfo> GetDataBarInfo(const ScAddress& rAddr) const;
311
312 void SetDataBarData( ScDataBarFormatData* pData );
313 const ScDataBarFormatData* GetDataBarData() const;
314 ScDataBarFormatData* GetDataBarData();
315
316 bool IsEqual(const ScFormatEntry& r, bool bIgnoreSrcPos) const override;
317
318 virtual void UpdateReference( sc::RefUpdateContext& rCxt ) override;
319 virtual void UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt ) override;
320 virtual void UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt ) override;
321 virtual void UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt ) override;
322
323 virtual Type GetType() const override;
324
329 void EnsureSize();
330
331private:
332 double getMin(double nMin, double nMax) const;
333 double getMax(double nMin, double nMax) const;
334
335 std::unique_ptr<ScDataBarFormatData> mpFormatData;
336};
337
339{
346 typedef std::vector<std::unique_ptr<ScColorScaleEntry, o3tl::default_delete<ScColorScaleEntry>>> Entries_t;
349 // the std::pair points to exactly one image
350 // std..pair::second == -1 means no image
351 std::vector<std::pair<ScIconSetType, sal_Int32> > maCustomVector;
352
355 mbShowValue(true),
356 mbReverse(false),
357 mbCustom(false)
358 {}
359
362};
363
365{
366public:
368 ScIconSetFormat(ScDocument* pDoc, const ScIconSetFormat& rFormat);
369
370 virtual ScColorFormat* Clone(ScDocument* pDoc) const override;
371
372 virtual void SetParent(ScConditionalFormat* pParent) override;
373
374 std::unique_ptr<ScIconSetInfo> GetIconSetInfo(const ScAddress& rAddr) const;
375
376 void SetIconSetData( ScIconSetFormatData* pData );
377 const ScIconSetFormatData* GetIconSetData() const;
378 ScIconSetFormatData* GetIconSetData();
379
380 virtual void UpdateReference( sc::RefUpdateContext& rCxt ) override;
381 virtual void UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt ) override;
382 virtual void UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt ) override;
383 virtual void UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt ) override;
384
385 virtual Type GetType() const override;
386
387 static const ScIconSetMap g_IconSetMap[];
388 static const char* getIconSetName( ScIconSetType eType );
389 static sal_Int32 getIconSetElements( ScIconSetType eType );
390 static OUString getIconName(ScIconSetType eType, sal_Int32 nIndex);
391 static BitmapEx& getBitmap(sc::IconSetBitmapMap& rBitmapMap, ScIconSetType eType, sal_Int32 nIndex);
392
393 typedef ScIconSetFormatData::Entries_t::iterator iterator;
394 typedef ScIconSetFormatData::Entries_t::const_iterator const_iterator;
395
396 iterator begin();
397 const_iterator begin() const;
398 iterator end();
399 const_iterator end() const;
400
401 size_t size() const;
402
407 void EnsureSize();
408
409private:
410
411 double GetMinValue() const;
412 double GetMaxValue() const;
413 double CalcValue(double nMin, double nMax, const ScIconSetFormat::const_iterator& itr) const;
414
415 std::unique_ptr<ScIconSetFormatData> mpFormatData;
416};
417
418/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
basegfx::BColor maColor
ScConditionalFormat * mpParent
Definition: colorscale.hxx:242
std::unique_ptr< ScColorFormatCache > mpCache
Definition: colorscale.hxx:250
std::unique_ptr< ScFormulaListener > mpListener
Definition: colorscale.hxx:47
ScColorScaleEntryType meType
Definition: colorscale.hxx:50
ScColorScaleEntryType GetType() const
Definition: colorscale.hxx:76
std::unique_ptr< ScFormulaCell > mpCell
Definition: colorscale.hxx:46
ScConditionalFormat * mpFormat
Definition: colorscale.hxx:48
ScColorScaleEntries maColorScales
Definition: colorscale.hxx:258
std::unique_ptr< ScDataBarFormatData > mpFormatData
Definition: colorscale.hxx:335
std::unique_ptr< ScIconSetFormatData > mpFormatData
Definition: colorscale.hxx:415
ScIconSetFormatData::Entries_t::iterator iterator
Definition: colorscale.hxx:393
ScIconSetFormatData::Entries_t::const_iterator const_iterator
Definition: colorscale.hxx:394
constexpr ::Color COL_BLACK(0x00, 0x00, 0x00)
std::vector< std::unique_ptr< ScColorScaleEntry, o3tl::default_delete< ScColorScaleEntry > > > ScColorScaleEntries
Definition: colorscale.hxx:253
ScIconSetType
Definition: colorscale.hxx:189
@ IconSet_3Arrows
Definition: colorscale.hxx:190
@ IconSet_3TrafficLights1
Definition: colorscale.hxx:193
@ IconSet_4Arrows
Definition: colorscale.hxx:202
@ IconSet_3Symbols2
Definition: colorscale.hxx:197
@ IconSet_3ArrowsGray
Definition: colorscale.hxx:191
@ IconSet_3Symbols
Definition: colorscale.hxx:196
@ IconSet_3Triangles
Definition: colorscale.hxx:200
@ IconSet_4TrafficLights
Definition: colorscale.hxx:206
@ IconSet_5Arrows
Definition: colorscale.hxx:207
@ IconSet_4Rating
Definition: colorscale.hxx:205
@ IconSet_3ColorSmilies
Definition: colorscale.hxx:201
@ IconSet_3Signs
Definition: colorscale.hxx:195
@ IconSet_5Quarters
Definition: colorscale.hxx:210
@ IconSet_5Boxes
Definition: colorscale.hxx:211
@ IconSet_5ArrowsGray
Definition: colorscale.hxx:208
@ IconSet_3TrafficLights2
Definition: colorscale.hxx:194
@ IconSet_4ArrowsGray
Definition: colorscale.hxx:203
@ IconSet_5Ratings
Definition: colorscale.hxx:209
@ IconSet_3Smilies
Definition: colorscale.hxx:198
@ IconSet_4RedToBlack
Definition: colorscale.hxx:204
@ IconSet_3Flags
Definition: colorscale.hxx:192
@ IconSet_3Stars
Definition: colorscale.hxx:199
ScColorScaleEntryType
Definition: colorscale.hxx:32
@ COLORSCALE_MAX
Definition: colorscale.hxx:35
@ COLORSCALE_VALUE
Definition: colorscale.hxx:37
@ COLORSCALE_FORMULA
Definition: colorscale.hxx:39
@ COLORSCALE_PERCENT
Definition: colorscale.hxx:38
@ COLORSCALE_PERCENTILE
Definition: colorscale.hxx:36
@ COLORSCALE_AUTO
Definition: colorscale.hxx:33
@ COLORSCALE_MIN
Definition: colorscale.hxx:34
virtual void SetValue(tools::Long nNew) override
DocumentType eType
AUTOMATIC
std::unique_ptr< sal_Int32[]> pData
size
enumrange< T >::Iterator begin(enumrange< T >)
end
std::map< OUString, BitmapEx > IconSetBitmapMap
Definition: document.hxx:217
css::uno::Reference< css::animations::XAnimationNode > Clone(const css::uno::Reference< css::animations::XAnimationNode > &xSourceNode, const SdPage *pSource=nullptr, const SdPage *pTarget=nullptr)
const char GetValue[]
#define SC_DLLPUBLIC
Definition: scdllapi.h:27
std::vector< double > maValues
Definition: colorscale.hxx:248
Color maAxisColor
Color of the axis if used Default color is black.
Definition: colorscale.hxx:145
std::optional< Color > mxNegativeColor
Specifies the color for negative values.
Definition: colorscale.hxx:140
std::unique_ptr< ScColorScaleEntry, o3tl::default_delete< ScColorScaleEntry > > mpLowerLimit
Definition: colorscale.hxx:185
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
double mnMinLength
Minimal length of a databar in percent of cell length Value has to be in the range [0,...
Definition: colorscale.hxx:172
double mnMaxLength
Maximal length of a databar in percent of cell length Value has to be in the range (0,...
Definition: colorscale.hxx:177
ScDataBarFormatData(const ScDataBarFormatData &r)
Definition: colorscale.hxx:109
Color maPositiveColor
Color for all Positive Values and if mbNeg == false also for negative ones.
Definition: colorscale.hxx:134
bool mbNeg
Use different color for negative values.
Definition: colorscale.hxx:159
bool mbGradient
Paint the bars with gradient.
Definition: colorscale.hxx:152
bool mbOnlyBar
If TRUE we only show the bar and not the value.
Definition: colorscale.hxx:182
std::unique_ptr< ScColorScaleEntry, o3tl::default_delete< ScColorScaleEntry > > mpUpperLimit
Definition: colorscale.hxx:184
ScIconSetFormatData(ScIconSetType eType=IconSet_3Arrows)
Definition: colorscale.hxx:353
std::vector< std::unique_ptr< ScColorScaleEntry, o3tl::default_delete< ScColorScaleEntry > > > Entries_t
Definition: colorscale.hxx:346
ScIconSetType eIconSetType
Definition: colorscale.hxx:340
bool mbReverse
Specifies whether the icons should be shown in reverse order.
Definition: colorscale.hxx:345
std::vector< std::pair< ScIconSetType, sal_Int32 > > maCustomVector
Definition: colorscale.hxx:351
ScIconSetFormatData & operator=(ScIconSetFormatData const &)=delete
ScIconSetType eType
Definition: colorscale.hxx:216
const char * pName
Definition: colorscale.hxx:215
sal_Int32 nElements
Definition: colorscale.hxx:217
Context for reference update during shifting, moving or copying of cell ranges.
RedlineType meType