LibreOffice Module sc (master) 1
dpshttab.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include <svl/numformat.hxx>
21#include <svl/zforlist.hxx>
23
24#include <dpcache.hxx>
25#include <dpshttab.hxx>
26#include <document.hxx>
27#include <dpfilteredcache.hxx>
28#include <dpobject.hxx>
29#include <globstr.hrc>
30#include <scresid.hxx>
31#include <rangenam.hxx>
32#include <queryentry.hxx>
33
34#include <osl/diagnose.h>
35
36#include <vector>
37
38using namespace ::com::sun::star;
39using ::com::sun::star::uno::Any;
40using ::com::sun::star::uno::Sequence;
41using ::std::vector;
42
43ScSheetDPData::ScSheetDPData(const ScDocument* pD, const ScSheetSourceDesc& rDesc, const ScDPCache& rCache) :
44 ScDPTableData(pD),
45 aQuery ( rDesc.GetQueryParam() ),
46 bIgnoreEmptyRows( false ),
47 bRepeatIfEmpty(false),
48 aCacheTable(rCache)
49{
50 SCSIZE nEntryCount( aQuery.GetEntryCount());
51 for (SCSIZE j = 0; j < nEntryCount; ++j)
52 {
53 ScQueryEntry& rEntry = aQuery.GetEntry(j);
54 if (rEntry.bDoQuery)
55 {
56 ScQueryEntry::Item& rItem = rEntry.GetQueryItem();
57 if (rItem.meType == ScQueryEntry::ByString)
58 {
59 sal_uInt32 nIndex = 0;
60 bool bNumber = pD->GetFormatTable()->IsNumberFormat(
61 rItem.maString.getString(), nIndex, rItem.mfVal);
63 }
64 }
65 }
66}
67
69{
70}
71
73{
75}
76
78{
80 return aCacheTable.getColSize();
81}
82
83OUString ScSheetDPData::getDimensionName(sal_Int32 nColumn)
84{
86 if (getIsDataLayoutDimension(nColumn))
87 {
88 //TODO: different internal and display names?
89 //return "Data";
90 return ScResId(STR_PIVOT_DATA);
91 }
92 else if (nColumn >= aCacheTable.getColSize())
93 {
94 OSL_FAIL("getDimensionName: invalid dimension");
95 return OUString();
96 }
97 else
98 {
99 return aCacheTable.getFieldName(static_cast<SCCOL>(nColumn));
100 }
101}
102
104{
106 tools::Long nColCount = aCacheTable.getColSize();
107 if (getIsDataLayoutDimension(nDim))
108 {
109 return false;
110 }
111 else if (nDim >= nColCount)
112 {
113 OSL_FAIL("IsDateDimension: invalid dimension");
114 return false;
115 }
116 else
117 {
118 return GetCacheTable().getCache().IsDateDimension( nDim);
119 }
120}
121
122sal_uInt32 ScSheetDPData::GetNumberFormat(sal_Int32 nDim)
123{
125 if (getIsDataLayoutDimension(nDim))
126 {
127 return 0;
128 }
129 else if (nDim >= GetCacheTable().getColSize())
130 {
131 OSL_FAIL("GetNumberFormat: invalid dimension");
132 return 0;
133 }
134 else
135 {
136 return GetCacheTable().getCache().GetNumberFormat( nDim );
137 }
138}
140{
141 if( !mpDoc )
142 return 0;
143
144 if ( SvNumberFormatter* pFormatter = mpDoc->GetFormatTable() )
145 return pFormatter->GetFormatIndex( eIdx, LANGUAGE_SYSTEM );
146
147 return 0;
148}
149
151{
153 return (nColumn ==static_cast<tools::Long>( aCacheTable.getColSize()));
154}
155
156void ScSheetDPData::SetEmptyFlags( bool bIgnoreEmptyRowsP, bool bRepeatIfEmptyP )
157{
158 bIgnoreEmptyRows = bIgnoreEmptyRowsP;
159 bRepeatIfEmpty = bRepeatIfEmptyP;
160}
161
163{
164 return bRepeatIfEmpty;
165}
166
168{
169 // Scan and store the data from the source range.
170 if (!aCacheTable.empty())
171 // already cached.
172 return;
173
175}
176
177void ScSheetDPData::FilterCacheTable(std::vector<ScDPFilteredCache::Criterion>&& rCriteria, std::unordered_set<sal_Int32>&& rCatDims)
178{
181 rCriteria, (IsRepeatIfEmpty() ? rCatDims : std::unordered_set<sal_Int32>()));
182}
183
184void ScSheetDPData::GetDrillDownData(std::vector<ScDPFilteredCache::Criterion>&& rCriteria, std::unordered_set<sal_Int32>&& rCatDims, Sequence< Sequence<Any> >& rData)
185{
187 sal_Int32 nRowSize = aCacheTable.getRowSize();
188 if (!nRowSize)
189 return;
190
192 rCriteria, rData, IsRepeatIfEmpty() ? rCatDims : std::unordered_set<sal_Int32>());
193}
194
195void ScSheetDPData::CalcResults(CalcInfo& rInfo, bool bAutoShow)
196{
198 CalcResultsFromCacheTable(aCacheTable, rInfo, bAutoShow);
199}
200
202{
203 return aCacheTable;
204}
205
207{
210}
211
212#if DUMP_PIVOT_TABLE
213
214void ScSheetDPData::Dump() const
215{
216 // TODO : Implement this.
217}
218
219#endif
220
222 mpDoc(pDoc) {}
223
225{
226 maSourceRange = rRange;
227 maRangeName.clear(); // overwrite existing range name if any.
228}
229
231{
232 if (!maRangeName.isEmpty())
233 {
234 // Obtain the source range from the range name first.
236 ScRangeName* pRangeName = mpDoc->GetRangeName();
237 do
238 {
239 if (!pRangeName)
240 break;
241
242 OUString aUpper = ScGlobal::getCharClass().uppercase(maRangeName);
243 const ScRangeData* pData = pRangeName->findByUpperName(aUpper);
244 if (!pData)
245 break;
246
247 // range name found. Fow now, we only use the first token and
248 // ignore the rest.
249 ScRange aRange;
250 if (!pData->IsReference(aRange))
251 break;
252
253 maSourceRange = aRange;
254 }
255 while (false);
256 }
257 return maSourceRange;
258}
259
260void ScSheetSourceDesc::SetRangeName(const OUString& rName)
261{
262 maRangeName = rName;
263}
264
266{
267 return !maRangeName.isEmpty();
268}
269
271{
272 maQueryParam = rParam;
273}
274
276{
277 return maSourceRange == rOther.maSourceRange &&
278 maRangeName == rOther.maRangeName &&
279 maQueryParam == rOther.maQueryParam;
280}
281
283{
284 if (!mpDoc)
285 return nullptr;
286
287 TranslateId pErrId = CheckSourceRange();
288 if (pErrId)
289 {
290 OSL_FAIL( "Error Create Cache" );
291 return nullptr;
292 }
293
294 // All cache instances are managed centrally by ScDPCollection.
296 if (HasRangeName())
297 {
298 // Name-based data source.
299 ScDPCollection::NameCaches& rCaches = pDPs->GetNameCaches();
300 return rCaches.getCache(GetRangeName(), GetSourceRange(), pDimData);
301 }
302
304 return rCaches.getCache(GetSourceRange(), pDimData);
305}
306
308{
309 if (!mpDoc)
310 return STR_ERR_DATAPILOTSOURCE;
311
312 // Make sure the range is valid and sane.
313 const ScRange& rSrcRange = GetSourceRange();
314 if (!rSrcRange.IsValid())
315 return STR_ERR_DATAPILOTSOURCE;
316
317 if (rSrcRange.aStart.Col() > rSrcRange.aEnd.Col() || rSrcRange.aStart.Row() > rSrcRange.aEnd.Row())
318 return STR_ERR_DATAPILOTSOURCE;
319
320 return {};
321}
322
323/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
size_t SCSIZE
size_t typedef to be able to find places where code was changed from USHORT to size_t and is used to ...
Definition: address.hxx:44
OUString uppercase(const OUString &rStr, sal_Int32 nPos, sal_Int32 nCount) const
SCROW Row() const
Definition: address.hxx:274
SCCOL Col() const
Definition: address.hxx:279
This class represents the cached data part of the datapilot cache table implementation.
Definition: dpcache.hxx:48
bool IsDateDimension(tools::Long nDim) const
Definition: dpcache.cxx:1066
sal_uInt32 GetNumberFormat(tools::Long nDim) const
Definition: dpcache.cxx:1056
Data caches for range name based source data.
Definition: dpobject.hxx:321
const ScDPCache * getCache(const OUString &rName, const ScRange &rRange, const ScDPDimensionSaveData *pDimData)
Definition: dpobject.cxx:3139
Stores and manages all caches from internal sheets.
Definition: dpobject.hxx:292
const ScDPCache * getCache(const ScRange &rRange, const ScDPDimensionSaveData *pDimData)
Definition: dpobject.cxx:2958
SC_DLLPUBLIC SheetCaches & GetSheetCaches()
Definition: dpobject.cxx:3794
NameCaches & GetNameCaches()
Definition: dpobject.cxx:3804
This class has to do with handling exclusively grouped dimensions? TODO: Find out what this class doe...
Definition: dpdimsave.hxx:164
This class is only a wrapper to the actual cache, to provide filtering on the raw data based on the q...
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.
void fillTable(const ScQueryParam &rQuery, bool bIgnoreEmptyRows, bool bRepeatIfEmpty)
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
const ScDPCache & getCache() const
Base class that abstracts different data source types of a datapilot table.
Definition: dptabdat.hxx:57
void CalcResultsFromCacheTable(const ScDPFilteredCache &rCacheTable, CalcInfo &rInfo, bool bAutoShow)
Definition: dptabdat.cxx:199
sal_uInt32 GetNumberFormatByIdx(NfIndexTableOffset)
Definition: dpshttab.cxx:139
const ScDocument * mpDoc
Definition: dptabdat.hxx:63
SC_DLLPUBLIC SvNumberFormatter * GetFormatTable() const
Definition: documen2.cxx:467
SC_DLLPUBLIC ScRangeName * GetRangeName(SCTAB nTab) const
Definition: documen3.cxx:171
SC_DLLPUBLIC ScDPCollection * GetDPCollection()
Definition: documen3.cxx:365
static SC_DLLPUBLIC const CharClass & getCharClass()
Definition: global.cxx:1064
SC_DLLPUBLIC ScRangeData * findByUpperName(const OUString &rName)
Definition: rangenam.cxx:704
ScAddress aEnd
Definition: address.hxx:498
bool IsValid() const
Definition: address.hxx:544
ScAddress aStart
Definition: address.hxx:497
virtual void CalcResults(CalcInfo &rInfo, bool bAutoShow) override
Definition: dpshttab.cxx:195
virtual void SetEmptyFlags(bool bIgnoreEmptyRows, bool bRepeatIfEmpty) override
Definition: dpshttab.cxx:156
virtual sal_uInt32 GetNumberFormat(sal_Int32 nDim) override
Definition: dpshttab.cxx:122
virtual void GetDrillDownData(std::vector< ScDPFilteredCache::Criterion > &&rCriteria, std::unordered_set< sal_Int32 > &&rCatDims, css::uno::Sequence< css::uno::Sequence< css::uno::Any > > &rData) override
Definition: dpshttab.cxx:184
virtual bool IsRepeatIfEmpty() override
Definition: dpshttab.cxx:162
virtual const ScDPFilteredCache & GetCacheTable() const override
Definition: dpshttab.cxx:201
ScSheetDPData(const ScDocument *pD, const ScSheetSourceDesc &rDesc, const ScDPCache &rCache)
Definition: dpshttab.cxx:43
bool bIgnoreEmptyRows
Definition: dpshttab.hxx:90
virtual void FilterCacheTable(std::vector< ScDPFilteredCache::Criterion > &&rCriteria, std::unordered_set< sal_Int32 > &&rCatDims) override
Definition: dpshttab.cxx:177
virtual bool IsDateDimension(sal_Int32 nDim) override
Definition: dpshttab.cxx:103
virtual void CreateCacheTable() override
Definition: dpshttab.cxx:167
virtual void Dump() const override
virtual sal_Int32 GetColumnCount() override
use (new) typed collection instead of ScStrCollection or separate Str and ValueCollection
Definition: dpshttab.cxx:77
ScQueryParam aQuery
Definition: dpshttab.hxx:89
virtual ~ScSheetDPData() override
Definition: dpshttab.cxx:68
virtual void DisposeData() override
Definition: dpshttab.cxx:72
bool bRepeatIfEmpty
Definition: dpshttab.hxx:91
ScDPFilteredCache aCacheTable
Definition: dpshttab.hxx:93
virtual OUString getDimensionName(sal_Int32 nColumn) override
Definition: dpshttab.cxx:83
virtual bool getIsDataLayoutDimension(sal_Int32 nColumn) override
Definition: dpshttab.cxx:150
virtual void ReloadCacheTable() override
Definition: dpshttab.cxx:206
This class contains authoritative information on the internal reference used as the data source for d...
Definition: dpshttab.hxx:40
ScQueryParam maQueryParam
Definition: dpshttab.hxx:79
const OUString & GetRangeName() const
Definition: dpshttab.hxx:60
SC_DLLPUBLIC const ScDPCache * CreateCache(const ScDPDimensionSaveData *pDimData) const
Definition: dpshttab.cxx:282
TranslateId CheckSourceRange() const
Check the sanity of the data source range.
Definition: dpshttab.cxx:307
SC_DLLPUBLIC void SetSourceRange(const ScRange &rRange)
Definition: dpshttab.cxx:224
SC_DLLPUBLIC void SetRangeName(const OUString &rName)
Definition: dpshttab.cxx:260
bool operator==(const ScSheetSourceDesc &rOther) const
Definition: dpshttab.cxx:275
OUString maRangeName
Definition: dpshttab.hxx:78
ScSheetSourceDesc()=delete
ScRange maSourceRange
Definition: dpshttab.hxx:77
ScDocument * mpDoc
Definition: dpshttab.hxx:80
SC_DLLPUBLIC const ScRange & GetSourceRange() const
Get the range that contains the source data.
Definition: dpshttab.cxx:230
void SetQueryParam(const ScQueryParam &rParam)
Definition: dpshttab.cxx:270
bool HasRangeName() const
Definition: dpshttab.cxx:265
bool IsNumberFormat(const OUString &sString, sal_uInt32 &F_Index, double &fOutNumber, SvNumInputOptions eInputOptions=SvNumInputOptions::NONE)
const OUString & getString() const
sal_Int32 nIndex
#define LANGUAGE_SYSTEM
std::unique_ptr< sal_Int32[]> pData
long Long
OUString ScResId(TranslateId aId)
Definition: scdll.cxx:90
This structure stores dimension information used when calculating results.
Definition: dptabdat.hxx:70
svl::SharedString maString
Definition: queryentry.hxx:49
Each instance of this struct represents a single filtering criteria.
Definition: queryentry.hxx:34
const Item & GetQueryItem() const
Definition: queryentry.hxx:85
SC_DLLPUBLIC const ScQueryEntry & GetEntry(SCSIZE n) const
Definition: queryparam.cxx:116
SC_DLLPUBLIC SCSIZE GetEntryCount() const
Definition: queryparam.cxx:111
sal_Int16 SCCOL
Definition: types.hxx:21
NfIndexTableOffset