summaryrefslogtreecommitdiff
path: root/sc/source/core
diff options
context:
space:
mode:
authorSamuel Mehrbrodt <samuel.mehrbrodt@allotropia.de>2021-04-21 09:53:54 +0200
committerSamuel Mehrbrodt <samuel.mehrbrodt@allotropia.de>2021-05-03 09:32:17 +0200
commit5a4bd9bfbdb881368c202bc766f893a5c672621e (patch)
treed3f37369f5085e1f343ebb38c2ed13cd9ed8cc72 /sc/source/core
parent95d8eb87eb20351a2e5795fc8c16653c0f58d6b4 (diff)
tdf#76258 Filter by colors
UI/Logic implementation Change-Id: If7b48219caa466d8a3341bdc4e104d696e8988c5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114385 Tested-by: Jenkins Reviewed-by: Samuel Mehrbrodt <samuel.mehrbrodt@allotropia.de>
Diffstat (limited to 'sc/source/core')
-rw-r--r--sc/source/core/data/column3.cxx28
-rw-r--r--sc/source/core/data/table3.cxx36
-rw-r--r--sc/source/core/tool/queryentry.cxx24
3 files changed, 82 insertions, 6 deletions
diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx
index 7a90c00db4e6..712595aab369 100644
--- a/sc/source/core/data/column3.cxx
+++ b/sc/source/core/data/column3.cxx
@@ -44,6 +44,8 @@
#include <sharedformula.hxx>
#include <listenercontext.hxx>
#include <filterentries.hxx>
+#include <editeng/brushitem.hxx>
+#include <editeng/colritem.hxx>
#include <com/sun/star/i18n/LocaleDataItem2.hpp>
#include <com/sun/star/lang/IllegalArgumentException.hpp>
@@ -2416,16 +2418,26 @@ class FilterEntriesHandler
ScColumn& mrColumn;
ScFilterEntries& mrFilterEntries;
- void processCell(SCROW nRow, ScRefCellValue& rCell)
+ void processCell(ScColumn& rColumn, SCROW nRow, ScRefCellValue& rCell)
{
SvNumberFormatter* pFormatter = mrColumn.GetDoc().GetFormatTable();
OUString aStr;
sal_uLong nFormat = mrColumn.GetNumberFormat(mrColumn.GetDoc().GetNonThreadedContext(), nRow);
ScCellFormat::GetInputString(rCell, nFormat, aStr, *pFormatter, mrColumn.GetDoc(), mrColumn.HasFiltering());
+ // Colors
+ ScAddress aPos(rColumn.GetCol(), nRow, rColumn.GetTab());
+ const SvxColorItem* pColor = rColumn.GetDoc().GetAttr(aPos, ATTR_FONT_COLOR);
+ Color textColor = pColor->GetValue();
+
+ const SvxBrushItem* pBrush = rColumn.GetDoc().GetAttr(aPos, ATTR_BACKGROUND);
+ Color backgroundColor = pBrush->GetColor();
+
if (rCell.hasString())
{
mrFilterEntries.push_back(ScTypedStrData(aStr));
+ mrFilterEntries.addTextColor(textColor);
+ mrFilterEntries.addBackgroundColor(backgroundColor);
return;
}
@@ -2448,6 +2460,8 @@ class FilterEntriesHandler
if (!aErr.isEmpty())
{
mrFilterEntries.push_back(ScTypedStrData(aErr));
+ mrFilterEntries.addTextColor(textColor);
+ mrFilterEntries.addBackgroundColor(backgroundColor);
return;
}
}
@@ -2483,6 +2497,8 @@ class FilterEntriesHandler
}
// maybe extend ScTypedStrData enum is also an option here
mrFilterEntries.push_back(ScTypedStrData(aStr, fVal, ScTypedStrData::Value,bDate));
+ mrFilterEntries.addTextColor(textColor);
+ mrFilterEntries.addBackgroundColor(backgroundColor);
}
public:
@@ -2492,25 +2508,25 @@ public:
void operator() (size_t nRow, double fVal)
{
ScRefCellValue aCell(fVal);
- processCell(nRow, aCell);
+ processCell(mrColumn, nRow, aCell);
}
void operator() (size_t nRow, const svl::SharedString& rStr)
{
ScRefCellValue aCell(&rStr);
- processCell(nRow, aCell);
+ processCell(mrColumn, nRow, aCell);
}
void operator() (size_t nRow, const EditTextObject* p)
{
ScRefCellValue aCell(p);
- processCell(nRow, aCell);
+ processCell(mrColumn, nRow, aCell);
}
void operator() (size_t nRow, const ScFormulaCell* p)
{
ScRefCellValue aCell(const_cast<ScFormulaCell*>(p));
- processCell(nRow, aCell);
+ processCell(mrColumn, nRow, aCell);
}
void operator() (const int nElemType, size_t nRow, size_t /* nDataSize */)
@@ -2525,7 +2541,7 @@ public:
return;
}
ScRefCellValue aCell = mrColumn.GetCellValue(nRow);
- processCell(nRow, aCell);
+ processCell(mrColumn, nRow, aCell);
}
};
diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx
index 93cd3f9dd5b2..dcc76104280b 100644
--- a/sc/source/core/data/table3.cxx
+++ b/sc/source/core/data/table3.cxx
@@ -19,6 +19,8 @@
#include <comphelper/processfactory.hxx>
#include <comphelper/random.hxx>
+#include <editeng/brushitem.hxx>
+#include <editeng/colritem.hxx>
#include <unotools/textsearch.hxx>
#include <svl/zforlist.hxx>
#include <svl/zformat.hxx>
@@ -2695,6 +2697,26 @@ public:
return std::pair<bool,bool>(bOk, bTestEqual);
}
+ std::pair<bool, bool> compareByTextColor(SCCOL nCol, SCROW nRow, SCTAB nTab,
+ const ScQueryEntry::Item& rItem)
+ {
+ ScAddress aPos(nCol, nRow, nTab);
+ const SvxColorItem* pColor = mrDoc.GetAttr(aPos, ATTR_FONT_COLOR);
+ Color color = pColor->GetValue();
+ bool bMatch = rItem.maColor == color;
+ return std::pair<bool, bool>(bMatch, false);
+ }
+
+ std::pair<bool, bool> compareByBackgroundColor(SCCOL nCol, SCROW nRow, SCTAB nTab,
+ const ScQueryEntry::Item& rItem)
+ {
+ ScAddress aPos(nCol, nRow, nTab);
+ const SvxBrushItem* pBrush = mrDoc.GetAttr(aPos, ATTR_BACKGROUND);
+ Color color = pBrush->GetColor();
+ bool bMatch = rItem.maColor == color;
+ return std::pair<bool, bool>(bMatch, false);
+ }
+
// To be called only if both isQueryByValue() and isQueryByString()
// returned false and range lookup is wanted! In range lookup comparison
// numbers are less than strings. Nothing else is compared.
@@ -2809,6 +2831,20 @@ bool ScTable::ValidQuery(
aRes.first |= aThisRes.first;
aRes.second |= aThisRes.second;
}
+ if (rItem.meType == ScQueryEntry::ByTextColor)
+ {
+ std::pair<bool, bool> aThisRes
+ = aEval.compareByTextColor(nCol, nRow, nTab, rItem);
+ aRes.first |= aThisRes.first;
+ aRes.second |= aThisRes.second;
+ }
+ if (rItem.meType == ScQueryEntry::ByBackgroundColor)
+ {
+ std::pair<bool,bool> aThisRes =
+ aEval.compareByBackgroundColor(nCol, nRow, nTab, rItem);
+ aRes.first |= aThisRes.first;
+ aRes.second |= aThisRes.second;
+ }
else if (rParam.mbRangeLookup)
{
std::pair<bool,bool> aThisRes =
diff --git a/sc/source/core/tool/queryentry.cxx b/sc/source/core/tool/queryentry.cxx
index a295759e0c3c..836b2caf7dd8 100644
--- a/sc/source/core/tool/queryentry.cxx
+++ b/sc/source/core/tool/queryentry.cxx
@@ -29,6 +29,8 @@
#define SC_EMPTYFIELDS (double(0x0042))
#define SC_NONEMPTYFIELDS (double(0x0043))
+#define SC_TEXTCOLOR (double(0x0044))
+#define SC_BACKGROUNDCOLOR (double(0x0045))
bool ScQueryEntry::Item::operator== (const Item& r) const
{
@@ -115,6 +117,28 @@ bool ScQueryEntry::IsQueryByNonEmpty() const
rItem.mfVal == SC_NONEMPTYFIELDS;
}
+void ScQueryEntry::SetQueryByTextColor(Color color)
+{
+ eOp = SC_EQUAL;
+ maQueryItems.resize(1);
+ Item& rItem = maQueryItems[0];
+ rItem.meType = ByTextColor;
+ rItem.maString = svl::SharedString();
+ rItem.mfVal = SC_TEXTCOLOR;
+ rItem.maColor = color;
+}
+
+void ScQueryEntry::SetQueryByBackgroundColor(Color color)
+{
+ eOp = SC_EQUAL;
+ maQueryItems.resize(1);
+ Item& rItem = maQueryItems[0];
+ rItem.meType = ByBackgroundColor;
+ rItem.maString = svl::SharedString();
+ rItem.mfVal = SC_BACKGROUNDCOLOR;
+ rItem.maColor = color;
+}
+
ScQueryEntry::Item& ScQueryEntry::GetQueryItemImpl() const
{
if (maQueryItems.size() != 1)