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;
44 std::vector<ScDPItemData> aValues;
45 aValues.push_back(maItem);
55 return std::find(maItems.begin(), maItems.end(), rCellData) != maItems.end();
65 maItems.push_back(rItem);
70 return maItems.size();
98 const ScQueryParam& rQuery,
bool bIgnoreEmptyRows,
bool bRepeatIfEmpty)
103 if (nRowCount <= 0 || nColCount <= 0)
111 for (
SCROW nRow = 0; nRow < nDataSize; ++nRow)
113 if (!
getCache().ValidQuery(nRow, rQuery))
116 if (bIgnoreEmptyRows &&
getCache().IsRowEmpty(nRow))
123 if (!bIgnoreEmptyRows)
133 for (
SCCOL nCol = 0; nCol < nColCount; ++nCol)
140 std::vector<SCROW> aAdded(nMemCount, -1);
142 SCROW nEndSegment = -1;
143 for (
SCROW nRow = 0; nRow < nRowCount; ++nRow)
145 if (nRow > nEndSegment)
147 if (!
maShowByFilter.search_tree(nRow, bShow,
nullptr, &nEndSegment).second)
149 OSL_FAIL(
"Tree search failed!");
162 aAdded[nIndex] = nIndex;
166 if (nRow == nDataSize)
169 for (
SCROW nRow = 0; nRow < nMemCount; ++nRow)
171 if (aAdded[nRow] != -1)
181 if (nRowCount <= 0 || nColCount <= 0)
196 for (
SCCOL nCol = 0; nCol < nColCount; ++nCol)
203 std::vector<SCROW> aAdded(nMemCount, -1);
205 for (
SCROW nRow = 0; nRow < nRowCount; ++nRow)
208 aAdded[nIndex] = nIndex;
210 for (
SCROW nRow = 0; nRow < nMemCount; ++nRow)
212 if (aAdded[nRow] != -1)
220 bool bFilter =
false, bPage =
true;
222 maShowByFilter.search_tree(nRow, bFilter,
nullptr, &nLastRowFilter);
223 maShowByPage.search_tree(nRow, bPage,
nullptr, &nLastRowPage);
227 *pLastRow = std::min(nLastRowFilter, nLastRowPage);
231 return bFilter && bPage;
241 for (
SCROW nRow = 0; nRow < nDataSize; ++nRow)
248 if (nDataSize < nRowSize)
250 bool bBlankShow =
isRowQualified(nDataSize, rCriteria, rRepeatIfEmptyDims);
251 maShowByPage.insert_back(nDataSize, nRowSize, bBlankShow);
286 static const ::std::vector<SCROW> emptyEntries{};
293 const std::unordered_set<sal_Int32>& rRepeatIfEmptyDims)
303 vector< Sequence<Any> > tableData;
304 tableData.reserve(nRowSize+1);
307 Sequence<Any> headerRow(nColSize);
308 for (
SCCOL nCol = 0; nCol < nColSize; ++nCol)
313 headerRow[nCol] = any;
315 tableData.push_back(headerRow);
317 for (sal_Int32 nRow = 0; nRow < nRowSize; ++nRow)
332 Sequence<Any> row(nColSize);
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 for (sal_Int32
i = 0;
i < nTabSize; ++
i)
354 rTabData[
i] = tableData[
i];
370 const std::unordered_set<sal_Int32>& rRepeatIfEmptyDims)
const
373 for (
const auto& rCriterion : rCriteria)
375 if (rCriterion.mnFieldIndex >= nColSize)
381 bool bRepeatIfEmpty = rRepeatIfEmptyDims.count(rCriterion.mnFieldIndex) > 0;
382 const ScDPItemData* pCellData =
getCell(static_cast<SCCOL>(rCriterion.mnFieldIndex), nRow, bRepeatIfEmpty);
383 if (!rCriterion.mpFilter->match(*pCellData))
393 RowFlagType::const_iterator it = rFlag.begin(), itEnd = rFlag.end();
394 bool bShow = it->second;
395 SCROW nRow1 = it->first;
396 for (++it; it != itEnd; ++it)
398 SCROW nRow2 = it->first;
399 cout <<
" * range " << nRow1 <<
"-" << nRow2 <<
": " << (bShow ?
"on" :
"off") << endl;
407 cout <<
"--- pivot filtered cache dump" <<
endl;
410 cout <<
"* show by filter" << endl;
414 cout <<
"* show by page dimensions" << endl;
418 cout <<
"* field entries" << endl;
420 for (
size_t i = 0;
i < nFieldCount; ++
i)
423 cout <<
" * field " <<
i << endl;
424 for (
size_t j = 0, n = rField.size(); j <
n; ++j)
425 cout <<
" ID: " << rField[j] << endl;
427 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
std::unique_ptr< ContentProperties > pData
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.
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