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 <colorscale.hxx>
26 #include <conditio.hxx>
27 #include <rangelst.hxx>
28 
29 #include <memory>
30 #include <vector>
31 
32 class ScColorScaleFormat;
33 class ScDataBarFormat;
34 struct ScDataBarFormatData;
35 class ScIconSetFormat;
36 struct ScIconSetFormatData;
37 
38 namespace oox { class AttributeList; }
39 
40 namespace oox::xls {
41 
42 class CondFormat;
43 
46 {
47  typedef ::std::vector< ApiTokenSequence > ApiTokenSequenceVector;
48 
49  ApiTokenSequenceVector maFormulas;
50  OUString maText;
51  sal_Int32 mnPriority;
52  sal_Int32 mnType;
53  sal_Int32 mnOperator;
54  sal_Int32 mnTimePeriod;
55  sal_Int32 mnRank;
56  sal_Int32 mnStdDev;
57  sal_Int32 mnDxfId;
58  bool mbStopIfTrue;
59  bool mbBottom;
60  bool mbPercent;
63 
64  explicit CondFormatRuleModel();
65 
67  void setBiffOperator( sal_Int32 nOperator );
68 
70  void setBiff12TextType( sal_Int32 nOperator );
71 };
72 
74 {
76  double mnVal;
77 
78  bool mbMin;
79  bool mbMax;
80  bool mbPercent;
82  bool mbNum;
83  OUString maFormula;
84 
86  maColor(),
87  mnVal(0),
88  mbMin(false),
89  mbMax(false),
90  mbPercent(false),
91  mbPercentile(false),
92  mbNum(false) {}
93 };
94 
96 {
97 public:
98  ColorScaleRule( const CondFormat& rFormat );
99 
100  void importCfvo( const AttributeList& rAttribs );
101  void importColor( const AttributeList& rAttribs );
102 
103  void AddEntries( ScColorScaleFormat* pFormat, ScDocument* pDoc, const ScAddress& rAddr );
104 
105 private:
106  std::vector< ColorScaleRuleModelEntry > maColorScaleRuleEntries;
107 
108  sal_uInt32 mnCfvo;
109  sal_uInt32 mnCol;
110 };
111 
113 {
114 public:
115  DataBarRule( const CondFormat& rFormat );
116  void importCfvo( const AttributeList& rAttribs );
117  void importColor( const AttributeList& rAttribs );
118  void importAttribs( const AttributeList& rAttribs );
119 
120  void SetData( ScDataBarFormat* pFormat, ScDocument* pDoc, const ScAddress& rAddr );
121 
123 
124 private:
125  std::unique_ptr<ScDataBarFormatData> mxFormat;
126 
127  std::unique_ptr<ColorScaleRuleModelEntry> mpUpperLimit;
128  std::unique_ptr<ColorScaleRuleModelEntry> mpLowerLimit;
129 };
130 
132 {
133 public:
134  IconSetRule( const WorksheetHelper& rParent );
135  void importCfvo( const AttributeList& rAttribs );
136  void importAttribs( const AttributeList& rAttribs );
137  void importFormula(const OUString& rFormula);
138  void importIcon(const AttributeList& rAttribs);
139 
140  void SetData( ScIconSetFormat* pFormat, ScDocument* pDoc, const ScAddress& rAddr );
141 
142 private:
143  std::vector< ColorScaleRuleModelEntry > maEntries;
144  std::unique_ptr<ScIconSetFormatData> mxFormatData;
145  OUString maIconSetType;
146  bool mbCustom;
147 };
148 
151 {
152 public:
153  explicit CondFormatRule( const CondFormat& rCondFormat, ScConditionalFormat* pFormat );
154 
156  void importCfRule( const AttributeList& rAttribs );
158  void appendFormula( const OUString& rFormula );
159 
162 
164  void setFormatEntry(sal_Int32 nPriority, ScFormatEntry* pEntry);
165 
167  void finalizeImport();
168 
170  sal_Int32 getPriority() const { return maModel.mnPriority; }
171 
175 
176 private:
181  std::unique_ptr<ColorScaleRule> mpColor;
182  std::unique_ptr<DataBarRule> mpDataBar;
183  std::unique_ptr<IconSetRule> mpIconSet;
184 };
185 
186 typedef std::shared_ptr< CondFormatRule > CondFormatRuleRef;
187 
190 {
192  bool mbPivot;
193 
194  explicit CondFormatModel();
195 };
196 
197 class CondFormatBuffer;
198 
201 {
202 friend class CondFormatBuffer;
203 public:
204  explicit CondFormat( const WorksheetHelper& rHelper );
205 
207  void importConditionalFormatting( const AttributeList& rAttribs );
209  CondFormatRuleRef importCfRule( const AttributeList& rAttribs );
210 
214  void importCfRule( SequenceInputStream& rStrm );
215 
217  void finalizeImport();
218 
220  const ScRangeList& getRanges() const { return maModel.maRanges; }
221 
223 private:
224  CondFormatRuleRef createRule();
225  void insertRule( CondFormatRuleRef const & xRule );
226 
227 private:
229 
231  CondFormatRuleMap maRules;
234 };
235 
237 {
239  // AxisColor
241  // NegativeFillColor
243  OUString maAxisPosition; // DataBar
244  OUString maColorScaleType; // Cfvo
245  bool mbGradient; // DataBar
246  bool mbIsLower; // Cfvo
247 };
248 
250 {
251  enum RuleType
252  {
258  };
262 public:
263 
264  ExtCfDataBarRule(ScDataBarFormatData* pTarget, const WorksheetHelper& rParent);
265  void finalizeImport();
266  void importDataBar( const AttributeList& rAttribs );
267  void importNegativeFillColor( const AttributeList& rAttribs );
268  void importAxisColor( const AttributeList& rAttribs );
269  void importCfvo( const AttributeList& rAttribs );
271 };
272 
274 {
275 public:
276  ExtCfCondFormat(const ScRangeList& aRange, std::vector< std::unique_ptr<ScFormatEntry> >& rEntries,
277  const std::vector<sal_Int32>* pPriorities = nullptr);
279 
280  const ScRangeList& getRange() const;
281  const std::vector< std::unique_ptr<ScFormatEntry> >& getEntries() const;
282  const std::vector<sal_Int32>& getPriorities() const { return maPriorities; }
283 
284 private:
285  std::vector< std::unique_ptr<ScFormatEntry> > maEntries;
286  std::vector<sal_Int32> maPriorities;
288 };
289 
290 typedef std::shared_ptr< CondFormat > CondFormatRef;
291 typedef std::shared_ptr< ExtCfDataBarRule > ExtCfDataBarRuleRef;
292 
294 {
295 public:
296  explicit CondFormatBuffer( const WorksheetHelper& rHelper );
297 
299  CondFormatRef importConditionalFormatting( const AttributeList& rAttribs );
302  ExtCfDataBarRuleRef createExtCfDataBarRule(ScDataBarFormatData* pTarget);
303  std::vector< std::unique_ptr<ExtCfCondFormat> >& importExtCondFormat();
304 
306  static sal_Int32 convertToApiOperator( sal_Int32 nToken );
307  static ScConditionMode convertToInternalOperator( sal_Int32 nToken );
308  void finalizeImport();
309 private:
310  CondFormatRef createCondFormat();
311 
312 private:
315  CondFormatVec maCondFormats;
316  ExtCfDataBarRuleVec maCfRules;
317  std::vector< std::unique_ptr<ExtCfCondFormat> > maExtCondFormats;
318  sal_Int32 mnNonPrioritizedRuleNextPriority = 1048576;
319 };
320 
321 } // namespace oox::xls
322 
323 #endif
324 
325 /* 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:399
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