LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / sc / source / filter / inc / autofilterbuffer.hxx
blob788be95615c14ccee4e125f49fe0009363ab8a60
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #pragma once
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>
28 namespace com::sun::star {
29 namespace sheet { class XDatabaseRange; }
30 namespace sheet { class XSheetFilterDescriptor3; }
33 namespace oox { class AttributeList; }
34 namespace oox { class SequenceInputStream; }
36 namespace oox {
37 namespace xls {
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, css::util::Color aColor, bool bIsBackgroundColor );
52 void appendField( bool bAnd, const std::vector<std::pair<OUString, bool>>& rValues );
55 /** Base class for specific filter settings for a column in a filtered range.
57 class FilterSettingsBase : public WorkbookHelper
59 public:
60 explicit FilterSettingsBase( const WorkbookHelper& rHelper );
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 );
67 /** Derived classes return converted UNO API filter settings representing all filter settings. */
68 virtual ApiFilterSettings finalizeImport();
72 /** Settings for a discrete filter, specifying a list of values to be shown in
73 the filtered range.
75 class DiscreteFilter final : public FilterSettingsBase
77 public:
78 explicit DiscreteFilter( const WorkbookHelper& rHelper );
80 /** Imports filter settings from the filters and filter elements. */
81 virtual void importAttribs( sal_Int32 nElement, const AttributeList& rAttribs ) override;
82 /** Imports filter settings from the FILTERS and FILTER records. */
83 virtual void importRecord( sal_Int32 nRecId, SequenceInputStream& rStrm ) override;
85 /** Returns converted UNO API filter settings representing all filter settings. */
86 virtual ApiFilterSettings finalizeImport() override;
88 private:
90 std::vector<std::pair<OUString, bool>> maValues; // first->values, second->bDatefFormat
91 sal_Int32 mnCalendarType;
92 bool mbShowBlank;
95 /** Settings for a top-10 filter. */
96 class Top10Filter final : public FilterSettingsBase
98 public:
99 explicit Top10Filter( const WorkbookHelper& rHelper );
101 /** Imports filter settings from the filters and filter elements. */
102 virtual void importAttribs( sal_Int32 nElement, const AttributeList& rAttribs ) override;
103 /** Imports filter settings from the FILTERS and FILTER records. */
104 virtual void importRecord( sal_Int32 nRecId, SequenceInputStream& rStrm ) override;
106 /** Returns converted UNO API filter settings representing all filter settings. */
107 virtual ApiFilterSettings finalizeImport() override;
109 private:
110 double mfValue; /// Number of items or percentage.
111 bool mbTop; /// True = show top (greatest) items/percentage.
112 bool mbPercent; /// True = percentage, false = number of items.
115 /** Settings for a color filter. */
116 class ColorFilter final : public FilterSettingsBase
118 public:
119 explicit ColorFilter(const WorkbookHelper& rHelper);
121 /** Imports filter settings from the filters and filter elements. */
122 virtual void importAttribs(sal_Int32 nElement, const AttributeList& rAttribs) override;
123 /** Imports filter settings from the FILTERS and FILTER records. */
124 virtual void importRecord(sal_Int32 nRecId, SequenceInputStream& rStrm) override;
126 /** Returns converted UNO API filter settings representing all filter settings. */
127 virtual ApiFilterSettings finalizeImport() override;
129 private:
130 /// Whether we are dealing with the background color (vs. text color)
131 bool mbIsBackgroundColor;
132 /// Style name to retrieve the color from
133 OUString msStyleName;
136 /** A filter criterion for a custom filter. */
137 struct FilterCriterionModel
139 css::uno::Any maValue; /// Comparison operand.
140 sal_Int32 mnOperator; /// Comparison operator.
141 sal_uInt8 mnDataType; /// Operand data type (BIFF only).
143 explicit FilterCriterionModel();
145 /** Sets the passed BIFF operator constant. */
146 void setBiffOperator( sal_uInt8 nOperator );
148 /** Imports the criterion model from the passed BIFF12 stream. */
149 void readBiffData( SequenceInputStream& rStrm );
152 /** Settings for a custom filter, specifying one or two comparison operators
153 associated with some values.
155 class CustomFilter final : public FilterSettingsBase
157 public:
158 explicit CustomFilter( const WorkbookHelper& rHelper );
160 /** Imports filter settings from the filters and filter elements. */
161 virtual void importAttribs( sal_Int32 nElement, const AttributeList& rAttribs ) override;
162 /** Imports filter settings from the FILTERS and FILTER records. */
163 virtual void importRecord( sal_Int32 nRecId, SequenceInputStream& rStrm ) override;
165 /** Returns converted UNO API filter settings representing all filter settings. */
166 virtual ApiFilterSettings finalizeImport() override;
168 private:
169 /** Appends the passed filter criterion, if it contains valid settings. */
170 void appendCriterion( const FilterCriterionModel& rCriterion );
172 private:
173 typedef ::std::vector< FilterCriterionModel > FilterCriterionVector;
175 FilterCriterionVector maCriteria;
176 bool mbAnd;
179 /** A column in a filtered range. Contains an object with specific filter
180 settings for the cells in the column.
182 class FilterColumn final : public WorkbookHelper
184 public:
185 explicit FilterColumn( const WorkbookHelper& rHelper );
187 /** Imports auto filter column settings from the filterColumn element. */
188 void importFilterColumn( const AttributeList& rAttribs );
189 /** Imports auto filter column settings from the FILTERCOLUMN record. */
190 void importFilterColumn( SequenceInputStream& rStrm );
192 /** Creates and returns the specified filter settings object. */
193 template< typename FilterSettingsType >
194 FilterSettingsBase& createFilterSettings()
195 { mxSettings = std::make_shared<FilterSettingsType>( *this ); return *mxSettings; }
197 /** Returns converted UNO API filter settings representing all filter
198 settings of this column. */
199 ApiFilterSettings finalizeImport();
201 private:
202 std::shared_ptr< FilterSettingsBase >
203 mxSettings;
204 sal_Int32 mnColId;
205 bool mbHiddenButton;
206 bool mbShowButton;
209 // class SortCondition
211 class SortCondition final : public WorkbookHelper
213 public:
214 explicit SortCondition( const WorkbookHelper& rHelper );
216 void importSortCondition( const AttributeList& rAttribs, sal_Int16 nSheet );
218 ScRange maRange; // Column/Row that this sort condition applies to.
219 OUString maSortCustomList; // Sort by a custom list.
220 bool mbDescending;
223 // class AutoFilter
225 class AutoFilter final : public WorkbookHelper
227 public:
228 explicit AutoFilter( const WorkbookHelper& rHelper );
230 /** Imports auto filter settings from the autoFilter element. */
231 void importAutoFilter( const AttributeList& rAttribs, sal_Int16 nSheet );
232 /** Imports auto filter settings from the AUTOFILTER record. */
233 void importAutoFilter( SequenceInputStream& rStrm, sal_Int16 nSheet );
235 void importSortState( const AttributeList& rAttribs, sal_Int16 nSheet );
237 /** Creates a new auto filter column and stores it internally. */
238 FilterColumn& createFilterColumn();
240 SortCondition& createSortCondition();
242 /** Applies the filter to the passed filter descriptor. */
243 void finalizeImport( const css::uno::Reference< css::sheet::XDatabaseRange >& rxDatabaseRange,
244 sal_Int16 nSheet );
246 private:
247 typedef RefVector< FilterColumn > FilterColumnVector;
249 FilterColumnVector maFilterColumns;
250 ScRange maRange;
252 ScRange maSortRange; // The whole range of data to sort (not just the sort-by column).
253 typedef RefVector< SortCondition > SortConditionVector;
254 SortConditionVector maSortConditions;
257 class AutoFilterBuffer final : public WorkbookHelper
259 public:
260 explicit AutoFilterBuffer( const WorkbookHelper& rHelper );
262 /** Creates a new auto filter and stores it internally. */
263 AutoFilter& createAutoFilter();
265 /** Applies filter settings to a new database range object (used for sheet
266 autofilter or advanced filter as specified by built-in defined names). */
267 void finalizeImport( sal_Int16 nSheet );
269 /** Applies the filters to the passed database range object.
270 @return True = this buffer contains valid auto filter settings. */
271 bool finalizeImport( const css::uno::Reference< css::sheet::XDatabaseRange >& rxDatabaseRange,
272 sal_Int16 nSheet );
274 private:
275 /** Returns the auto filter object used to perform auto filtering. */
276 AutoFilter* getActiveAutoFilter();
278 private:
279 typedef RefVector< AutoFilter > AutoFilterVector;
280 AutoFilterVector maAutoFilters;
283 } // namespace xls
284 } // namespace oox
286 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */