LibreOffice Module sc (master)  1
autofilterbuffer.hxx
Go to the documentation of this file.
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 #pragma once
21 
22 #include <oox/helper/helper.hxx>
23 #include <oox/helper/refvector.hxx>
24 #include "workbookhelper.hxx"
25 #include <com/sun/star/sheet/TableFilterField3.hpp>
26 #include <com/sun/star/util/Color.hpp>
27 
28 namespace com::sun::star {
29  namespace sheet { class XDatabaseRange; }
30  namespace sheet { class XSheetFilterDescriptor3; }
31 }
32 
33 namespace oox { class AttributeList; }
34 namespace oox { class SequenceInputStream; }
35 
36 namespace oox {
37 namespace xls {
38 
41 {
42  typedef ::std::vector<css::sheet::TableFilterField3> FilterFieldVector;
43 
44  FilterFieldVector maFilterFields;
46 
47  explicit ApiFilterSettings();
48 
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, css::util::Color aColor, bool bIsBackgroundColor );
52  void appendField( bool bAnd, const std::vector<std::pair<OUString, bool>>& rValues );
53 };
54 
58 {
59 public:
60  explicit FilterSettingsBase( const WorkbookHelper& rHelper );
61 
63  virtual void importAttribs( sal_Int32 nElement, const AttributeList& rAttribs );
65  virtual void importRecord( sal_Int32 nRecId, SequenceInputStream& rStrm );
66 
69 };
70 
71 
75 class DiscreteFilter final : public FilterSettingsBase
76 {
77 public:
78  explicit DiscreteFilter( const WorkbookHelper& rHelper );
79 
81  virtual void importAttribs( sal_Int32 nElement, const AttributeList& rAttribs ) override;
83  virtual void importRecord( sal_Int32 nRecId, SequenceInputStream& rStrm ) override;
84 
86  virtual ApiFilterSettings finalizeImport() override;
87 
88 private:
89 
90  std::vector<std::pair<OUString, bool>> maValues; // first->values, second->bDatefFormat
91  sal_Int32 mnCalendarType;
93 };
94 
96 class Top10Filter final : public FilterSettingsBase
97 {
98 public:
99  explicit Top10Filter( const WorkbookHelper& rHelper );
100 
102  virtual void importAttribs( sal_Int32 nElement, const AttributeList& rAttribs ) override;
104  virtual void importRecord( sal_Int32 nRecId, SequenceInputStream& rStrm ) override;
105 
107  virtual ApiFilterSettings finalizeImport() override;
108 
109 private:
110  double mfValue;
111  bool mbTop;
112  bool mbPercent;
113 };
114 
116 class ColorFilter final : public FilterSettingsBase
117 {
118 public:
119  explicit ColorFilter(const WorkbookHelper& rHelper);
120 
122  virtual void importAttribs(sal_Int32 nElement, const AttributeList& rAttribs) override;
124  virtual void importRecord(sal_Int32 nRecId, SequenceInputStream& rStrm) override;
125 
127  virtual ApiFilterSettings finalizeImport() override;
128 
129 private:
133  OUString msStyleName;
134 };
135 
138 {
139  css::uno::Any maValue;
140  sal_Int32 mnOperator;
142 
143  explicit FilterCriterionModel();
144 
146  void setBiffOperator( sal_uInt8 nOperator );
147 
149  void readBiffData( SequenceInputStream& rStrm );
150 };
151 
155 class CustomFilter final : public FilterSettingsBase
156 {
157 public:
158  explicit CustomFilter( const WorkbookHelper& rHelper );
159 
161  virtual void importAttribs( sal_Int32 nElement, const AttributeList& rAttribs ) override;
163  virtual void importRecord( sal_Int32 nRecId, SequenceInputStream& rStrm ) override;
164 
166  virtual ApiFilterSettings finalizeImport() override;
167 
168 private:
170  void appendCriterion( const FilterCriterionModel& rCriterion );
171 
172 private:
173  typedef ::std::vector< FilterCriterionModel > FilterCriterionVector;
174 
175  FilterCriterionVector maCriteria;
176  bool mbAnd;
177 };
178 
182 class FilterColumn final : public WorkbookHelper
183 {
184 public:
185  explicit FilterColumn( const WorkbookHelper& rHelper );
186 
188  void importFilterColumn( const AttributeList& rAttribs );
191 
193  template< typename FilterSettingsType >
195  { mxSettings = std::make_shared<FilterSettingsType>( *this ); return *mxSettings; }
196 
200 
201 private:
202  std::shared_ptr< FilterSettingsBase >
204  sal_Int32 mnColId;
207 };
208 
209 // class SortCondition
210 
211 class SortCondition final : public WorkbookHelper
212 {
213 public:
214  explicit SortCondition( const WorkbookHelper& rHelper );
215 
216  void importSortCondition( const AttributeList& rAttribs, sal_Int16 nSheet );
217 
218  ScRange maRange; // Column/Row that this sort condition applies to.
219  OUString maSortCustomList; // Sort by a custom list.
221 };
222 
223 // class AutoFilter
224 
225 class AutoFilter final : public WorkbookHelper
226 {
227 public:
228  explicit AutoFilter( const WorkbookHelper& rHelper );
229 
231  void importAutoFilter( const AttributeList& rAttribs, sal_Int16 nSheet );
233  void importAutoFilter( SequenceInputStream& rStrm, sal_Int16 nSheet );
234 
235  void importSortState( const AttributeList& rAttribs, sal_Int16 nSheet );
236 
239 
241 
243  void finalizeImport( const css::uno::Reference< css::sheet::XDatabaseRange >& rxDatabaseRange,
244  sal_Int16 nSheet );
245 
246 private:
248 
249  FilterColumnVector maFilterColumns;
251 
252  ScRange maSortRange; // The whole range of data to sort (not just the sort-by column).
254  SortConditionVector maSortConditions;
255 };
256 
257 class AutoFilterBuffer final : public WorkbookHelper
258 {
259 public:
260  explicit AutoFilterBuffer( const WorkbookHelper& rHelper );
261 
264 
267  void finalizeImport( sal_Int16 nSheet );
268 
271  bool finalizeImport( const css::uno::Reference< css::sheet::XDatabaseRange >& rxDatabaseRange,
272  sal_Int16 nSheet );
273 
274 private:
277 
278 private:
280  AutoFilterVector maAutoFilters;
281 };
282 
283 } // namespace xls
284 } // namespace oox
285 
286 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Helper class to provide access to global workbook data.
virtual ApiFilterSettings finalizeImport() override
Returns converted UNO API filter settings representing all filter settings.
void importSortState(const AttributeList &rAttribs, sal_Int16 nSheet)
::std::vector< css::sheet::TableFilterField3 > FilterFieldVector
virtual void importRecord(sal_Int32 nRecId, SequenceInputStream &rStrm) override
Imports filter settings from the FILTERS and FILTER records.
virtual ApiFilterSettings finalizeImport() override
Returns converted UNO API filter settings representing all filter settings.
void appendCriterion(const FilterCriterionModel &rCriterion)
Appends the passed filter criterion, if it contains valid settings.
sal_Int32 mnOperator
Comparison operand.
Settings for a color filter.
bool mbTop
Number of items or percentage.
SortConditionVector maSortConditions
ColorFilter(const WorkbookHelper &rHelper)
FilterColumnVector maFilterColumns
virtual void importAttribs(sal_Int32 nElement, const AttributeList &rAttribs)
Derived classes import filter settings from the passed attribute list.
OptValue< bool > mobNeedsRegExp
List of UNO API filter settings.
Contains UNO API filter settings for a column in a filtered range.
exports com.sun.star. sheet
void importAutoFilter(const AttributeList &rAttribs, sal_Int16 nSheet)
Imports auto filter settings from the autoFilter element.
AutoFilter & createAutoFilter()
Creates a new auto filter and stores it internally.
A filter criterion for a custom filter.
SortCondition & createSortCondition()
void importFilterColumn(const AttributeList &rAttribs)
Imports auto filter column settings from the filterColumn element.
FilterCriterionModel()
Operand data type (BIFF only).
RefVector< AutoFilter > AutoFilterVector
void importSortCondition(const AttributeList &rAttribs, sal_Int16 nSheet)
Settings for a custom filter, specifying one or two comparison operators associated with some values...
AutoFilter(const WorkbookHelper &rHelper)
FilterCriterionVector maCriteria
DiscreteFilter(const WorkbookHelper &rHelper)
CustomFilter(const WorkbookHelper &rHelper)
RefVector< SortCondition > SortConditionVector
virtual ApiFilterSettings finalizeImport()
Derived classes return converted UNO API filter settings representing all filter settings.
FilterColumn(const WorkbookHelper &rHelper)
virtual void importAttribs(sal_Int32 nElement, const AttributeList &rAttribs) override
Imports filter settings from the filters and filter elements.
AutoFilter * getActiveAutoFilter()
Returns the auto filter object used to perform auto filtering.
ApiFilterSettings finalizeImport()
Returns converted UNO API filter settings representing all filter settings of this column...
bool mbIsBackgroundColor
Whether we are dealing with the background color (vs. text color)
virtual void importAttribs(sal_Int32 nElement, const AttributeList &rAttribs) override
Imports filter settings from the filters and filter elements.
ApiFilterSettings()
If set, requires regular expressions to be enabled/disabled.
FilterSettingsBase & createFilterSettings()
Creates and returns the specified filter settings object.
virtual void importAttribs(sal_Int32 nElement, const AttributeList &rAttribs) override
Imports filter settings from the filters and filter elements.
sal_uInt8 mnDataType
Comparison operator.
void finalizeImport(sal_Int16 nSheet)
Applies filter settings to a new database range object (used for sheet autofilter or advanced filter ...
void appendField(bool bAnd, sal_Int32 nOperator, double fValue)
void readBiffData(SequenceInputStream &rStrm)
Imports the criterion model from the passed BIFF12 stream.
RefVector< FilterColumn > FilterColumnVector
FilterColumn & createFilterColumn()
Creates a new auto filter column and stores it internally.
virtual void importRecord(sal_Int32 nRecId, SequenceInputStream &rStrm) override
Imports filter settings from the FILTERS and FILTER records.
virtual void importRecord(sal_Int32 nRecId, SequenceInputStream &rStrm) override
Imports filter settings from the FILTERS and FILTER records.
virtual void importAttribs(sal_Int32 nElement, const AttributeList &rAttribs) override
Imports filter settings from the filters and filter elements.
virtual void importRecord(sal_Int32 nRecId, SequenceInputStream &rStrm)
Derived classes import filter settings from the passed record.
SortCondition(const WorkbookHelper &rHelper)
bool mbPercent
True = show top (greatest) items/percentage.
unsigned char sal_uInt8
A column in a filtered range.
FilterSettingsBase(const WorkbookHelper &rHelper)
std::shared_ptr< FilterSettingsBase > mxSettings
virtual ApiFilterSettings finalizeImport() override
Returns converted UNO API filter settings representing all filter settings.
::std::vector< FilterCriterionModel > FilterCriterionVector
void finalizeImport(const css::uno::Reference< css::sheet::XDatabaseRange > &rxDatabaseRange, sal_Int16 nSheet)
Applies the filter to the passed filter descriptor.
Settings for a discrete filter, specifying a list of values to be shown in the filtered range...
Top10Filter(const WorkbookHelper &rHelper)
Base class for specific filter settings for a column in a filtered range.
Settings for a top-10 filter.
virtual void importRecord(sal_Int32 nRecId, SequenceInputStream &rStrm) override
Imports filter settings from the FILTERS and FILTER records.
void setBiffOperator(sal_uInt8 nOperator)
Sets the passed BIFF operator constant.
void SvStream & rStrm
AutoFilterBuffer(const WorkbookHelper &rHelper)
FilterFieldVector maFilterFields
virtual ApiFilterSettings finalizeImport() override
Returns converted UNO API filter settings representing all filter settings.
OUString msStyleName
Style name to retrieve the color from.
std::vector< std::pair< OUString, bool > > maValues