LCOV - code coverage report
Current view: top level - libreoffice/sc/source/filter/inc - condformatbuffer.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 7 14 50.0 %
Date: 2012-12-27 Functions: 9 20 45.0 %
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 OOX_XLS_CONDFORMATBUFFER_HXX
      21             : #define OOX_XLS_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             : // ============================================================================
      45             : 
      46             : /** Model for a single rule in a conditional formatting. */
      47          36 : struct CondFormatRuleModel
      48             : {
      49             :     typedef ::std::vector< ApiTokenSequence > ApiTokenSequenceVector;
      50             : 
      51             :     ApiTokenSequenceVector maFormulas;      /// Formulas for rule conditions.
      52             :     ::rtl::OUString     maText;             /// Text for 'contains' rules.
      53             :     sal_Int32           mnPriority;         /// Priority of this rule.
      54             :     sal_Int32           mnType;             /// Type of the rule.
      55             :     sal_Int32           mnOperator;         /// In cell-is rules: Comparison operator.
      56             :     sal_Int32           mnTimePeriod;       /// In time-period rules: Type of time period.
      57             :     sal_Int32           mnRank;             /// In top-10 rules: True = bottom, false = top.
      58             :     sal_Int32           mnStdDev;           /// In average rules: Number of std deviations.
      59             :     sal_Int32           mnDxfId;            /// Differential formatting identifier.
      60             :     bool                mbStopIfTrue;       /// True = stop evaluating rules, if this rule is true.
      61             :     bool                mbBottom;           /// In top-10 rules: True = bottom, false = top.
      62             :     bool                mbPercent;          /// In top-10 rules: True = percent, false = rank.
      63             :     bool                mbAboveAverage;     /// In average rules: True = above average, false = below.
      64             :     bool                mbEqualAverage;     /// In average rules: True = include average, false = exclude.
      65             : 
      66             :     explicit            CondFormatRuleModel();
      67             : 
      68             :     /** Sets the passed BIFF operator for condition type cellIs. */
      69             :     void                setBiffOperator( sal_Int32 nOperator );
      70             : 
      71             :     /** Sets the passed BIFF12 text comparison type and operator. */
      72             :     void                setBiff12TextType( sal_Int32 nOperator );
      73             : };
      74             : 
      75           0 : struct ColorScaleRuleModelEntry
      76             : {
      77             :     ::Color maColor;
      78             :     double mnVal;
      79             : 
      80             :     bool mbMin;
      81             :     bool mbMax;
      82             :     bool mbPercent;
      83             :     bool mbPercentile;
      84             :     rtl::OUString maFormula;
      85             : 
      86           0 :     ColorScaleRuleModelEntry():
      87             :         maColor(),
      88             :         mnVal(0),
      89             :         mbMin(false),
      90             :         mbMax(false),
      91             :         mbPercent(false),
      92           0 :         mbPercentile(false) {}
      93             : };
      94             : 
      95           0 : class ColorScaleRule : public WorksheetHelper
      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             : 
     112           0 : class DataBarRule : public WorksheetHelper
     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             : 
     122           0 :     ScDataBarFormatData* getDataBarFormatData() { return mpFormat; }
     123             : 
     124             : private:
     125             :     ScDataBarFormatData* mpFormat;
     126             : 
     127             :     boost::scoped_ptr<ColorScaleRuleModelEntry> mpUpperLimit;
     128             :     boost::scoped_ptr<ColorScaleRuleModelEntry> mpLowerLimit;
     129             : };
     130             : 
     131           0 : class IconSetRule : public WorksheetHelper
     132             : {
     133             : public:
     134             :     IconSetRule( const CondFormat& rFormat );
     135             :     void importCfvo( const AttributeList& rAttribs );
     136             :     void importAttribs( const AttributeList& rAttribs );
     137             : 
     138             :     void SetData( ScIconSetFormat* pFormat, ScDocument* pDoc, const ScAddress& rAddr );
     139             : 
     140             : private:
     141             :     std::vector< ColorScaleRuleModelEntry > maEntries;
     142             :     ScIconSetFormatData* mpFormatData;
     143             :     rtl::OUString maIconSetType;
     144             : };
     145             : 
     146             : 
     147             : // ============================================================================
     148             : 
     149             : 
     150             : /** Represents a single rule in a conditional formatting. */
     151          72 : 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 ::rtl::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          72 :     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             :     boost::scoped_ptr<ColorScaleRule> mpColor;
     179             :     boost::scoped_ptr<DataBarRule> mpDataBar;
     180             :     boost::scoped_ptr<IconSetRule> mpIconSet;
     181             : };
     182             : 
     183             : typedef ::boost::shared_ptr< CondFormatRule > CondFormatRuleRef;
     184             : 
     185             : // ============================================================================
     186             : 
     187             : /** Model for a conditional formatting object. */
     188          28 : struct CondFormatModel
     189             : {
     190             :     ApiCellRangeList    maRanges;           /// Cell ranges for this conditional format.
     191             :     bool                mbPivot;            /// Conditional formatting belongs to pivot table.
     192             : 
     193             :     explicit            CondFormatModel();
     194             : };
     195             : 
     196             : // ============================================================================
     197             : 
     198             : /** Represents a conditional formatting object with a list of affected cell ranges. */
     199          56 : class CondFormat : public WorksheetHelper
     200             : {
     201             : public:
     202             :     explicit            CondFormat( const WorksheetHelper& rHelper );
     203             : 
     204             :     /** Imports settings from the conditionalFormatting element. */
     205             :     void                importConditionalFormatting( const AttributeList& rAttribs );
     206             :     /** Imports a conditional formatting rule from the cfRule element. */
     207             :     CondFormatRuleRef   importCfRule( const AttributeList& rAttribs );
     208             : 
     209             :     /** Imports settings from the CONDFORMATTING record. */
     210             :     void                importCondFormatting( SequenceInputStream& rStrm );
     211             :     /** Imports a conditional formatting rule from the CFRULE record. */
     212             :     void                importCfRule( SequenceInputStream& rStrm );
     213             : 
     214             :     /** Creates the conditional formatting in the Calc document. */
     215             :     void                finalizeImport();
     216             : 
     217             :     /** Returns the cell ranges this conditional formatting belongs to. */
     218          55 :     inline const ApiCellRangeList& getRanges() const { return maModel.maRanges; }
     219             : 
     220             : private:
     221             :     CondFormatRuleRef   createRule();
     222             :     void                insertRule( CondFormatRuleRef xRule );
     223             : 
     224             : private:
     225             :     typedef RefMap< sal_Int32, CondFormatRule > CondFormatRuleMap;
     226             : 
     227             :     CondFormatModel     maModel;            /// Model of this conditional formatting.
     228             :     CondFormatRuleMap   maRules;            /// Maps formatting rules by priority.
     229             :     ScConditionalFormat* mpFormat;
     230             : };
     231             : 
     232             : typedef ::boost::shared_ptr< CondFormat > CondFormatRef;
     233             : 
     234             : // ============================================================================
     235             : 
     236          25 : class CondFormatBuffer : public WorksheetHelper
     237             : {
     238             : public:
     239             :     explicit            CondFormatBuffer( const WorksheetHelper& rHelper );
     240             : 
     241             :     /** Imports settings from the conditionalFormatting element. */
     242             :     CondFormatRef       importConditionalFormatting( const AttributeList& rAttribs );
     243             :     /** Imports settings from the CONDFORMATTING record. */
     244             :     CondFormatRef       importCondFormatting( SequenceInputStream& rStrm );
     245             : 
     246             :     /** Converts an OOXML condition operator token to the API constant. */
     247             :     static sal_Int32    convertToApiOperator( sal_Int32 nToken );
     248             :     static sal_Int32    convertToInternalOperator( sal_Int32 nToken );
     249             : 
     250             : private:
     251             :     CondFormatRef       createCondFormat();
     252             : 
     253             : private:
     254             :     typedef RefVector< CondFormat > CondFormatVec;
     255             :     CondFormatVec       maCondFormats;      /// All conditional formatting in a sheet.
     256             : };
     257             : 
     258             : // ============================================================================
     259             : 
     260             : } // namespace xls
     261             : } // namespace oox
     262             : 
     263             : #endif
     264             : 
     265             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10