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

Generated by: LCOV version 1.10