summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorSamuel Mehrbrodt <samuel.mehrbrodt@allotropia.de>2021-05-06 09:12:05 +0200
committerSamuel Mehrbrodt <samuel.mehrbrodt@allotropia.de>2021-05-11 09:17:13 +0200
commit3c8b248b5a7395b174fc265e3237bd79aeb2455f (patch)
tree9cad940a0791d4f2977597f860a0cba8de8faafa /sc
parent3595670c9082639b3efcd8d9426e4909b8fa212a (diff)
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.mehrbrodt@allotropia.de>
Diffstat (limited to 'sc')
-rw-r--r--sc/source/filter/inc/autofilterbuffer.hxx23
-rw-r--r--sc/source/filter/oox/autofilterbuffer.cxx76
-rw-r--r--sc/source/filter/oox/autofiltercontext.cxx5
-rw-r--r--sc/source/ui/unoobj/datauno.cxx26
4 files changed, 125 insertions, 5 deletions
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