25 #include <com/sun/star/uno/Sequence.hxx>
27 #include <osl/diagnose.h>
31 using ::com::sun::star::uno::Sequence;
32 using ::com::sun::star::uno::Any;
39 return maItem == rCellData;
53 return std::find(maItems.begin(), maItems.end(), rCellData) != maItems.end();
63 maItems.push_back(rItem);
68 return maItems.size();
96 const ScQueryParam& rQuery,
bool bIgnoreEmptyRows,
bool bRepeatIfEmpty)
101 if (nRowCount <= 0 || nColCount <= 0)
109 for (
SCROW nRow = 0; nRow < nDataSize; ++nRow)
111 if (!
getCache().ValidQuery(nRow, rQuery))
114 if (bIgnoreEmptyRows &&
getCache().IsRowEmpty(nRow))
121 if (!bIgnoreEmptyRows)
131 for (
SCCOL nCol = 0; nCol < nColCount; ++nCol)
138 std::vector<SCROW> aAdded(nMemCount, -1);
140 SCROW nEndSegment = -1;
141 for (
SCROW nRow = 0; nRow < nRowCount; ++nRow)
143 if (nRow > nEndSegment)
145 if (!
maShowByFilter.search_tree(nRow, bShow,
nullptr, &nEndSegment).second)
147 OSL_FAIL(
"Tree search failed!");
160 aAdded[nIndex] = nIndex;
164 if (nRow == nDataSize)
167 for (
SCROW nRow = 0; nRow < nMemCount; ++nRow)
169 if (aAdded[nRow] != -1)
179 if (nRowCount <= 0 || nColCount <= 0)
194 for (
SCCOL nCol = 0; nCol < nColCount; ++nCol)
201 std::vector<SCROW> aAdded(nMemCount, -1);
203 for (
SCROW nRow = 0; nRow < nRowCount; ++nRow)
206 aAdded[nIndex] = nIndex;
208 for (
SCROW nRow = 0; nRow < nMemCount; ++nRow)
210 if (aAdded[nRow] != -1)
218 bool bFilter =
false, bPage =
true;
220 maShowByFilter.search_tree(nRow, bFilter,
nullptr, &nLastRowFilter);
221 maShowByPage.search_tree(nRow, bPage,
nullptr, &nLastRowPage);
225 *pLastRow = std::min(nLastRowFilter, nLastRowPage);
229 return bFilter && bPage;
239 for (
SCROW nRow = 0; nRow < nDataSize; ++nRow)
246 if (nDataSize < nRowSize)
248 bool bBlankShow =
isRowQualified(nDataSize, rCriteria, rRepeatIfEmptyDims);
249 maShowByPage.insert_back(nDataSize, nRowSize, bBlankShow);
284 static const ::std::vector<SCROW> emptyEntries{};
291 const std::unordered_set<sal_Int32>& rRepeatIfEmptyDims)
301 vector< Sequence<Any> > tableData;
302 tableData.reserve(nRowSize+1);
305 Sequence<Any> headerRow(nColSize);
306 auto pRow = headerRow.getArray();
307 for (
SCCOL nCol = 0; nCol < nColSize; ++nCol)
314 tableData.push_back(headerRow);
316 for (sal_Int32 nRow = 0; nRow < nRowSize; ++nRow)
331 Sequence<Any> row(nColSize);
332 pRow = row.getArray();
333 for (
SCCOL nCol = 0; nCol < nColSize; ++nCol)
336 bool bRepeatIfEmpty = rRepeatIfEmptyDims.count(nCol) > 0;
347 tableData.push_back(row);
351 sal_Int32
nTabSize =
static_cast<sal_Int32
>(tableData.size());
352 rTabData.realloc(nTabSize);
353 auto pTabData = rTabData.getArray();
354 for (sal_Int32
i = 0;
i < nTabSize; ++
i)
355 pTabData[
i] = tableData[
i];
371 const std::unordered_set<sal_Int32>& rRepeatIfEmptyDims)
const
374 for (
const auto& rCriterion : rCriteria)
376 if (rCriterion.mnFieldIndex >= nColSize)
382 bool bRepeatIfEmpty = rRepeatIfEmptyDims.count(rCriterion.mnFieldIndex) > 0;
383 const ScDPItemData* pCellData =
getCell(static_cast<SCCOL>(rCriterion.mnFieldIndex), nRow, bRepeatIfEmpty);
384 if (!rCriterion.mpFilter->match(*pCellData))
394 RowFlagType::const_iterator it = rFlag.begin(), itEnd = rFlag.end();
395 bool bShow = it->second;
396 SCROW nRow1 = it->first;
397 for (++it; it != itEnd; ++it)
399 SCROW nRow2 = it->first;
400 cout <<
" * range " << nRow1 <<
"-" << nRow2 <<
": " << (bShow ?
"on" :
"off") << endl;
408 cout <<
"--- pivot filtered cache dump" <<
endl;
411 cout <<
"* show by filter" << endl;
415 cout <<
"* show by page dimensions" << endl;
419 cout <<
"* field entries" << endl;
421 for (
size_t i = 0;
i < nFieldCount; ++
i)
424 cout <<
" * field " <<
i << endl;
425 for (
size_t j = 0, n = rField.size(); j <
n; ++j)
426 cout <<
" ID: " << rField[j] << endl;
428 cout <<
"---" << endl;
OUString getFieldName(SCCOL nIndex) const
virtual std::vector< ScDPItemData > getMatchValues() const override
virtual bool match(const ScDPItemData &rCellData) const override
returns true if the matching condition is met for a single cell value, or false otherwise.
tools::Long GetDimMemberCount(tools::Long nDim) const
OUString GetDimensionName(std::vector< OUString >::size_type nDim) const
sal_Int32 getRowSize() const
void filterTable(const std::vector< Criterion > &rCriteria, css::uno::Sequence< css::uno::Sequence< css::uno::Any >> &rTabData, const std::unordered_set< sal_Int32 > &rRepeatIfEmptyDims)
Filter the table based on the specified criteria, and copy the result to rTabData.
std::unique_ptr< sal_Int32[]> pData
size_t getMatchItemCount() const
This class represents the cached data part of the datapilot cache table implementation.
SCROW GetItemDataId(sal_uInt16 nDim, SCROW nRow, bool bRepeatIfEmpty) const
static void dumpRowFlag(const RowFlagType &rFlag)
SCROW GetRowCount() const
Row count is the number of records plus any trailing empty rows in case the source data is sheet and ...
const ScDPItemData * GetItemDataById(tools::Long nDim, SCROW nId) const
void getValue(ScDPValue &rVal, SCCOL nCol, SCROW nRow) const
bool isRowActive(sal_Int32 nRow, sal_Int32 *pLastRow=nullptr) const
Check whether a specified row is active or not.
virtual bool match(const ScDPItemData &rCellData) const override
returns true if the matching condition is met for a single cell value, or false otherwise.
When assigning a string value, you can also assign an interned string whose life-cycle is managed by ...
ScDPFilteredCache(const ScDPCache &rCache)
const ScDPItemData * getCell(SCCOL nCol, SCROW nRow, bool bRepeatIfEmpty) const
Get the cell instance at specified location within the data grid.
SCROW GetDataSize() const
Data size is the number of records without any trailing empty rows for sheet source data...
::std::vector<::std::vector< SCROW > > maFieldEntries
unique field entries for each field (column).
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
tools::Long GetColumnCount() const
void addMatchItem(const ScDPItemData &rItem)
RowFlagType maShowByPage
Rows visible by page dimension filtering.
RowFlagType maShowByFilter
Rows visible by standard filter query.
sal_Int32 getColSize() const
bool isRowQualified(sal_Int32 nRow, const ::std::vector< Criterion > &rCriteria, const std::unordered_set< sal_Int32 > &rRepeatIfEmptyDims) const
Check if a given row meets all specified criteria.
SvStream & endl(SvStream &rStr)
virtual std::vector< ScDPItemData > getMatchValues() const override
const ::std::vector< SCROW > & getFieldEntries(sal_Int32 nColumn) const
Get the unique entries for a field specified by index.
SingleFilter(const ScDPItemData &rItem)
OUString GetString() const
ScDPValue::Type GetCellType() const
const ScDPCache & mrCache
void filterByPageDimension(const std::vector< Criterion > &rCriteria, const std::unordered_set< sal_Int32 > &rRepeatIfEmptyDims)
Set filter on/off flag to each row to control visibility.
void Set(double fV, Type eT)
const ScDPCache & getCache() const
bool m_bDetectedRangeSegmentation false