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

Generated by: LCOV version 1.10