offapi/UnoApi_offapi.mk | 1 offapi/com/sun/star/sheet/FilterFieldType.idl | 40 +++++++++++++ offapi/com/sun/star/sheet/FilterFieldValue.idl | 24 ++++++++ sc/source/filter/inc/autofilterbuffer.hxx | 23 +++++++ sc/source/filter/oox/autofilterbuffer.cxx | 74 +++++++++++++++++++++++-- sc/source/filter/oox/autofiltercontext.cxx | 5 + sc/source/ui/unoobj/datauno.cxx | 26 ++++++++ 7 files changed, 189 insertions(+), 4 deletions(-)
New commits: commit 594989639f120ed058cfc2bd5defc161ad67d474 Author: Samuel Mehrbrodt <samuel.mehrbr...@allotropia.de> AuthorDate: Thu May 6 09:12:05 2021 +0200 Commit: Thorsten Behrens <thorsten.behr...@allotropia.de> CommitDate: Mon Jun 28 10:54:22 2021 +0200 tdf#76258 Add OOXML import for color filter Change-Id: I74cf4f56e0adf1cb8af8e6e932c14b30cce67c71 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115168 Tested-by: Jenkins Reviewed-by: Samuel Mehrbrodt <samuel.mehrbr...@allotropia.de> (cherry picked from commit 3c8b248b5a7395b174fc265e3237bd79aeb2455f) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116600 Reviewed-by: Thorsten Behrens <thorsten.behr...@allotropia.de> Tested-by: Thorsten Behrens <thorsten.behr...@allotropia.de> diff --git a/offapi/UnoApi_offapi.mk b/offapi/UnoApi_offapi.mk index 12ab8e2057e9..c360c7e5f270 100644 --- a/offapi/UnoApi_offapi.mk +++ b/offapi/UnoApi_offapi.mk @@ -3413,6 +3413,7 @@ $(eval $(call gb_UnoApi_add_idlfiles,offapi,com/sun/star/sheet,\ FillMode \ FilterConnection \ FilterFieldValue \ + FilterFieldType \ FilterOperator \ FilterOperator2 \ FormulaLanguage \ diff --git a/offapi/com/sun/star/sheet/FilterFieldType.idl b/offapi/com/sun/star/sheet/FilterFieldType.idl new file mode 100644 index 000000000000..0a5113c7a075 --- /dev/null +++ b/offapi/com/sun/star/sheet/FilterFieldType.idl @@ -0,0 +1,40 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef __com_sun_star_sheet_FilterFieldType_idl__ +#define __com_sun_star_sheet_FilterFieldType_idl__ + +module com { module sun { module star { module sheet { + +/** + * @since LibreOffice 7.2 + */ +constants FilterFieldType +{ + /** Filter by numeric value */ + const short NUMERIC = 0; + + /** Filter by string value */ + const short STRING = 1; + + /** Filter by date */ + const short DATE = 2; + + /** Filter by text color */ + const short TEXT_COLOR = 3; + + /** Filter by background color */ + const short BACKGROUND_COLOR = 4; +}; + +}; }; }; }; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/offapi/com/sun/star/sheet/FilterFieldValue.idl b/offapi/com/sun/star/sheet/FilterFieldValue.idl index 5d1b40837476..12e9b8ba62e8 100644 --- a/offapi/com/sun/star/sheet/FilterFieldValue.idl +++ b/offapi/com/sun/star/sheet/FilterFieldValue.idl @@ -19,6 +19,8 @@ struct FilterFieldValue { /** selects whether the TableFilterFieldValue::NumericValue or the TableFilterFieldValue::StringValue is used. + + @deprecated - Use FilterType instead. */ boolean IsNumeric; @@ -29,6 +31,28 @@ struct FilterFieldValue /** specifies a string value for the condition. */ string StringValue; + + /** Which field should be used for filtering: + + <ul> + <li>com::sun::star::sheet::FilterFieldType::NUMERIC -> NumericValue</li> + <li>com::sun::star::sheet::FilterFieldType::STRING -> StringValue</li> + <li>com::sun::star::sheet::FilterFieldType::DATE -> StringValue</li> + <li>com::sun::star::sheet::FilterFieldType::TEXT_COLOR -> ColorValue</li> + <li>com::sun::star::sheet::FilterFieldType::BACKGROUND_COLOR -> ColorValue</li> + </ul> + + @see com::sun::star::sheet::FilterFieldType + @since LibreOffice 7.2 + */ + short FilterType; + + /** The color which is used for filtering + + @since LibreOffice 7.2 + */ + com::sun::star::util::Color ColorValue; + }; }; }; }; }; diff --git a/sc/source/filter/inc/autofilterbuffer.hxx b/sc/source/filter/inc/autofilterbuffer.hxx index ae8e8b4fa2a0..cf3593de5e63 100644 --- a/sc/source/filter/inc/autofilterbuffer.hxx +++ b/sc/source/filter/inc/autofilterbuffer.hxx @@ -24,6 +24,7 @@ #include <oox/helper/refvector.hxx> #include "workbookhelper.hxx" #include <com/sun/star/sheet/TableFilterField3.hpp> +#include <com/sun/star/util/Color.hpp> namespace com { namespace sun { namespace star { namespace sheet { class XDatabaseRange; } @@ -49,6 +50,7 @@ struct ApiFilterSettings void appendField( bool bAnd, sal_Int32 nOperator, double fValue ); void appendField( bool bAnd, sal_Int32 nOperator, const OUString& rValue ); void appendField( bool bAnd, const std::vector<OUString>& rValues ); + void appendField( bool bAnd, css::util::Color aColor, bool bIsBackgroundColor ); }; /** Base class for specific filter settings for a column in a filtered range. @@ -111,6 +113,27 @@ private: bool mbPercent; /// True = percentage, false = number of items. }; +/** Settings for a color filter. */ +class ColorFilter : public FilterSettingsBase +{ +public: + explicit ColorFilter(const WorkbookHelper& rHelper); + + /** Imports filter settings from the filters and filter elements. */ + virtual void importAttribs(sal_Int32 nElement, const AttributeList& rAttribs) override; + /** Imports filter settings from the FILTERS and FILTER records. */ + virtual void importRecord(sal_Int32 nRecId, SequenceInputStream& rStrm) override; + + /** Returns converted UNO API filter settings representing all filter settings. */ + virtual ApiFilterSettings finalizeImport(sal_Int32 nMaxCount) override; + +private: + /// Whether we are dealing with the background color (vs. text color) + bool mbIsBackgroundColor; + /// Style name to retrieve the color from + OUString msStyleName; +}; + /** A filter criterion for a custom filter. */ struct FilterCriterionModel { diff --git a/sc/source/filter/oox/autofilterbuffer.cxx b/sc/source/filter/oox/autofilterbuffer.cxx index 8209df526283..f433456fb369 100644 --- a/sc/source/filter/oox/autofilterbuffer.cxx +++ b/sc/source/filter/oox/autofilterbuffer.cxx @@ -20,6 +20,7 @@ #include <autofilterbuffer.hxx> #include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/sheet/FilterFieldType.hpp> #include <com/sun/star/sheet/FilterConnection.hpp> #include <com/sun/star/sheet/FilterOperator2.hpp> #include <com/sun/star/sheet/TableFilterField3.hpp> @@ -27,6 +28,8 @@ #include <com/sun/star/sheet/XSheetFilterDescriptor3.hpp> #include <com/sun/star/table/TableOrientation.hpp> #include <com/sun/star/table/CellAddress.hpp> +#include <editeng/colritem.hxx> +#include <editeng/brushitem.hxx> #include <rtl/ustrbuf.hxx> #include <osl/diagnose.h> #include <oox/helper/attributelist.hxx> @@ -41,12 +44,17 @@ #include <biffhelper.hxx> #include <document.hxx> #include <dbdata.hxx> +#include <scitems.hxx> #include <sortparam.hxx> +#include <stlpool.hxx> +#include <stlsheet.hxx> +#include <stylesbuffer.hxx> #include <userlist.hxx> namespace oox { namespace xls { +using namespace css; using namespace ::com::sun::star::sheet; using namespace ::com::sun::star::table; using namespace ::com::sun::star::uno; @@ -161,7 +169,7 @@ void ApiFilterSettings::appendField( bool bAnd, sal_Int32 nOperator, double fVal rFilterField.Connection = bAnd ? FilterConnection_AND : FilterConnection_OR; rFilterField.Operator = nOperator; rFilterField.Values.realloc(1); - rFilterField.Values[0].IsNumeric = true; + rFilterField.Values[0].FilterType = FilterFieldType::NUMERIC; rFilterField.Values[0].NumericValue = fValue; } @@ -172,7 +180,7 @@ void ApiFilterSettings::appendField( bool bAnd, sal_Int32 nOperator, const OUStr rFilterField.Connection = bAnd ? FilterConnection_AND : FilterConnection_OR; rFilterField.Operator = nOperator; rFilterField.Values.realloc(1); - rFilterField.Values[0].IsNumeric = false; + rFilterField.Values[0].FilterType = FilterFieldType::STRING; rFilterField.Values[0].StringValue = rValue; } @@ -186,11 +194,23 @@ void ApiFilterSettings::appendField( bool bAnd, const std::vector<OUString>& rVa rFilterField.Values.realloc(n); for (size_t i = 0; i < n; ++i) { - rFilterField.Values[i].IsNumeric = false; + rFilterField.Values[i].FilterType = FilterFieldType::STRING; rFilterField.Values[i].StringValue = rValues[i]; } } +void ApiFilterSettings::appendField(bool bAnd, util::Color aColor, bool bIsBackgroundColor) +{ + maFilterFields.emplace_back(); + TableFilterField3& rFilterField = maFilterFields.back(); + rFilterField.Connection = bAnd ? FilterConnection_AND : FilterConnection_OR; + rFilterField.Operator = FilterOperator2::EQUAL; + rFilterField.Values.realloc(1); + rFilterField.Values[0].FilterType + = bIsBackgroundColor ? FilterFieldType::BACKGROUND_COLOR : FilterFieldType::TEXT_COLOR; + rFilterField.Values[0].ColorValue = aColor; +} + FilterSettingsBase::FilterSettingsBase( const WorkbookHelper& rHelper ) : WorkbookHelper( rHelper ) { @@ -325,6 +345,54 @@ ApiFilterSettings Top10Filter::finalizeImport( sal_Int32 /*nMaxCount*/ ) return aSettings; } +ColorFilter::ColorFilter(const WorkbookHelper& rHelper) + : FilterSettingsBase(rHelper) +{ +} + +void ColorFilter::importAttribs(sal_Int32 nElement, const AttributeList& rAttribs) +{ + if (nElement == XLS_TOKEN(colorFilter)) + { + // When cellColor attribute not found, it means cellColor = true + // cellColor = 0 (false) -> TextColor + // cellColor = 1 (true) -> BackgroundColor + mbIsBackgroundColor = rAttribs.getBool(XML_cellColor, true); + msStyleName = getStyles().createDxfStyle( rAttribs.getInteger(XML_dxfId, -1) ); + } +} + +void ColorFilter::importRecord(sal_Int32 /* nRecId */, SequenceInputStream& /* rStrm */) +{ + // TODO +} + +ApiFilterSettings ColorFilter::finalizeImport(sal_Int32 /*nMaxCount*/) +{ + ApiFilterSettings aSettings; + ScDocument& rDoc = getScDocument(); + ScStyleSheet* pStyleSheet = static_cast<ScStyleSheet*>( + rDoc.GetStyleSheetPool()->Find(msStyleName, SfxStyleFamily::Para)); + if (!pStyleSheet) + return aSettings; + + const SfxItemSet& rItemSet = pStyleSheet->GetItemSet(); + ::Color aColor; + if (mbIsBackgroundColor) + { + const SvxBrushItem* pItem = rItemSet.GetItem<SvxBrushItem>(ATTR_BACKGROUND); + aColor = pItem->GetColor(); + } + else + { + const SvxColorItem* pItem = rItemSet.GetItem<SvxColorItem>(ATTR_FONT_COLOR); + aColor = pItem->GetValue(); + } + util::Color nColor(aColor); + aSettings.appendField(true, nColor, mbIsBackgroundColor); + return aSettings; +} + FilterCriterionModel::FilterCriterionModel() : mnOperator( XML_equal ), mnDataType( BIFF_FILTER_DATATYPE_NONE ) diff --git a/sc/source/filter/oox/autofiltercontext.cxx b/sc/source/filter/oox/autofiltercontext.cxx index 814569e0b45f..550e0f69e5fe 100644 --- a/sc/source/filter/oox/autofiltercontext.cxx +++ b/sc/source/filter/oox/autofiltercontext.cxx @@ -44,6 +44,9 @@ ContextHandlerRef FilterSettingsContext::onCreateContext( sal_Int32 nElement, co case XLS_TOKEN( customFilters ): if( nElement == XLS_TOKEN( customFilter ) ) return this; break; + case XLS_TOKEN( colorFilter ): + if( nElement == XLS_TOKEN( colorFilter ) ) return this; + break; } return nullptr; } @@ -88,6 +91,8 @@ ContextHandlerRef FilterColumnContext::onCreateContext( sal_Int32 nElement, cons return new FilterSettingsContext( *this, mrFilterColumn.createFilterSettings< Top10Filter >() ); case XLS_TOKEN( customFilters ): return new FilterSettingsContext( *this, mrFilterColumn.createFilterSettings< CustomFilter >() ); + case XLS_TOKEN( colorFilter ): + return new FilterSettingsContext( *this, mrFilterColumn.createFilterSettings< ColorFilter >() ); } return nullptr; } diff --git a/sc/source/ui/unoobj/datauno.cxx b/sc/source/ui/unoobj/datauno.cxx index 596da506ad14..03d84526d102 100644 --- a/sc/source/ui/unoobj/datauno.cxx +++ b/sc/source/ui/unoobj/datauno.cxx @@ -34,6 +34,7 @@ #include <com/sun/star/table/TableOrientation.hpp> #include <com/sun/star/table/CellRangeAddress.hpp> #include <com/sun/star/sheet/DataImportMode.hpp> +#include <com/sun/star/sheet/FilterFieldType.hpp> #include <com/sun/star/sheet/FilterOperator2.hpp> #include <com/sun/star/sheet/TableFilterField2.hpp> @@ -63,6 +64,7 @@ #include <memory> using namespace com::sun::star; +using namespace css::sheet; // everything without Which-ID, map only for PropertySetInfo @@ -1122,7 +1124,24 @@ void fillQueryParam( for (const auto& rVal : rVals) { ScQueryEntry::Item aItem; - aItem.meType = rVal.IsNumeric ? ScQueryEntry::ByValue : ScQueryEntry::ByString; + switch (rVal.FilterType) + { + case FilterFieldType::NUMERIC: + aItem.meType = ScQueryEntry::ByValue; + break; + case FilterFieldType::STRING: + aItem.meType = ScQueryEntry::ByString; + break; + case FilterFieldType::DATE: + aItem.meType = ScQueryEntry::ByDate; + break; + case FilterFieldType::TEXT_COLOR: + aItem.meType = ScQueryEntry::ByTextColor; + break; + case FilterFieldType::BACKGROUND_COLOR: + aItem.meType = ScQueryEntry::ByBackgroundColor; + break; + } aItem.mfVal = rVal.NumericValue; aItem.maString = rPool.intern(rVal.StringValue); @@ -1132,6 +1151,11 @@ void fillQueryParam( pDoc->GetFormatTable()->GetInputLineString(aItem.mfVal, 0, aStr); aItem.maString = rPool.intern(aStr); } + else if (aItem.meType == ScQueryEntry::ByTextColor + || aItem.meType == ScQueryEntry::ByBackgroundColor) + { + aItem.maColor = Color(rVal.ColorValue); + } rItems.push_back(aItem); } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits