LibreOffice Module sc (master)  1
condformatbuffer.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  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #ifndef INCLUDED_SC_SOURCE_FILTER_INC_CONDFORMATBUFFER_HXX
21 #define INCLUDED_SC_SOURCE_FILTER_INC_CONDFORMATBUFFER_HXX
22 
23 #include "worksheethelper.hxx"
24 #include <tools/color.hxx>
25 #include <conditio.hxx>
26 #include <rangelst.hxx>
27 
28 #include <memory>
29 #include <vector>
30 
31 class ScColorScaleFormat;
32 class ScDataBarFormat;
33 struct ScDataBarFormatData;
34 class ScIconSetFormat;
35 struct ScIconSetFormatData;
36 
37 namespace oox { class AttributeList; }
38 
39 namespace oox::xls {
40 
41 class CondFormat;
42 
45 {
46  typedef ::std::vector< ApiTokenSequence > ApiTokenSequenceVector;
47 
48  ApiTokenSequenceVector maFormulas;
49  OUString maText;
50  sal_Int32 mnPriority;
51  sal_Int32 mnType;
52  sal_Int32 mnOperator;
53  sal_Int32 mnTimePeriod;
54  sal_Int32 mnRank;
55  sal_Int32 mnStdDev;
56  sal_Int32 mnDxfId;
57  bool mbStopIfTrue;
58  bool mbBottom;
59  bool mbPercent;
62 
63  explicit CondFormatRuleModel();
64 
66  void setBiffOperator( sal_Int32 nOperator );
67 
69  void setBiff12TextType( sal_Int32 nOperator );
70 };
71 
73 {
75  double mnVal;
76 
77  bool mbMin;
78  bool mbMax;
79  bool mbPercent;
81  bool mbNum;
82  OUString maFormula;
83 
85  maColor(),
86  mnVal(0),
87  mbMin(false),
88  mbMax(false),
89  mbPercent(false),
90  mbPercentile(false),
91  mbNum(false) {}
92 };
93 
95 {
96 public:
97  ColorScaleRule( const CondFormat& rFormat );
98 
99  void importCfvo( const AttributeList& rAttribs );
100  void importColor( const AttributeList& rAttribs );
101 
102  void AddEntries( ScColorScaleFormat* pFormat, ScDocument* pDoc, const ScAddress& rAddr );
103 
104 private:
105  std::vector< ColorScaleRuleModelEntry > maColorScaleRuleEntries;
106 
107  sal_uInt32 mnCfvo;
108  sal_uInt32 mnCol;
109 };
110 
112 {
113 public:
114  DataBarRule( const CondFormat& rFormat );
115  void importCfvo( const AttributeList& rAttribs );
116  void importColor( const AttributeList& rAttribs );
117  void importAttribs( const AttributeList& rAttribs );
118 
119  void SetData( ScDataBarFormat* pFormat, ScDocument* pDoc, const ScAddress& rAddr );
120 
122 
123 private:
124  std::unique_ptr<ScDataBarFormatData> mxFormat;
125 
126  std::unique_ptr<ColorScaleRuleModelEntry> mpUpperLimit;
127  std::unique_ptr<ColorScaleRuleModelEntry> mpLowerLimit;
128 };
129 
131 {
132 public:
133  IconSetRule( const WorksheetHelper& rParent );
134  void importCfvo( const AttributeList& rAttribs );
135  void importAttribs( const AttributeList& rAttribs );
136  void importFormula(const OUString& rFormula);
137  void importIcon(const AttributeList& rAttribs);
138 
139  void SetData( ScIconSetFormat* pFormat, ScDocument* pDoc, const ScAddress& rAddr );
140 
141 private:
142  std::vector< ColorScaleRuleModelEntry > maEntries;
143  std::unique_ptr<ScIconSetFormatData> mxFormatData;
144  OUString maIconSetType;
145  bool mbCustom;
146 };
147 
150 {
151 public:
152  explicit CondFormatRule( const CondFormat& rCondFormat, ScConditionalFormat* pFormat );
153 
155  void importCfRule( const AttributeList& rAttribs );
157  void appendFormula( const OUString& rFormula );
158 
161 
163  void setFormatEntry(sal_Int32 nPriority, ScFormatEntry* pEntry);
164 
166  void finalizeImport();
167 
169  sal_Int32 getPriority() const { return maModel.mnPriority; }
170 
174 
175 private:
180  std::unique_ptr<ColorScaleRule> mpColor;
181  std::unique_ptr<DataBarRule> mpDataBar;
182  std::unique_ptr<IconSetRule> mpIconSet;
183 };
184 
185 typedef std::shared_ptr< CondFormatRule > CondFormatRuleRef;
186 
189 {
191  bool mbPivot;
192 
193  explicit CondFormatModel();
194 };
195 
196 class CondFormatBuffer;
197 
200 {
201 friend class CondFormatBuffer;
202 public:
203  explicit CondFormat( const WorksheetHelper& rHelper );
204 
206  void importConditionalFormatting( const AttributeList& rAttribs );
208  CondFormatRuleRef importCfRule( const AttributeList& rAttribs );
209 
213  void importCfRule( SequenceInputStream& rStrm );
214 
216  void finalizeImport();
217 
219  const ScRangeList& getRanges() const { return maModel.maRanges; }
220 
222 private:
223  CondFormatRuleRef createRule();
224  void insertRule( CondFormatRuleRef const & xRule );
225 
226 private:
228 
230  CondFormatRuleMap maRules;
233 };
234 
236 {
238  // AxisColor
240  // NegativeFillColor
242  OUString maAxisPosition; // DataBar
243  OUString maColorScaleType; // Cfvo
244  bool mbGradient; // DataBar
245  bool mbIsLower; // Cfvo
246 };
247 
249 {
250  enum RuleType
251  {
257  };
261 public:
262 
263  ExtCfDataBarRule(ScDataBarFormatData* pTarget, const WorksheetHelper& rParent);
264  void finalizeImport();
265  void importDataBar( const AttributeList& rAttribs );
266  void importNegativeFillColor( const AttributeList& rAttribs );
267  void importAxisColor( const AttributeList& rAttribs );
268  void importCfvo( const AttributeList& rAttribs );
270 };
271 
273 {
274 public:
275  ExtCfCondFormat(const ScRangeList& aRange, std::vector< std::unique_ptr<ScFormatEntry> >& rEntries,
276  const std::vector<sal_Int32>* pPriorities = nullptr);
278 
279  const ScRangeList& getRange() const;
280  const std::vector< std::unique_ptr<ScFormatEntry> >& getEntries() const;
281  const std::vector<sal_Int32>& getPriorities() const { return maPriorities; }
282 
283 private:
284  std::vector< std::unique_ptr<ScFormatEntry> > maEntries;
285  std::vector<sal_Int32> maPriorities;
287 };
288 
289 typedef std::shared_ptr< CondFormat > CondFormatRef;
290 typedef std::shared_ptr< ExtCfDataBarRule > ExtCfDataBarRuleRef;
291 
293 {
294 public:
295  explicit CondFormatBuffer( const WorksheetHelper& rHelper );
296 
298  CondFormatRef importConditionalFormatting( const AttributeList& rAttribs );
301  ExtCfDataBarRuleRef createExtCfDataBarRule(ScDataBarFormatData* pTarget);
302  std::vector< std::unique_ptr<ExtCfCondFormat> >& importExtCondFormat();
303 
305  static sal_Int32 convertToApiOperator( sal_Int32 nToken );
306  static ScConditionMode convertToInternalOperator( sal_Int32 nToken );
307  void finalizeImport();
308 private:
309  CondFormatRef createCondFormat();
310 
311 private:
314  CondFormatVec maCondFormats;
315  ExtCfDataBarRuleVec maCfRules;
316  std::vector< std::unique_ptr<ExtCfCondFormat> > maExtCondFormats;
317  sal_Int32 mnNonPrioritizedRuleNextPriority = 1048576;
318 };
319 
320 } // namespace oox::xls
321 
322 #endif
323 
324 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void setBiffOperator(sal_Int32 nOperator)
Sets the passed BIFF operator for condition type cellIs.
CondFormatBuffer(const WorksheetHelper &rHelper)
CondFormatModel()
Conditional formatting belongs to pivot table.
std::unique_ptr< ScIconSetFormatData > mxFormatData
RefMap< sal_Int32, CondFormatRule > CondFormatRuleMap
CondFormatRef importConditionalFormatting(const AttributeList &rAttribs)
Imports settings from the conditionalFormatting element.
ColorScaleRule * getColorScale()
void importIcon(const AttributeList &rAttribs)
static sal_Int32 convertToApiOperator(sal_Int32 nToken)
Converts an OOXML condition operator token to the API constant.
bool mbBottom
True = stop evaluating rules, if this rule is true.
void importColor(const AttributeList &rAttribs)
std::vector< sal_Int32 > maPriorities
sal_Int32 mnStdDev
In top-10 rules: True = bottom, false = top.
sal_Int32 mnRank
In time-period rules: Type of time period.
std::vector< std::unique_ptr< ExtCfCondFormat > > maExtCondFormats
All external conditional formatting rules in a sheet.
ScDataBarFormatData * getDataBarFormatData()
OUString maText
Formulas for rule conditions.
const std::vector< sal_Int32 > & getPriorities() const
void importCondFormatting(SequenceInputStream &rStrm)
Imports settings from the CONDFORMATTING record.
const sal_uInt32 UNSIGNED_RGB_TRANSPARENT
void importConditionalFormatting(const AttributeList &rAttribs)
Imports settings from the conditionalFormatting element.
IconSetRule(const WorksheetHelper &rParent)
std::unique_ptr< ScDataBarFormatData > mxFormat
void finalizeImport()
Creates a conditional formatting rule in the Calc document.
ApiTokenSequenceVector maFormulas
void importCfvo(const AttributeList &rAttribs)
const CondFormat & mrCondFormat
void finalizeImport()
Creates the conditional formatting in the Calc document.
bool mbEqualAverage
In average rules: True = above average, false = below.
sal_Int32 mnTimePeriod
In cell-is rules: Comparison operator.
void setBiff12TextType(sal_Int32 nOperator)
Sets the passed BIFF12 text comparison type and operator.
std::unique_ptr< IconSetRule > mpIconSet
std::vector< std::unique_ptr< ExtCfCondFormat > > & importExtCondFormat()
sal_Int32 mnPriority
Text for 'contains' rules.
Model for a single rule in a conditional formatting.
CondFormatRuleModel()
In average rules: True = include average, false = exclude.
void AddEntries(ScColorScaleFormat *pFormat, ScDocument *pDoc, const ScAddress &rAddr)
ScConditionMode
Definition: conditio.hxx:61
Represents a conditional formatting object with a list of affected cell ranges.
ExtCfDataBarRuleVec maCfRules
All conditional formatting in a sheet.
sal_Int32 mnType
Priority of this rule.
bool mbPercent
In top-10 rules: True = bottom, false = top.
void insertRule(CondFormatRuleRef const &xRule)
void importColor(const AttributeList &rAttribs)
std::unique_ptr< ColorScaleRuleModelEntry > mpUpperLimit
std::unique_ptr< ColorScaleRule > mpColor
ExtCfCondFormat(const ScRangeList &aRange, std::vector< std::unique_ptr< ScFormatEntry > > &rEntries, const std::vector< sal_Int32 > *pPriorities=nullptr)
CondFormatRuleMap maRules
Model of this conditional formatting.
std::shared_ptr< CondFormatRule > CondFormatRuleRef
std::vector< ColorScaleRuleModelEntry > maColorScaleRuleEntries
bool mbStopIfTrue
Differential formatting identifier.
RefVector< CondFormat > CondFormatVec
const ScRangeList & getRanges() const
Returns the cell ranges this conditional formatting belongs to.
Shared formula definition.
ExtCfDataBarRule(ScDataBarFormatData *pTarget, const WorksheetHelper &rParent)
std::shared_ptr< CondFormat > CondFormatRef
void importNegativeFillColor(const AttributeList &rAttribs)
ExtCfDataBarRuleRef createExtCfDataBarRule(ScDataBarFormatData *pTarget)
void importAttribs(const AttributeList &rAttribs)
static ScConditionMode convertToInternalOperator(sal_Int32 nToken)
bool mbPivot
Cell ranges for this conditional format.
sal_Int32 mnDxfId
In average rules: Number of std deviations.
CondFormatRule(const CondFormat &rCondFormat, ScConditionalFormat *pFormat)
void importAttribs(const AttributeList &rAttribs)
Model for a conditional formatting object.
DefTokenId nToken
Definition: qproform.cxx:400
CondFormatRuleRef createRule()
::std::vector< ApiTokenSequence > ApiTokenSequenceVector
ScDataBarFormatData * mpTarget
const ScRangeList & getRange() const
void importCfvo(const AttributeList &rAttribs)
CondFormatRuleModel maModel
void appendFormula(const OUString &rFormula)
Appends a new condition formula string.
ColorScaleRule(const CondFormat &rFormat)
bool mbAboveAverage
In top-10 rules: True = percent, false = rank.
ScConditionalFormat * mpFormat
RefVector< ExtCfDataBarRule > ExtCfDataBarRuleVec
void importCfRule(const AttributeList &rAttribs)
Imports rule settings from the cfRule element.
std::unique_ptr< ColorScaleRuleModelEntry > mpLowerLimit
const std::vector< std::unique_ptr< ScFormatEntry > > & getEntries() const
Represents a single rule in a conditional formatting.
void SetData(ScDataBarFormat *pFormat, ScDocument *pDoc, const ScAddress &rAddr)
std::unique_ptr< DataBarRule > mpDataBar
CondFormat(const WorksheetHelper &rHelper)
void importCfvo(const AttributeList &rAttribs)
std::shared_ptr< ExtCfDataBarRule > ExtCfDataBarRuleRef
CondFormatRuleRef importCfRule(const AttributeList &rAttribs)
Imports a conditional formatting rule from the cfRule element.
sal_Int32 mnOperator
Type of the rule.
void setFormatEntry(sal_Int32 nPriority, ScFormatEntry *pEntry)
Directly set a ScFormatEntry with a priority ready for finalizeImport().
void importCfvo(const AttributeList &rAttribs)
void importFormula(const OUString &rFormula)
CondFormatRef importCondFormatting(SequenceInputStream &rStrm)
Imports settings from the CONDFORMATTING record.
ScConditionalFormat * mpFormat
Maps formatting rules by priority.
std::vector< std::unique_ptr< ScFormatEntry > > maEntries
void importAxisColor(const AttributeList &rAttribs)
void SvStream & rStrm
DataBarRule(const CondFormat &rFormat)
void SetData(ScIconSetFormat *pFormat, ScDocument *pDoc, const ScAddress &rAddr)
sal_Int32 getPriority() const
Returns the priority of this rule.
void importDataBar(const AttributeList &rAttribs)
std::vector< ColorScaleRuleModelEntry > maEntries