1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SC_SOURCE_FILTER_INC_AUTOFILTERBUFFER_HXX
21 #define INCLUDED_SC_SOURCE_FILTER_INC_AUTOFILTERBUFFER_HXX
23 #include <oox/helper/helper.hxx>
24 #include <oox/helper/refvector.hxx>
25 #include "workbookhelper.hxx"
26 #include <com/sun/star/sheet/TableFilterField3.hpp>
28 namespace com
{ namespace sun
{ namespace star
{
29 namespace sheet
{ class XDatabaseRange
; }
30 namespace sheet
{ class XSheetFilterDescriptor3
; }
33 namespace oox
{ class AttributeList
; }
34 namespace oox
{ class SequenceInputStream
; }
39 /** Contains UNO API filter settings for a column in a filtered range. */
40 struct ApiFilterSettings
42 typedef ::std::vector
<css::sheet::TableFilterField3
> FilterFieldVector
;
44 FilterFieldVector maFilterFields
; /// List of UNO API filter settings.
45 OptValue
< bool > mobNeedsRegExp
; /// If set, requires regular expressions to be enabled/disabled.
47 explicit ApiFilterSettings();
49 void appendField( bool bAnd
, sal_Int32 nOperator
, double fValue
);
50 void appendField( bool bAnd
, sal_Int32 nOperator
, const OUString
& rValue
);
51 void appendField( bool bAnd
, const std::vector
<OUString
>& rValues
);
54 /** Base class for specific filter settings for a column in a filtered range.
56 class FilterSettingsBase
: public WorkbookHelper
59 explicit FilterSettingsBase( const WorkbookHelper
& rHelper
);
61 /** Derived classes import filter settings from the passed attribute list. */
62 virtual void importAttribs( sal_Int32 nElement
, const AttributeList
& rAttribs
);
63 /** Derived classes import filter settings from the passed record. */
64 virtual void importRecord( sal_Int32 nRecId
, SequenceInputStream
& rStrm
);
66 /** Derived classes return converted UNO API filter settings representing all filter settings. */
67 virtual ApiFilterSettings
finalizeImport( sal_Int32 nMaxCount
);
71 /** Settings for a discrete filter, specifying a list of values to be shown in
74 class DiscreteFilter
: public FilterSettingsBase
77 explicit DiscreteFilter( const WorkbookHelper
& rHelper
);
79 /** Imports filter settings from the filters and filter elements. */
80 virtual void importAttribs( sal_Int32 nElement
, const AttributeList
& rAttribs
) override
;
81 /** Imports filter settings from the FILTERS and FILTER records. */
82 virtual void importRecord( sal_Int32 nRecId
, SequenceInputStream
& rStrm
) override
;
84 /** Returns converted UNO API filter settings representing all filter settings. */
85 virtual ApiFilterSettings
finalizeImport( sal_Int32 nMaxCount
) override
;
89 std::vector
< OUString
> maValues
;
90 sal_Int32 mnCalendarType
;
94 /** Settings for a top-10 filter. */
95 class Top10Filter
: public FilterSettingsBase
98 explicit Top10Filter( const WorkbookHelper
& rHelper
);
100 /** Imports filter settings from the filters and filter elements. */
101 virtual void importAttribs( sal_Int32 nElement
, const AttributeList
& rAttribs
) override
;
102 /** Imports filter settings from the FILTERS and FILTER records. */
103 virtual void importRecord( sal_Int32 nRecId
, SequenceInputStream
& rStrm
) override
;
105 /** Returns converted UNO API filter settings representing all filter settings. */
106 virtual ApiFilterSettings
finalizeImport( sal_Int32 nMaxCount
) override
;
109 double mfValue
; /// Number of items or percentage.
110 bool mbTop
; /// True = show top (greatest) items/percentage.
111 bool mbPercent
; /// True = percentage, false = number of items.
114 /** A filter criterion for a custom filter. */
115 struct FilterCriterionModel
117 css::uno::Any maValue
; /// Comparison operand.
118 sal_Int32 mnOperator
; /// Comparison operator.
119 sal_uInt8 mnDataType
; /// Operand data type (BIFF only).
121 explicit FilterCriterionModel();
123 /** Sets the passed BIFF operator constant. */
124 void setBiffOperator( sal_uInt8 nOperator
);
126 /** Imports the criterion model from the passed BIFF12 stream. */
127 void readBiffData( SequenceInputStream
& rStrm
);
130 /** Settings for a custom filter, specifying one or two comparison operators
131 associated with some values.
133 class CustomFilter
: public FilterSettingsBase
136 explicit CustomFilter( const WorkbookHelper
& rHelper
);
138 /** Imports filter settings from the filters and filter elements. */
139 virtual void importAttribs( sal_Int32 nElement
, const AttributeList
& rAttribs
) override
;
140 /** Imports filter settings from the FILTERS and FILTER records. */
141 virtual void importRecord( sal_Int32 nRecId
, SequenceInputStream
& rStrm
) override
;
143 /** Returns converted UNO API filter settings representing all filter settings. */
144 virtual ApiFilterSettings
finalizeImport( sal_Int32 nMaxCount
) override
;
147 /** Appends the passed filter criterion, if it contains valid settings. */
148 void appendCriterion( const FilterCriterionModel
& rCriterion
);
151 typedef ::std::vector
< FilterCriterionModel
> FilterCriterionVector
;
153 FilterCriterionVector maCriteria
;
157 /** A column in a filtered range. Contains an object with specific filter
158 settings for the cells in the column.
160 class FilterColumn
: public WorkbookHelper
163 explicit FilterColumn( const WorkbookHelper
& rHelper
);
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
);
170 /** Creates and returns the specified filter settings object. */
171 template< typename FilterSettingsType
>
172 FilterSettingsBase
& createFilterSettings()
173 { mxSettings
.reset( new FilterSettingsType( *this ) ); return *mxSettings
; }
175 /** Returns converted UNO API filter settings representing all filter
176 settings of this column. */
177 ApiFilterSettings
finalizeImport( sal_Int32 nMaxCount
);
180 std::shared_ptr
< FilterSettingsBase
>
187 class AutoFilter
: public WorkbookHelper
190 explicit AutoFilter( const WorkbookHelper
& rHelper
);
192 /** Imports auto filter settings from the autoFilter element. */
193 void importAutoFilter( const AttributeList
& rAttribs
, sal_Int16 nSheet
);
194 /** Imports auto filter settings from the AUTOFILTER record. */
195 void importAutoFilter( SequenceInputStream
& rStrm
, sal_Int16 nSheet
);
197 /** Creates a new auto filter column and stores it internally. */
198 FilterColumn
& createFilterColumn();
200 /** Applies the filter to the passed filter descriptor. */
201 void finalizeImport( const css::uno::Reference
< css::sheet::XSheetFilterDescriptor3
>& rxFilterDesc
);
204 typedef RefVector
< FilterColumn
> FilterColumnVector
;
206 FilterColumnVector maFilterColumns
;
210 class AutoFilterBuffer
: public WorkbookHelper
213 explicit AutoFilterBuffer( const WorkbookHelper
& rHelper
);
215 /** Creates a new auto filter and stores it internally. */
216 AutoFilter
& createAutoFilter();
218 /** Applies filter settings to a new database range object (used for sheet
219 autofilter or advanced filter as specified by built-in defined names). */
220 void finalizeImport( sal_Int16 nSheet
);
222 /** Applies the filters to the passed database range object.
223 @return True = this buffer contains valid auto filter settings. */
224 bool finalizeImport( const css::uno::Reference
< css::sheet::XDatabaseRange
>& rxDatabaseRange
);
227 /** Returns the auto filter object used to perform auto filtering. */
228 AutoFilter
* getActiveAutoFilter();
231 typedef RefVector
< AutoFilter
> AutoFilterVector
;
232 AutoFilterVector maAutoFilters
;
240 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */