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/zforlist.hxx>
21 #include <unotools/charclass.hxx>
22 
23 #include <dpcache.hxx>
24 #include <dpshttab.hxx>
25 #include <document.hxx>
26 #include <dpfilteredcache.hxx>
27 #include <dpobject.hxx>
28 #include <globstr.hrc>
29 #include <scresid.hxx>
30 #include <rangenam.hxx>
31 #include <queryentry.hxx>
32 
33 #include <osl/diagnose.h>
34 
35 #include <vector>
36 
37 using namespace ::com::sun::star;
38 using ::com::sun::star::uno::Any;
39 using ::com::sun::star::uno::Sequence;
40 using ::std::vector;
41 
42 ScSheetDPData::ScSheetDPData(const ScDocument* pD, const ScSheetSourceDesc& rDesc, const ScDPCache& rCache) :
43  ScDPTableData(pD),
44  aQuery ( rDesc.GetQueryParam() ),
45  bIgnoreEmptyRows( false ),
46  bRepeatIfEmpty(false),
47  aCacheTable(rCache)
48 {
49  SCSIZE nEntryCount( aQuery.GetEntryCount());
50  for (SCSIZE j = 0; j < nEntryCount; ++j)
51  {
52  ScQueryEntry& rEntry = aQuery.GetEntry(j);
53  if (rEntry.bDoQuery)
54  {
55  ScQueryEntry::Item& rItem = rEntry.GetQueryItem();
56  if (rItem.meType == ScQueryEntry::ByString)
57  {
58  sal_uInt32 nIndex = 0;
59  bool bNumber = pD->GetFormatTable()->IsNumberFormat(
60  rItem.maString.getString(), nIndex, rItem.mfVal);
62  }
63  }
64  }
65 }
66 
68 {
69 }
70 
72 {
74 }
75 
77 {
79  return aCacheTable.getColSize();
80 }
81 
83 {
85  if (getIsDataLayoutDimension(nColumn))
86  {
87  //TODO: different internal and display names?
88  //return "Data";
89  return ScResId(STR_PIVOT_DATA);
90  }
91  else if (nColumn >= aCacheTable.getColSize())
92  {
93  OSL_FAIL("getDimensionName: invalid dimension");
94  return OUString();
95  }
96  else
97  {
98  return aCacheTable.getFieldName(static_cast<SCCOL>(nColumn));
99  }
100 }
101 
103 {
106  if (getIsDataLayoutDimension(nDim))
107  {
108  return false;
109  }
110  else if (nDim >= nColCount)
111  {
112  OSL_FAIL("IsDateDimension: invalid dimension");
113  return false;
114  }
115  else
116  {
117  return GetCacheTable().getCache().IsDateDimension( nDim);
118  }
119 }
120 
122 {
124  if (getIsDataLayoutDimension(nDim))
125  {
126  return 0;
127  }
128  else if (nDim >= GetCacheTable().getColSize())
129  {
130  OSL_FAIL("GetNumberFormat: invalid dimension");
131  return 0;
132  }
133  else
134  {
135  return GetCacheTable().getCache().GetNumberFormat( nDim );
136  }
137 }
139 {
140  if( !mpDoc )
141  return 0;
142 
143  if ( SvNumberFormatter* pFormatter = mpDoc->GetFormatTable() )
144  return pFormatter->GetFormatIndex( eIdx, LANGUAGE_SYSTEM );
145 
146  return 0;
147 }
148 
150 {
152  return (nColumn ==static_cast<tools::Long>( aCacheTable.getColSize()));
153 }
154 
155 void ScSheetDPData::SetEmptyFlags( bool bIgnoreEmptyRowsP, bool bRepeatIfEmptyP )
156 {
157  bIgnoreEmptyRows = bIgnoreEmptyRowsP;
158  bRepeatIfEmpty = bRepeatIfEmptyP;
159 }
160 
162 {
163  return bRepeatIfEmpty;
164 }
165 
167 {
168  // Scan and store the data from the source range.
169  if (!aCacheTable.empty())
170  // already cached.
171  return;
172 
174 }
175 
176 void ScSheetDPData::FilterCacheTable(const vector<ScDPFilteredCache::Criterion>& rCriteria, const std::unordered_set<sal_Int32>& rCatDims)
177 {
180  rCriteria, (IsRepeatIfEmpty() ? rCatDims : std::unordered_set<sal_Int32>()));
181 }
182 
183 void ScSheetDPData::GetDrillDownData(const vector<ScDPFilteredCache::Criterion>& rCriteria, const std::unordered_set<sal_Int32>& rCatDims, Sequence< Sequence<Any> >& rData)
184 {
186  sal_Int32 nRowSize = aCacheTable.getRowSize();
187  if (!nRowSize)
188  return;
189 
191  rCriteria, rData, IsRepeatIfEmpty() ? rCatDims : std::unordered_set<sal_Int32>());
192 }
193 
194 void ScSheetDPData::CalcResults(CalcInfo& rInfo, bool bAutoShow)
195 {
197  CalcResultsFromCacheTable(aCacheTable, rInfo, bAutoShow);
198 }
199 
201 {
202  return aCacheTable;
203 }
204 
206 {
207  aCacheTable.clear();
209 }
210 
211 #if DUMP_PIVOT_TABLE
212 
213 void ScSheetDPData::Dump() const
214 {
215  // TODO : Implement this.
216 }
217 
218 #endif
219 
221  mpDoc(pDoc) {}
222 
224 {
225  maSourceRange = rRange;
226  maRangeName.clear(); // overwrite existing range name if any.
227 }
228 
230 {
231  if (!maRangeName.isEmpty())
232  {
233  // Obtain the source range from the range name first.
235  ScRangeName* pRangeName = mpDoc->GetRangeName();
236  do
237  {
238  if (!pRangeName)
239  break;
240 
241  OUString aUpper = ScGlobal::getCharClassPtr()->uppercase(maRangeName);
242  const ScRangeData* pData = pRangeName->findByUpperName(aUpper);
243  if (!pData)
244  break;
245 
246  // range name found. Fow now, we only use the first token and
247  // ignore the rest.
248  ScRange aRange;
249  if (!pData->IsReference(aRange))
250  break;
251 
252  maSourceRange = aRange;
253  }
254  while (false);
255  }
256  return maSourceRange;
257 }
258 
259 void ScSheetSourceDesc::SetRangeName(const OUString& rName)
260 {
261  maRangeName = rName;
262 }
263 
265 {
266  return !maRangeName.isEmpty();
267 }
268 
270 {
271  maQueryParam = rParam;
272 }
273 
275 {
276  return maSourceRange == rOther.maSourceRange &&
277  maRangeName == rOther.maRangeName &&
278  maQueryParam == rOther.maQueryParam;
279 }
280 
282 {
283  if (!mpDoc)
284  return nullptr;
285 
286  const char* pErrId = CheckSourceRange();
287  if (pErrId)
288  {
289  OSL_FAIL( "Error Create Cache" );
290  return nullptr;
291  }
292 
293  // All cache instances are managed centrally by ScDPCollection.
295  if (HasRangeName())
296  {
297  // Name-based data source.
298  ScDPCollection::NameCaches& rCaches = pDPs->GetNameCaches();
299  return rCaches.getCache(GetRangeName(), GetSourceRange(), pDimData);
300  }
301 
302  ScDPCollection::SheetCaches& rCaches = pDPs->GetSheetCaches();
303  return rCaches.getCache(GetSourceRange(), pDimData);
304 }
305 
307 {
308  if (!mpDoc)
309  return STR_ERR_DATAPILOTSOURCE;
310 
311  // Make sure the range is valid and sane.
312  const ScRange& rSrcRange = GetSourceRange();
313  if (!rSrcRange.IsValid())
314  return STR_ERR_DATAPILOTSOURCE;
315 
316  if (rSrcRange.aStart.Col() > rSrcRange.aEnd.Col() || rSrcRange.aStart.Row() > rSrcRange.aEnd.Row())
317  return STR_ERR_DATAPILOTSOURCE;
318 
319  return nullptr;
320 }
321 
322 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUString getFieldName(SCCOL nIndex) const
const int nColCount
sal_Int32 nIndex
OUString getString() const
ScAddress aStart
Definition: address.hxx:500
virtual bool getIsDataLayoutDimension(tools::Long nColumn) override
Definition: dpshttab.cxx:149
This class has to do with handling exclusively grouped dimensions? TODO: Find out what this class doe...
Definition: dpdimsave.hxx:160
virtual void CreateCacheTable() override
Definition: dpshttab.cxx:166
SCROW Row() const
Definition: address.hxx:262
SC_DLLPUBLIC SheetCaches & GetSheetCaches()
Definition: dpobject.cxx:3754
sal_Int32 getRowSize() const
virtual void GetDrillDownData(const std::vector< ScDPFilteredCache::Criterion > &rCriteria, const std::unordered_set< sal_Int32 > &rCatDims, css::uno::Sequence< css::uno::Sequence< css::uno::Any > > &rData) override
Definition: dpshttab.cxx:183
std::unique_ptr< ContentProperties > pData
void fillTable(const ScQueryParam &rQuery, bool bIgnoreEmptyRows, bool bRepeatIfEmpty)
long Long
virtual void ReloadCacheTable() override
Definition: dpshttab.cxx:205
SC_DLLPUBLIC ScRangeName * GetRangeName(SCTAB nTab) const
Definition: documen3.cxx:168
SC_DLLPUBLIC ScDPCollection * GetDPCollection()
Definition: documen3.cxx:360
const ContentProperties & rData
ScAddress aEnd
Definition: address.hxx:501
Data caches for range name based source data.
Definition: dpobject.hxx:317
This class represents the cached data part of the datapilot cache table implementation.
Definition: dpcache.hxx:48
ScDocument * mpDoc
Definition: dpshttab.hxx:80
virtual void FilterCacheTable(const std::vector< ScDPFilteredCache::Criterion > &rCriteria, const std::unordered_set< sal_Int32 > &rCatDims) override
Definition: dpshttab.cxx:176
void SetQueryParam(const ScQueryParam &rParam)
Definition: dpshttab.cxx:269
const char * CheckSourceRange() const
Check the sanity of the data source range.
Definition: dpshttab.cxx:306
const Item & GetQueryItem() const
Definition: queryentry.cxx:118
ScQueryParam maQueryParam
Definition: dpshttab.hxx:79
SC_DLLPUBLIC void SetSourceRange(const ScRange &rRange)
Definition: dpshttab.cxx:223
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:45
virtual sal_uInt32 GetNumberFormat(tools::Long nDim) override
Definition: dpshttab.cxx:121
SC_DLLPUBLIC SCSIZE GetEntryCount() const
Definition: queryparam.cxx:119
ScRange maSourceRange
Definition: dpshttab.hxx:77
virtual const ScDPFilteredCache & GetCacheTable() const override
Definition: dpshttab.cxx:200
SC_DLLPUBLIC const ScQueryEntry & GetEntry(SCSIZE n) const
Definition: queryparam.cxx:124
NfIndexTableOffset
ScSheetSourceDesc()=delete
SC_DLLPUBLIC const ScRange & GetSourceRange() const
Get the range that contains the source data.
Definition: dpshttab.cxx:229
virtual void Dump() const override
const ScDocument * mpDoc
Definition: dptabdat.hxx:64
void CalcResultsFromCacheTable(const ScDPFilteredCache &rCacheTable, CalcInfo &rInfo, bool bAutoShow)
Definition: dptabdat.cxx:199
virtual ~ScSheetDPData() override
Definition: dpshttab.cxx:67
SC_DLLPUBLIC ScRangeData * findByUpperName(const OUString &rName)
Definition: rangenam.cxx:682
SC_DLLPUBLIC SvNumberFormatter * GetFormatTable() const
Definition: documen2.cxx:438
const ScDPCache * getCache(const OUString &rName, const ScRange &rRange, const ScDPDimensionSaveData *pDimData)
Definition: dpobject.cxx:3099
ScQueryParam aQuery
Definition: dpshttab.hxx:89
This structure stores dimension information used when calculating results.
Definition: dptabdat.hxx:70
Stores and manages all caches from internal sheets.
Definition: dpobject.hxx:288
const ScDPCache * getCache(const ScRange &rRange, const ScDPDimensionSaveData *pDimData)
Definition: dpobject.cxx:2918
virtual bool IsDateDimension(tools::Long nDim) override
Definition: dpshttab.cxx:102
#define LANGUAGE_SYSTEM
sal_uInt32 GetNumberFormatByIdx(NfIndexTableOffset)
Definition: dpshttab.cxx:138
OUString uppercase(const OUString &rStr, sal_Int32 nPos, sal_Int32 nCount) const
OUString ScResId(const char *pId)
Definition: scdll.cxx:95
bool IsNumberFormat(const OUString &sString, sal_uInt32 &F_Index, double &fOutNumber, SvNumInputOptions eInputOptions=SvNumInputOptions::NONE)
bool IsValid() const
Definition: address.hxx:547
bool operator==(const ScSheetSourceDesc &rOther) const
Definition: dpshttab.cxx:274
svl::SharedString maString
Definition: queryentry.hxx:41
SC_DLLPUBLIC const ScDPCache * CreateCache(const ScDPDimensionSaveData *pDimData) const
Definition: dpshttab.cxx:281
SCCOL Col() const
Definition: address.hxx:267
bool HasRangeName() const
Definition: dpshttab.cxx:264
Base class that abstracts different data source types of a datapilot table.
Definition: dptabdat.hxx:57
sal_Int32 getColSize() const
bool bRepeatIfEmpty
Definition: dpshttab.hxx:91
virtual bool IsRepeatIfEmpty() override
Definition: dpshttab.cxx:161
virtual void SetEmptyFlags(bool bIgnoreEmptyRows, bool bRepeatIfEmpty) override
Definition: dpshttab.cxx:155
bool IsDateDimension(tools::Long nDim) const
Definition: dpcache.cxx:1068
sal_uInt32 GetNumberFormat(tools::Long nDim) const
Definition: dpcache.cxx:1058
const OUString & GetRangeName() const
Definition: dpshttab.hxx:60
static SC_DLLPUBLIC const CharClass * getCharClassPtr()
Definition: global.cxx:1010
virtual void DisposeData() override
Definition: dpshttab.cxx:71
virtual void CalcResults(CalcInfo &rInfo, bool bAutoShow) override
Definition: dpshttab.cxx:194
SC_DLLPUBLIC bool IsReference(ScRange &rRef) const
Definition: rangenam.cxx:369
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.
bool bIgnoreEmptyRows
Definition: dpshttab.hxx:90
OUString maRangeName
Definition: dpshttab.hxx:78
SC_DLLPUBLIC void SetRangeName(const OUString &rName)
Definition: dpshttab.cxx:259
This class is only a wrapper to the actual cache, to provide filtering on the raw data based on the q...
virtual tools::Long GetColumnCount() override
use (new) typed collection instead of ScStrCollection or separate Str and ValueCollection ...
Definition: dpshttab.cxx:76
virtual OUString getDimensionName(tools::Long nColumn) override
Definition: dpshttab.cxx:82
ScSheetDPData(const ScDocument *pD, const ScSheetSourceDesc &rDesc, const ScDPCache &rCache)
Definition: dpshttab.cxx:42
NameCaches & GetNameCaches()
Definition: dpobject.cxx:3764
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.
This class contains authoritative information on the internal reference used as the data source for d...
Definition: dpshttab.hxx:39
Each instance of this struct represents a single filtering criteria.
Definition: queryentry.hxx:33
const ScDPCache & getCache() const
ScDPFilteredCache aCacheTable
Definition: dpshttab.hxx:93