LCOV - code coverage report
Current view: top level - sc/source/filter/inc - condformatbuffer.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 19 19 100.0 %
Date: 2015-06-13 12:38:46 Functions: 26 27 96.3 %
Legend: Lines: hit not hit

          Line data    Source code
       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 "formulaparser.hxx"
      24             : #include "worksheethelper.hxx"
      25             : #include <tools/color.hxx>
      26             : #include "rangelst.hxx"
      27             : 
      28             : #include <memory>
      29             : 
      30             : #include <boost/ptr_container/ptr_vector.hpp>
      31             : 
      32             : class ScColorScaleFormat;
      33             : class ScDataBarFormat;
      34             : struct ScDataBarFormatData;
      35             : class ScConditionalFormat;
      36             : class ScIconSetFormat;
      37             : class ScFormatEntry;
      38             : struct ScIconSetFormatData;
      39             : 
      40             : namespace oox {
      41             : namespace xls {
      42             : 
      43             : class CondFormat;
      44             : 
      45             : /** Model for a single rule in a conditional formatting. */
      46          67 : struct CondFormatRuleModel
      47             : {
      48             :     typedef ::std::vector< ApiTokenSequence > ApiTokenSequenceVector;
      49             : 
      50             :     ApiTokenSequenceVector maFormulas;      /// Formulas for rule conditions.
      51             :     OUString     maText;             /// Text for 'contains' rules.
      52             :     sal_Int32           mnPriority;         /// Priority of this rule.
      53             :     sal_Int32           mnType;             /// Type of the rule.
      54             :     sal_Int32           mnOperator;         /// In cell-is rules: Comparison operator.
      55             :     sal_Int32           mnTimePeriod;       /// In time-period rules: Type of time period.
      56             :     sal_Int32           mnRank;             /// In top-10 rules: True = bottom, false = top.
      57             :     sal_Int32           mnStdDev;           /// In average rules: Number of std deviations.
      58             :     sal_Int32           mnDxfId;            /// Differential formatting identifier.
      59             :     bool                mbStopIfTrue;       /// True = stop evaluating rules, if this rule is true.
      60             :     bool                mbBottom;           /// In top-10 rules: True = bottom, false = top.
      61             :     bool                mbPercent;          /// In top-10 rules: True = percent, false = rank.
      62             :     bool                mbAboveAverage;     /// In average rules: True = above average, false = below.
      63             :     bool                mbEqualAverage;     /// In average rules: True = include average, false = exclude.
      64             : 
      65             :     explicit            CondFormatRuleModel();
      66             : 
      67             :     /** Sets the passed BIFF operator for condition type cellIs. */
      68             :     void                setBiffOperator( sal_Int32 nOperator );
      69             : 
      70             :     /** Sets the passed BIFF12 text comparison type and operator. */
      71             :     void                setBiff12TextType( sal_Int32 nOperator );
      72             : };
      73             : 
      74         352 : struct ColorScaleRuleModelEntry
      75             : {
      76             :     ::Color maColor;
      77             :     double mnVal;
      78             : 
      79             :     bool mbMin;
      80             :     bool mbMax;
      81             :     bool mbPercent;
      82             :     bool mbPercentile;
      83             :     bool mbNum;
      84             :     OUString maFormula;
      85             : 
      86         100 :     ColorScaleRuleModelEntry():
      87             :         maColor(),
      88             :         mnVal(0),
      89             :         mbMin(false),
      90             :         mbMax(false),
      91             :         mbPercent(false),
      92             :         mbPercentile(false),
      93         100 :         mbNum(false) {}
      94             : };
      95             : 
      96          38 : class ColorScaleRule : public WorksheetHelper
      97             : {
      98             : public:
      99             :     ColorScaleRule( const CondFormat& rFormat );
     100             : 
     101             :     void importCfvo( const AttributeList& rAttribs );
     102             :     void importColor( const AttributeList& rAttribs );
     103             : 
     104             :     void AddEntries( ScColorScaleFormat* pFormat, ScDocument* pDoc, const ScAddress& rAddr );
     105             : 
     106             : private:
     107             :     std::vector< ColorScaleRuleModelEntry > maColorScaleRuleEntries;
     108             : 
     109             :     sal_uInt32 mnCfvo;
     110             :     sal_uInt32 mnCol;
     111             : };
     112             : 
     113          34 : class DataBarRule : public WorksheetHelper
     114             : {
     115             : public:
     116             :     DataBarRule( const CondFormat& rFormat );
     117             :     void importCfvo( const AttributeList& rAttribs );
     118             :     void importColor( const AttributeList& rAttribs );
     119             :     void importAttribs( const AttributeList& rAttribs );
     120             : 
     121             :     void SetData( ScDataBarFormat* pFormat, ScDocument* pDoc, const ScAddress& rAddr );
     122             : 
     123          17 :     ScDataBarFormatData* getDataBarFormatData() { return mxFormat.get(); }
     124             : 
     125             : private:
     126             :     std::unique_ptr<ScDataBarFormatData> mxFormat;
     127             : 
     128             :     std::unique_ptr<ColorScaleRuleModelEntry> mpUpperLimit;
     129             :     std::unique_ptr<ColorScaleRuleModelEntry> mpLowerLimit;
     130             : };
     131             : 
     132          10 : class IconSetRule : public WorksheetHelper
     133             : {
     134             : public:
     135             :     IconSetRule( const WorksheetHelper& rParent );
     136             :     void importCfvo( const AttributeList& rAttribs );
     137             :     void importAttribs( const AttributeList& rAttribs );
     138             :     void importFormula(const OUString& rFormula);
     139             :     void importIcon(const AttributeList& rAttribs);
     140             : 
     141             :     void SetData( ScIconSetFormat* pFormat, ScDocument* pDoc, const ScAddress& rAddr );
     142             : 
     143             : private:
     144             :     std::vector< ColorScaleRuleModelEntry > maEntries;
     145             :     std::unique_ptr<ScIconSetFormatData> mxFormatData;
     146             :     OUString maIconSetType;
     147             :     bool mbCustom;
     148             : };
     149             : 
     150             : /** Represents a single rule in a conditional formatting. */
     151         134 : class CondFormatRule : public WorksheetHelper
     152             : {
     153             : public:
     154             :     explicit            CondFormatRule( const CondFormat& rCondFormat, ScConditionalFormat* pFormat );
     155             : 
     156             :     /** Imports rule settings from the cfRule element. */
     157             :     void                importCfRule( const AttributeList& rAttribs );
     158             :     /** Appends a new condition formula string. */
     159             :     void                appendFormula( const OUString& rFormula );
     160             : 
     161             :     /** Imports rule settings from a CFRULE record. */
     162             :     void                importCfRule( SequenceInputStream& rStrm );
     163             : 
     164             :     /** Creates a conditional formatting rule in the Calc document. */
     165             :     void                finalizeImport();
     166             : 
     167             :     /** Returns the priority of this rule. */
     168         134 :     inline sal_Int32    getPriority() const { return maModel.mnPriority; }
     169             : 
     170             :     ColorScaleRule*     getColorScale();
     171             :     DataBarRule*        getDataBar();
     172             :     IconSetRule*            getIconSet();
     173             : 
     174             : private:
     175             :     const CondFormat&   mrCondFormat;
     176             :     CondFormatRuleModel maModel;
     177             :     ScConditionalFormat* mpFormat;
     178             :     std::unique_ptr<ColorScaleRule> mpColor;
     179             :     std::unique_ptr<DataBarRule> mpDataBar;
     180             :     std::unique_ptr<IconSetRule> mpIconSet;
     181             : };
     182             : 
     183             : typedef std::shared_ptr< CondFormatRule > CondFormatRuleRef;
     184             : 
     185             : /** Model for a conditional formatting object. */
     186          67 : struct CondFormatModel
     187             : {
     188             :     ApiCellRangeList    maRanges;           /// Cell ranges for this conditional format.
     189             :     bool                mbPivot;            /// Conditional formatting belongs to pivot table.
     190             : 
     191             :     explicit            CondFormatModel();
     192             : };
     193             : 
     194             : /** Represents a conditional formatting object with a list of affected cell ranges. */
     195         134 : class CondFormat : public WorksheetHelper
     196             : {
     197             : public:
     198             :     explicit            CondFormat( const WorksheetHelper& rHelper );
     199             : 
     200             :     /** Imports settings from the conditionalFormatting element. */
     201             :     void                importConditionalFormatting( const AttributeList& rAttribs );
     202             :     /** Imports a conditional formatting rule from the cfRule element. */
     203             :     CondFormatRuleRef   importCfRule( const AttributeList& rAttribs );
     204             : 
     205             :     /** Imports settings from the CONDFORMATTING record. */
     206             :     void                importCondFormatting( SequenceInputStream& rStrm );
     207             :     /** Imports a conditional formatting rule from the CFRULE record. */
     208             :     void                importCfRule( SequenceInputStream& rStrm );
     209             : 
     210             :     /** Creates the conditional formatting in the Calc document. */
     211             :     void                finalizeImport();
     212             : 
     213             :     /** Returns the cell ranges this conditional formatting belongs to. */
     214          78 :     inline const ApiCellRangeList& getRanges() const { return maModel.maRanges; }
     215             : 
     216          67 :     void                setReadyForFinalize() { mbReadyForFinalize = true; }
     217             : private:
     218             :     CondFormatRuleRef   createRule();
     219             :     void                insertRule( CondFormatRuleRef xRule );
     220             : 
     221             : private:
     222             :     typedef RefMap< sal_Int32, CondFormatRule > CondFormatRuleMap;
     223             : 
     224             :     CondFormatModel     maModel;            /// Model of this conditional formatting.
     225             :     CondFormatRuleMap   maRules;            /// Maps formatting rules by priority.
     226             :     ScConditionalFormat* mpFormat;
     227             :     bool                mbReadyForFinalize;
     228             : };
     229             : 
     230          85 : struct ExCfRuleModel
     231             : {
     232          85 :     ExCfRuleModel() : mbGradient( false ), mnAxisColor( UNSIGNED_RGB_TRANSPARENT ), mnNegativeColor( UNSIGNED_RGB_TRANSPARENT ), mbIsLower( true ) {}
     233             :     // DataBar
     234             :     bool mbGradient;
     235             :     OUString maAxisPosition;
     236             :     // AxisColor
     237             :     ::Color mnAxisColor;
     238             :     // NegativeFillColor
     239             :     ::Color mnNegativeColor;
     240             :     // Cfvo
     241             :     bool mbIsLower;
     242             :     OUString maColorScaleType;
     243             : };
     244             : 
     245         170 : class ExtCfDataBarRule : public WorksheetHelper
     246             : {
     247             :     enum RuleType
     248             :     {
     249             :         DATABAR,
     250             :         NEGATIVEFILLCOLOR,
     251             :         AXISCOLOR,
     252             :         CFVO,
     253             :         UNKNOWN,
     254             :     };
     255             :     ExCfRuleModel maModel;
     256             :     RuleType mnRuleType;
     257             :     ScDataBarFormatData* mpTarget;
     258             : public:
     259             : 
     260             :     ExtCfDataBarRule(ScDataBarFormatData* pTarget, WorksheetHelper& rParent);
     261             :     void finalizeImport();
     262             :     void importDataBar(  const AttributeList& rAttribs );
     263             :     void importNegativeFillColor(  const AttributeList& rAttribs );
     264             :     void importAxisColor(  const AttributeList& rAttribs );
     265             :     void importCfvo(  const AttributeList& rAttribs );
     266          34 :     ExCfRuleModel& getModel() { return maModel; }
     267             : };
     268             : 
     269             : class ExtCfCondFormat
     270             : {
     271             : public:
     272             :     ExtCfCondFormat(const ScRangeList& aRange, boost::ptr_vector<ScFormatEntry>& rEntries);
     273             :     ~ExtCfCondFormat();
     274             : 
     275             :     const ScRangeList& getRange();
     276             :     const boost::ptr_vector<ScFormatEntry>& getEntries();
     277             : 
     278             : private:
     279             :     boost::ptr_vector<ScFormatEntry> maEntries;
     280             :     ScRangeList maRange;
     281             : };
     282             : 
     283             : typedef std::shared_ptr< CondFormat > CondFormatRef;
     284             : typedef std::shared_ptr< ExtCfDataBarRule > ExtCfDataBarRuleRef;
     285             : 
     286         269 : class CondFormatBuffer : public WorksheetHelper
     287             : {
     288             : public:
     289             :     explicit            CondFormatBuffer( const WorksheetHelper& rHelper );
     290             : 
     291             :     /** Imports settings from the conditionalFormatting element. */
     292             :     CondFormatRef       importConditionalFormatting( const AttributeList& rAttribs );
     293             :     /** Imports settings from the CONDFORMATTING record. */
     294             :     CondFormatRef       importCondFormatting( SequenceInputStream& rStrm );
     295             :     ExtCfDataBarRuleRef createExtCfDataBarRule(ScDataBarFormatData* pTarget);
     296             :     boost::ptr_vector<ExtCfCondFormat>& importExtCondFormat();
     297             : 
     298             :     /** Converts an OOXML condition operator token to the API constant. */
     299             :     static sal_Int32    convertToApiOperator( sal_Int32 nToken );
     300             :     static sal_Int32    convertToInternalOperator( sal_Int32 nToken );
     301             :     void                finalizeImport();
     302             : private:
     303             :     CondFormatRef       createCondFormat();
     304             : 
     305             : private:
     306             :     typedef RefVector< CondFormat > CondFormatVec;
     307             :     typedef RefVector< ExtCfDataBarRule > ExtCfDataBarRuleVec;
     308             :     CondFormatVec       maCondFormats;      /// All conditional formatting in a sheet.
     309             :     ExtCfDataBarRuleVec        maCfRules;          /// All external conditional formatting rules in a sheet.
     310             :     boost::ptr_vector<ExtCfCondFormat> maExtCondFormats;
     311             : };
     312             : 
     313             : } // namespace xls
     314             : } // namespace oox
     315             : 
     316             : #endif
     317             : 
     318             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11