25#include <com/sun/star/uno/Sequence.hxx>
27#include <osl/diagnose.h>
31using ::com::sun::star::uno::Sequence;
32using ::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!");
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)
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;
338 if (
pData->IsValue() )
342 OUString string (
pData->GetString() );
347 tableData.push_back(row);
351 sal_Int32
nTabSize =
static_cast<sal_Int32
>(tableData.size());
353 auto pTabData = rTabData.getArray();
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;
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;
This class represents the cached data part of the datapilot cache table implementation.
SCROW GetDataSize() const
Data size is the number of records without any trailing empty rows for sheet source data.
const ScDPItemData * GetItemDataById(tools::Long nDim, SCROW nId) const
tools::Long GetDimMemberCount(tools::Long nDim) const
SCROW GetRowCount() const
Row count is the number of records plus any trailing empty rows in case the source data is sheet and ...
SCROW GetItemDataId(sal_uInt16 nDim, SCROW nRow, bool bRepeatIfEmpty) const
OUString GetDimensionName(std::vector< OUString >::size_type nDim) const
tools::Long GetColumnCount() const
virtual std::vector< ScDPItemData > getMatchValues() const override
void addMatchItem(const ScDPItemData &rItem)
virtual bool match(const ScDPItemData &rCellData) const override
returns true if the matching condition is met for a single cell value, or false otherwise.
size_t getMatchItemCount() const
virtual bool match(const ScDPItemData &rCellData) const override
returns true if the matching condition is met for a single cell value, or false otherwise.
virtual std::vector< ScDPItemData > getMatchValues() const override
SingleFilter(const ScDPItemData &rItem)
sal_Int32 getColSize() 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.
RowFlagType maShowByFilter
Rows visible by standard filter query.
const ScDPItemData * getCell(SCCOL nCol, SCROW nRow, bool bRepeatIfEmpty) const
Get the cell instance at specified location within the data grid.
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.
RowFlagType maShowByPage
Rows visible by page dimension filtering.
ScDPFilteredCache(const ScDPCache &rCache)
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.
sal_Int32 getRowSize() const
OUString getFieldName(SCCOL nIndex) const
static void dumpRowFlag(const RowFlagType &rFlag)
const ScDPCache & mrCache
const ::std::vector< SCROW > & getFieldEntries(sal_Int32 nColumn) const
Get the unique entries for a field specified by index.
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.
::std::vector<::std::vector< SCROW > > maFieldEntries
unique field entries for each field (column).
const ScDPCache & getCache() const
When assigning a string value, you can also assign an interned string whose life-cycle is managed by ...
std::unique_ptr< sal_Int32[]> pData
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
TOOLS_DLLPUBLIC SvStream & endl(SvStream &rStr)
void Set(double fV, Type eT)