LCOV - code coverage report
Current view: top level - sc/source/filter/inc - autofilterbuffer.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 9 11 81.8 %
Date: 2015-06-13 12:38:46 Functions: 13 21 61.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_AUTOFILTERBUFFER_HXX
      21             : #define INCLUDED_SC_SOURCE_FILTER_INC_AUTOFILTERBUFFER_HXX
      22             : 
      23             : #include <com/sun/star/table/CellRangeAddress.hpp>
      24             : #include <oox/helper/refvector.hxx>
      25             : #include "workbookhelper.hxx"
      26             : 
      27             : namespace com { namespace sun { namespace star {
      28             :     namespace sheet { struct TableFilterField3; }
      29             :     namespace sheet { class XDatabaseRange; }
      30             :     namespace sheet { class XSheetFilterDescriptor3; }
      31             : } } }
      32             : 
      33             : namespace oox {
      34             : namespace xls {
      35             : 
      36             : /** Contains UNO API filter settings for a column in a filtered range. */
      37           3 : struct ApiFilterSettings
      38             : {
      39             :     typedef ::std::vector<com::sun::star::sheet::TableFilterField3> FilterFieldVector;
      40             : 
      41             :     FilterFieldVector   maFilterFields;     /// List of UNO API filter settings.
      42             :     OptValue< bool >    mobNeedsRegExp;     /// If set, requires regular expressions to be enabled/disabled.
      43             : 
      44             :     explicit            ApiFilterSettings();
      45             : 
      46             :     void appendField( bool bAnd, sal_Int32 nOperator, double fValue );
      47             :     void appendField( bool bAnd, sal_Int32 nOperator, const OUString& rValue );
      48             :     void appendField( bool bAnd, const std::vector<OUString>& rValues );
      49             : };
      50             : 
      51             : /** Base class for specific filter settings for a column in a filtered range.
      52             :  */
      53           1 : class FilterSettingsBase : public WorkbookHelper
      54             : {
      55             : public:
      56             :     explicit            FilterSettingsBase( const WorkbookHelper& rHelper );
      57             : 
      58             :     /** Derived classes import filter settings from the passed attribute list. */
      59             :     virtual void        importAttribs( sal_Int32 nElement, const AttributeList& rAttribs );
      60             :     /** Derived classes import filter settings from the passed record. */
      61             :     virtual void        importRecord( sal_Int32 nRecId, SequenceInputStream& rStrm );
      62             : 
      63             :     /** Derived classes return converted UNO API filter settings representing all filter settings. */
      64             :     virtual ApiFilterSettings finalizeImport( sal_Int32 nMaxCount );
      65             : };
      66             : 
      67             : typedef ::boost::shared_ptr< FilterSettingsBase > FilterSettingsRef;
      68             : 
      69             : /** Settings for a discrete filter, specifying a list of values to be shown in
      70             :     the filtered range.
      71             :  */
      72           0 : class DiscreteFilter : public FilterSettingsBase
      73             : {
      74             : public:
      75             :     explicit            DiscreteFilter( const WorkbookHelper& rHelper );
      76             : 
      77             :     /** Imports filter settings from the filters and filter elements. */
      78             :     virtual void        importAttribs( sal_Int32 nElement, const AttributeList& rAttribs ) SAL_OVERRIDE;
      79             :     /** Imports filter settings from the FILTERS and FILTER records. */
      80             :     virtual void        importRecord( sal_Int32 nRecId, SequenceInputStream& rStrm ) SAL_OVERRIDE;
      81             : 
      82             :     /** Returns converted UNO API filter settings representing all filter settings. */
      83             :     virtual ApiFilterSettings finalizeImport( sal_Int32 nMaxCount ) SAL_OVERRIDE;
      84             : 
      85             : private:
      86             :     typedef ::std::vector< OUString > FilterValueVector;
      87             : 
      88             :     FilterValueVector   maValues;
      89             :     sal_Int32           mnCalendarType;
      90             :     bool                mbShowBlank;
      91             : };
      92             : 
      93             : /** Settings for a top-10 filter. */
      94           0 : class Top10Filter : public FilterSettingsBase
      95             : {
      96             : public:
      97             :     explicit            Top10Filter( const WorkbookHelper& rHelper );
      98             : 
      99             :     /** Imports filter settings from the filters and filter elements. */
     100             :     virtual void        importAttribs( sal_Int32 nElement, const AttributeList& rAttribs ) SAL_OVERRIDE;
     101             :     /** Imports filter settings from the FILTERS and FILTER records. */
     102             :     virtual void        importRecord( sal_Int32 nRecId, SequenceInputStream& rStrm ) SAL_OVERRIDE;
     103             : 
     104             :     /** Returns converted UNO API filter settings representing all filter settings. */
     105             :     virtual ApiFilterSettings finalizeImport( sal_Int32 nMaxCount ) SAL_OVERRIDE;
     106             : 
     107             : private:
     108             :     double              mfValue;        /// Number of items or percentage.
     109             :     bool                mbTop;          /// True = show top (greatest) items/percentage.
     110             :     bool                mbPercent;      /// True = percentage, false = number of items.
     111             : };
     112             : 
     113             : /** A filter criterion for a custom filter. */
     114           3 : struct FilterCriterionModel
     115             : {
     116             :     ::com::sun::star::uno::Any maValue; /// Comparison operand.
     117             :     sal_Int32           mnOperator;     /// Comparison operator.
     118             :     sal_uInt8           mnDataType;     /// Operand data type (BIFF only).
     119             :     sal_uInt8           mnStrLen;       /// Length of string operand (BIFF5-BIFF8 only).
     120             : 
     121             :     explicit            FilterCriterionModel();
     122             : 
     123             :     /** Sets the passed BIFF operator constant. */
     124             :     void                setBiffOperator( sal_uInt8 nOperator );
     125             : 
     126             :     /** Imports the criterion model from the passed BIFF12 stream. */
     127             :     void                readBiffData( SequenceInputStream& rStrm );
     128             : };
     129             : 
     130             : /** Settings for a custom filter, specifying one or two comparison operators
     131             :     associated with some values.
     132             :  */
     133           2 : class CustomFilter : public FilterSettingsBase
     134             : {
     135             : public:
     136             :     explicit            CustomFilter( const WorkbookHelper& rHelper );
     137             : 
     138             :     /** Imports filter settings from the filters and filter elements. */
     139             :     virtual void        importAttribs( sal_Int32 nElement, const AttributeList& rAttribs ) SAL_OVERRIDE;
     140             :     /** Imports filter settings from the FILTERS and FILTER records. */
     141             :     virtual void        importRecord( sal_Int32 nRecId, SequenceInputStream& rStrm ) SAL_OVERRIDE;
     142             : 
     143             :     /** Returns converted UNO API filter settings representing all filter settings. */
     144             :     virtual ApiFilterSettings finalizeImport( sal_Int32 nMaxCount ) SAL_OVERRIDE;
     145             : 
     146             : private:
     147             :     /** Apeends the passed filter criteriom, if it contains valid settings. */
     148             :     void                appendCriterion( const FilterCriterionModel& rCriterion );
     149             : 
     150             : private:
     151             :     typedef ::std::vector< FilterCriterionModel > FilterCriterionVector;
     152             : 
     153             :     FilterCriterionVector maCriteria;
     154             :     bool                mbAnd;
     155             : };
     156             : 
     157             : /** A column in a filtered range. Contains an object with specific filter
     158             :     settings for the cells in the column.
     159             :  */
     160           2 : class FilterColumn : public WorkbookHelper
     161             : {
     162             : public:
     163             :     explicit            FilterColumn( const WorkbookHelper& rHelper );
     164             : 
     165             :     /** Imports auto filter column settings from the filterColumn element. */
     166             :     void                importFilterColumn( const AttributeList& rAttribs );
     167             :     /** Imports auto filter column settings from the FILTERCOLUMN record. */
     168             :     void                importFilterColumn( SequenceInputStream& rStrm );
     169             : 
     170             :     /** Creates and returns the specified filter settings object. */
     171             :     template< typename FilterSettingsType >
     172           1 :     inline FilterSettingsBase& createFilterSettings()
     173           1 :         { mxSettings.reset( new FilterSettingsType( *this ) ); return *mxSettings; }
     174             : 
     175             :     /** Returns the index of the column in the filtered range this object is related to. */
     176             :     inline sal_Int32    getColumnId() const { return mnColId; }
     177             : 
     178             :     /** Returns converted UNO API filter settings representing all filter
     179             :         settings of this column. */
     180             :     ApiFilterSettings   finalizeImport( sal_Int32 nMaxCount );
     181             : 
     182             : private:
     183             :     FilterSettingsRef   mxSettings;
     184             :     sal_Int32           mnColId;
     185             :     bool                mbHiddenButton;
     186             :     bool                mbShowButton;
     187             : };
     188             : 
     189           2 : class AutoFilter : public WorkbookHelper
     190             : {
     191             : public:
     192             :     explicit            AutoFilter( const WorkbookHelper& rHelper );
     193             : 
     194             :     /** Imports auto filter settings from the autoFilter element. */
     195             :     void                importAutoFilter( const AttributeList& rAttribs, sal_Int16 nSheet );
     196             :     /** Imports auto filter settings from the AUTOFILTER record. */
     197             :     void                importAutoFilter( SequenceInputStream& rStrm, sal_Int16 nSheet );
     198             : 
     199             :     /** Creates a new auto filter column and stores it internally. */
     200             :     FilterColumn&       createFilterColumn();
     201             : 
     202             :     /** Applies the filter to the passed filter descriptor. */
     203             :     void                finalizeImport(
     204             :         const ::com::sun::star::uno::Reference<
     205             :             ::com::sun::star::sheet::XSheetFilterDescriptor3>& rxFilterDesc );
     206             : 
     207             : private:
     208             :     typedef RefVector< FilterColumn > FilterColumnVector;
     209             : 
     210             :     FilterColumnVector  maFilterColumns;
     211             :     ::com::sun::star::table::CellRangeAddress maRange;
     212             : };
     213             : 
     214         269 : class AutoFilterBuffer : public WorkbookHelper
     215             : {
     216             : public:
     217             :     explicit            AutoFilterBuffer( const WorkbookHelper& rHelper );
     218             : 
     219             :     /** Creates a new auto filter and stores it internally. */
     220             :     AutoFilter&         createAutoFilter();
     221             : 
     222             :     /** Applies filter settings to a new database range object (used for sheet
     223             :         autofilter or advanced filter as specified by built-in defined names). */
     224             :     void                finalizeImport( sal_Int16 nSheet );
     225             : 
     226             :     /** Applies the filters to the passed database range object.
     227             :         @return  True = this buffer contains valid auto filter settings. */
     228             :     bool                finalizeImport( const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XDatabaseRange >& rxDatabaseRange );
     229             : 
     230             : private:
     231             :     /** Returns the auto filter object used to perform auto filtering. */
     232             :     AutoFilter*         getActiveAutoFilter();
     233             : 
     234             : private:
     235             :     typedef RefVector< AutoFilter > AutoFilterVector;
     236             :     AutoFilterVector    maAutoFilters;
     237             : };
     238             : 
     239             : } // namespace xls
     240             : } // namespace oox
     241             : 
     242             : #endif
     243             : 
     244             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11