offapi/UnoApi_offapi.mk                        |    1 
 offapi/com/sun/star/sheet/FilterFieldType.idl  |   40 +++++++++++++
 offapi/com/sun/star/sheet/FilterFieldValue.idl |   23 ++++++-
 sc/source/filter/inc/autofilterbuffer.hxx      |   23 +++++++
 sc/source/filter/oox/autofilterbuffer.cxx      |   76 +++++++++++++++++++++++--
 sc/source/filter/oox/autofiltercontext.cxx     |    5 +
 sc/source/ui/unoobj/datauno.cxx                |   26 ++++++++
 7 files changed, 186 insertions(+), 8 deletions(-)

New commits:
commit 3c8b248b5a7395b174fc265e3237bd79aeb2455f
Author:     Samuel Mehrbrodt <samuel.mehrbr...@allotropia.de>
AuthorDate: Thu May 6 09:12:05 2021 +0200
Commit:     Samuel Mehrbrodt <samuel.mehrbr...@allotropia.de>
CommitDate: Tue May 11 09:17:13 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>

diff --git a/offapi/UnoApi_offapi.mk b/offapi/UnoApi_offapi.mk
index c958419b7aa3..3abfc388ba95 100644
--- a/offapi/UnoApi_offapi.mk
+++ b/offapi/UnoApi_offapi.mk
@@ -3422,6 +3422,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 2e3ba927dc97..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;
 
@@ -30,12 +32,27 @@ struct FilterFieldValue
      */
     string StringValue;
 
-    /** specifies whether the TableFilterFieldValue::StringValue
-        is a string value or a date value.
+    /** 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
      */
-    boolean IsDateValue;
+    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 8af001d24db4..0f9135be7123 100644
--- a/sc/source/filter/inc/autofilterbuffer.hxx
+++ b/sc/source/filter/inc/autofilterbuffer.hxx
@@ -23,6 +23,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::sun::star {
     namespace sheet { class XDatabaseRange; }
@@ -47,6 +48,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, css::util::Color aColor, bool 
bIsBackgroundColor );
     void appendField( bool bAnd, const std::vector<std::pair<OUString, bool>>& 
rValues );
 };
 
@@ -110,6 +112,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() 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 b75c05f65f19..6e205a032b24 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,11 +44,16 @@
 #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::xls {
 
+using namespace css;
 using namespace ::com::sun::star::sheet;
 using namespace ::com::sun::star::table;
 using namespace ::com::sun::star::uno;
@@ -160,7 +168,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;
 }
 
@@ -171,10 +179,22 @@ 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;
 }
 
+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;
+}
+
 void ApiFilterSettings::appendField( bool bAnd, const 
std::vector<std::pair<OUString, bool>>& rValues )
 {
     maFilterFields.emplace_back();
@@ -186,9 +206,9 @@ void ApiFilterSettings::appendField( bool bAnd, const 
std::vector<std::pair<OUSt
 
     for( auto const& it : rValues )
     {
-        rFilterField.Values[i].IsNumeric = false;
         rFilterField.Values[i].StringValue = it.first;
-        rFilterField.Values[i++].IsDateValue = it.second;
+        rFilterField.Values[i++].FilterType
+            = it.second ? FilterFieldType::DATE : FilterFieldType::STRING;
     }
 }
 
@@ -382,6 +402,54 @@ ApiFilterSettings Top10Filter::finalizeImport()
     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()
+{
+    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 5dd3a6b34b28..9cdbacea4e92 100644
--- a/sc/source/filter/oox/autofiltercontext.cxx
+++ b/sc/source/filter/oox/autofiltercontext.cxx
@@ -43,6 +43,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;
 }
@@ -87,6 +90,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 3d149d3567d2..4691b7082326 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>
 
@@ -64,6 +65,7 @@
 #include <memory>
 
 using namespace com::sun::star;
+using namespace css::sheet;
 
 //  everything without Which-ID, map only for PropertySetInfo
 
@@ -1124,7 +1126,24 @@ void fillQueryParam(
             for (const auto& rVal : rVals)
             {
                 ScQueryEntry::Item aItem;
-                aItem.meType   = rVal.IsNumeric ? ScQueryEntry::ByValue : 
(rVal.IsDateValue ? ScQueryEntry::ByDate : 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);
 
@@ -1151,6 +1170,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(ColorTransparency, rVal.ColorValue);
+                }
 
                 // filter all dates starting with the given date filter YYYY 
or YYYY-MM and filter all datetimes
                 // starting with the given datetime filter YYYY-MM-DD, 
YYYY-MM-DD HH, or YYYY-MM-DD HH:MM
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to