LCOV - code coverage report
Current view: top level - sc/source/filter/inc - autofilterbuffer.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 9 11 81.8 %
Date: 2012-08-25 Functions: 13 21 61.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 7 22 31.8 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #ifndef OOX_XLS_AUTOFILTERBUFFER_HXX
      30                 :            : #define OOX_XLS_AUTOFILTERBUFFER_HXX
      31                 :            : 
      32                 :            : #include <com/sun/star/table/CellRangeAddress.hpp>
      33                 :            : #include "oox/helper/refvector.hxx"
      34                 :            : #include "workbookhelper.hxx"
      35                 :            : 
      36                 :            : namespace com { namespace sun { namespace star {
      37                 :            :     namespace sheet { struct TableFilterField3; }
      38                 :            :     namespace sheet { class XDatabaseRange; }
      39                 :            :     namespace sheet { class XSheetFilterDescriptor3; }
      40                 :            : } } }
      41                 :            : 
      42                 :            : namespace oox {
      43                 :            : namespace xls {
      44                 :            : 
      45                 :            : // ============================================================================
      46                 :            : 
      47                 :            : /** Contains UNO API filter settings for a column in a filtered range. */
      48                 :          9 : struct ApiFilterSettings
      49                 :            : {
      50                 :            :     typedef ::std::vector<com::sun::star::sheet::TableFilterField3> FilterFieldVector;
      51                 :            : 
      52                 :            :     FilterFieldVector   maFilterFields;     /// List of UNO API filter settings.
      53                 :            :     OptValue< bool >    mobNeedsRegExp;     /// If set, requires regular expressions to be enabled/disabled.
      54                 :            : 
      55                 :            :     explicit            ApiFilterSettings();
      56                 :            : 
      57                 :            :     void appendField( bool bAnd, sal_Int32 nOperator, double fValue );
      58                 :            :     void appendField( bool bAnd, sal_Int32 nOperator, const ::rtl::OUString& rValue );
      59                 :            :     void appendField( bool bAnd, const std::vector<rtl::OUString>& rValues );
      60                 :            : };
      61                 :            : 
      62                 :            : // ============================================================================
      63                 :            : 
      64                 :            : /** Base class for specific filter settings for a column in a filtered range.
      65                 :            :  */
      66         [ -  + ]:          3 : class FilterSettingsBase : public WorkbookHelper
      67                 :            : {
      68                 :            : public:
      69                 :            :     explicit            FilterSettingsBase( const WorkbookHelper& rHelper );
      70                 :            : 
      71                 :            :     /** Derived classes import filter settings from the passed attribute list. */
      72                 :            :     virtual void        importAttribs( sal_Int32 nElement, const AttributeList& rAttribs );
      73                 :            :     /** Derived classes import filter settings from the passed record. */
      74                 :            :     virtual void        importRecord( sal_Int32 nRecId, SequenceInputStream& rStrm );
      75                 :            :     /** Derived classes import filter settings from the FILTERCOLUMN record. */
      76                 :            :     virtual void        importBiffRecord( BiffInputStream& rStrm, sal_uInt16 nFlags );
      77                 :            : 
      78                 :            :     /** Derived classes return converted UNO API filter settings representing all filter settings. */
      79                 :            :     virtual ApiFilterSettings finalizeImport( sal_Int32 nMaxCount );
      80                 :            : };
      81                 :            : 
      82                 :            : typedef ::boost::shared_ptr< FilterSettingsBase > FilterSettingsRef;
      83                 :            : 
      84                 :            : // ============================================================================
      85                 :            : 
      86                 :            : /** Settings for a discrete filter, specifying a list of values to be shown in
      87                 :            :     the filtered range.
      88                 :            :  */
      89         [ #  # ]:          0 : class DiscreteFilter : public FilterSettingsBase
      90                 :            : {
      91                 :            : public:
      92                 :            :     explicit            DiscreteFilter( const WorkbookHelper& rHelper );
      93                 :            : 
      94                 :            :     /** Imports filter settings from the filters and filter elements. */
      95                 :            :     virtual void        importAttribs( sal_Int32 nElement, const AttributeList& rAttribs );
      96                 :            :     /** Imports filter settings from the FILTERS and FILTER records. */
      97                 :            :     virtual void        importRecord( sal_Int32 nRecId, SequenceInputStream& rStrm );
      98                 :            : 
      99                 :            :     /** Returns converted UNO API filter settings representing all filter settings. */
     100                 :            :     virtual ApiFilterSettings finalizeImport( sal_Int32 nMaxCount );
     101                 :            : 
     102                 :            : private:
     103                 :            :     typedef ::std::vector< ::rtl::OUString > FilterValueVector;
     104                 :            : 
     105                 :            :     FilterValueVector   maValues;
     106                 :            :     sal_Int32           mnCalendarType;
     107                 :            :     bool                mbShowBlank;
     108                 :            : };
     109                 :            : 
     110                 :            : // ============================================================================
     111                 :            : 
     112                 :            : /** Settings for a top-10 filter. */
     113         [ #  # ]:          0 : class Top10Filter : public FilterSettingsBase
     114                 :            : {
     115                 :            : public:
     116                 :            :     explicit            Top10Filter( const WorkbookHelper& rHelper );
     117                 :            : 
     118                 :            :     /** Imports filter settings from the filters and filter elements. */
     119                 :            :     virtual void        importAttribs( sal_Int32 nElement, const AttributeList& rAttribs );
     120                 :            :     /** Imports filter settings from the FILTERS and FILTER records. */
     121                 :            :     virtual void        importRecord( sal_Int32 nRecId, SequenceInputStream& rStrm );
     122                 :            :     /** Imports filter settings from the FILTERCOLUMN record. */
     123                 :            :     virtual void        importBiffRecord( BiffInputStream& rStrm, sal_uInt16 nFlags );
     124                 :            : 
     125                 :            :     /** Returns converted UNO API filter settings representing all filter settings. */
     126                 :            :     virtual ApiFilterSettings finalizeImport( sal_Int32 nMaxCount );
     127                 :            : 
     128                 :            : private:
     129                 :            :     double              mfValue;        /// Number of items or percentage.
     130                 :            :     bool                mbTop;          /// True = show top (greatest) items/percentage.
     131                 :            :     bool                mbPercent;      /// True = percentage, false = number of items.
     132                 :            : };
     133                 :            : 
     134                 :            : // ============================================================================
     135                 :            : 
     136                 :            : /** A filter criterion for a custom filter. */
     137                 :          9 : struct FilterCriterionModel
     138                 :            : {
     139                 :            :     ::com::sun::star::uno::Any maValue; /// Comparison operand.
     140                 :            :     sal_Int32           mnOperator;     /// Comparison operator.
     141                 :            :     sal_uInt8           mnDataType;     /// Operand data type (BIFF only).
     142                 :            :     sal_uInt8           mnStrLen;       /// Length of string operand (BIFF5-BIFF8 only).
     143                 :            : 
     144                 :            :     explicit            FilterCriterionModel();
     145                 :            : 
     146                 :            :     /** Sets the passed BIFF operator constant. */
     147                 :            :     void                setBiffOperator( sal_uInt8 nOperator );
     148                 :            : 
     149                 :            :     /** Imports the criterion model from the passed BIFF12 stream. */
     150                 :            :     void                readBiffData( SequenceInputStream& rStrm );
     151                 :            :     /** Imports the initial criterion data from the passed BIFF5/BIFF8 stream. */
     152                 :            :     void                readBiffData( BiffInputStream& rStrm );
     153                 :            :     /** Imports the trailing string data from the passed BIFF5/BIFF8 stream. */
     154                 :            :     void                readString( BiffInputStream& rStrm, BiffType eBiff, rtl_TextEncoding eTextEnc );
     155                 :            : };
     156                 :            : 
     157                 :            : // ----------------------------------------------------------------------------
     158                 :            : 
     159                 :            : /** Settings for a custom filter, specifying one or two comparison operators
     160                 :            :     associated with some values.
     161                 :            :  */
     162         [ -  + ]:          6 : class CustomFilter : public FilterSettingsBase
     163                 :            : {
     164                 :            : public:
     165                 :            :     explicit            CustomFilter( const WorkbookHelper& rHelper );
     166                 :            : 
     167                 :            :     /** Imports filter settings from the filters and filter elements. */
     168                 :            :     virtual void        importAttribs( sal_Int32 nElement, const AttributeList& rAttribs );
     169                 :            :     /** Imports filter settings from the FILTERS and FILTER records. */
     170                 :            :     virtual void        importRecord( sal_Int32 nRecId, SequenceInputStream& rStrm );
     171                 :            :     /** Imports filter settings from the FILTERCOLUMN record. */
     172                 :            :     virtual void        importBiffRecord( BiffInputStream& rStrm, sal_uInt16 nFlags );
     173                 :            : 
     174                 :            :     /** Returns converted UNO API filter settings representing all filter settings. */
     175                 :            :     virtual ApiFilterSettings finalizeImport( sal_Int32 nMaxCount );
     176                 :            : 
     177                 :            : private:
     178                 :            :     /** Apeends the passed filter criteriom, if it contains valid settings. */
     179                 :            :     void                appendCriterion( const FilterCriterionModel& rCriterion );
     180                 :            : 
     181                 :            : private:
     182                 :            :     typedef ::std::vector< FilterCriterionModel > FilterCriterionVector;
     183                 :            : 
     184                 :            :     FilterCriterionVector maCriteria;
     185                 :            :     bool                mbAnd;
     186                 :            : };
     187                 :            : 
     188                 :            : // ============================================================================
     189                 :            : 
     190                 :            : /** A column in a filtered range. Contains an object with specific filter
     191                 :            :     settings for the cells in the column.
     192                 :            :  */
     193 [ +  - ][ -  + ]:          6 : class FilterColumn : public WorkbookHelper
     194                 :            : {
     195                 :            : public:
     196                 :            :     explicit            FilterColumn( const WorkbookHelper& rHelper );
     197                 :            : 
     198                 :            :     /** Imports auto filter column settings from the filterColumn element. */
     199                 :            :     void                importFilterColumn( const AttributeList& rAttribs );
     200                 :            :     /** Imports auto filter column settings from the FILTERCOLUMN record. */
     201                 :            :     void                importFilterColumn( SequenceInputStream& rStrm );
     202                 :            : 
     203                 :            :     /** Creates and returns the specified filter settings object. */
     204                 :            :     template< typename FilterSettingsType >
     205                 :          3 :     inline FilterSettingsBase& createFilterSettings()
     206 [ +  - ][ #  # ]:          3 :         { mxSettings.reset( new FilterSettingsType( *this ) ); return *mxSettings; }
                 [ #  # ]
     207                 :            : 
     208                 :            :     /** Returns the index of the column in the filtered range this object is related to. */
     209                 :            :     inline sal_Int32    getColumnId() const { return mnColId; }
     210                 :            : 
     211                 :            :     /** Returns converted UNO API filter settings representing all filter
     212                 :            :         settings of this column. */
     213                 :            :     ApiFilterSettings   finalizeImport( sal_Int32 nMaxCount );
     214                 :            : 
     215                 :            : private:
     216                 :            :     FilterSettingsRef   mxSettings;
     217                 :            :     sal_Int32           mnColId;
     218                 :            :     bool                mbHiddenButton;
     219                 :            :     bool                mbShowButton;
     220                 :            : };
     221                 :            : 
     222                 :            : // ============================================================================
     223                 :            : 
     224         [ -  + ]:          6 : class AutoFilter : public WorkbookHelper
     225                 :            : {
     226                 :            : public:
     227                 :            :     explicit            AutoFilter( const WorkbookHelper& rHelper );
     228                 :            : 
     229                 :            :     /** Imports auto filter settings from the autoFilter element. */
     230                 :            :     void                importAutoFilter( const AttributeList& rAttribs, sal_Int16 nSheet );
     231                 :            :     /** Imports auto filter settings from the AUTOFILTER record. */
     232                 :            :     void                importAutoFilter( SequenceInputStream& rStrm, sal_Int16 nSheet );
     233                 :            : 
     234                 :            :     /** Creates a new auto filter column and stores it internally. */
     235                 :            :     FilterColumn&       createFilterColumn();
     236                 :            : 
     237                 :            :     /** Applies the filter to the passed filter descriptor. */
     238                 :            :     void                finalizeImport(
     239                 :            :         const ::com::sun::star::uno::Reference<
     240                 :            :             ::com::sun::star::sheet::XSheetFilterDescriptor3>& rxFilterDesc );
     241                 :            : 
     242                 :            : private:
     243                 :            :     typedef RefVector< FilterColumn > FilterColumnVector;
     244                 :            : 
     245                 :            :     FilterColumnVector  maFilterColumns;
     246                 :            :     ::com::sun::star::table::CellRangeAddress maRange;
     247                 :            : };
     248                 :            : 
     249                 :            : // ============================================================================
     250                 :            : 
     251         [ -  + ]:         60 : class AutoFilterBuffer : public WorkbookHelper
     252                 :            : {
     253                 :            : public:
     254                 :            :     explicit            AutoFilterBuffer( const WorkbookHelper& rHelper );
     255                 :            : 
     256                 :            :     /** Creates a new auto filter and stores it internally. */
     257                 :            :     AutoFilter&         createAutoFilter();
     258                 :            : 
     259                 :            :     /** Applies filter settings to a new database range object (used for sheet
     260                 :            :         autofilter or advanced filter as specified by built-in defined names). */
     261                 :            :     void                finalizeImport( sal_Int16 nSheet );
     262                 :            : 
     263                 :            :     /** Applies the filters to the passed database range object.
     264                 :            :         @return  True = this buffer contains valid auto filter settings. */
     265                 :            :     bool                finalizeImport( const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XDatabaseRange >& rxDatabaseRange );
     266                 :            : 
     267                 :            : private:
     268                 :            :     /** Returns the auto filter object used to perform auto filtering. */
     269                 :            :     AutoFilter*         getActiveAutoFilter();
     270                 :            : 
     271                 :            : private:
     272                 :            :     typedef RefVector< AutoFilter > AutoFilterVector;
     273                 :            :     AutoFilterVector    maAutoFilters;
     274                 :            : };
     275                 :            : 
     276                 :            : // ============================================================================
     277                 :            : 
     278                 :            : } // namespace xls
     279                 :            : } // namespace oox
     280                 :            : 
     281                 :            : #endif
     282                 :            : 
     283                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10