Kaydet (Commit) b53d03f4 authored tarafından Kohei Yoshida's avatar Kohei Yoshida

Remove the last use of SC_DP_MAX_FIELDS.

Now the pivot table core no longer uses static array for result data
storage.

Change-Id: I70a44011e2c12a1739c0507b1723c21a4808758c
üst 352306ee
...@@ -20,8 +20,6 @@ ...@@ -20,8 +20,6 @@
#ifndef _SC_DPGLOBAL_HXX #ifndef _SC_DPGLOBAL_HXX
#define _SC_DPGLOBAL_HXX #define _SC_DPGLOBAL_HXX
#define SC_DP_MAX_FIELDS 256
#define PIVOT_MAXFUNC 11 #define PIVOT_MAXFUNC 11
#define PIVOT_FUNC_NONE 0x0000 #define PIVOT_FUNC_NONE 0x0000
#define PIVOT_FUNC_SUM 0x0001 #define PIVOT_FUNC_SUM 0x0001
......
...@@ -98,14 +98,12 @@ private: ...@@ -98,14 +98,12 @@ private:
ScDPTableData* pData; // data source (ScDPObject manages its life time) ScDPTableData* pData; // data source (ScDPObject manages its life time)
ScDPDimensions* pDimensions; // api objects ScDPDimensions* pDimensions; // api objects
// settings: // settings:
long nColDims[SC_DP_MAX_FIELDS];
long nRowDims[SC_DP_MAX_FIELDS]; std::vector<long> maColDims;
long nDataDims[SC_DP_MAX_FIELDS]; std::vector<long> maRowDims;
long nPageDims[SC_DP_MAX_FIELDS]; std::vector<long> maDataDims;
long nColDimCount; std::vector<long> maPageDims;
long nRowDimCount;
long nDataDimCount;
long nPageDimCount;
bool bColumnGrand; bool bColumnGrand;
bool bRowGrand; bool bRowGrand;
bool bIgnoreEmptyRows; bool bIgnoreEmptyRows;
......
...@@ -109,10 +109,6 @@ static void lcl_SetBoolInAny( uno::Any& rAny, sal_Bool bValue ) ...@@ -109,10 +109,6 @@ static void lcl_SetBoolInAny( uno::Any& rAny, sal_Bool bValue )
ScDPSource::ScDPSource( ScDPTableData* pD ) : ScDPSource::ScDPSource( ScDPTableData* pD ) :
pData( pD ), pData( pD ),
pDimensions( NULL ), pDimensions( NULL ),
nColDimCount( 0 ),
nRowDimCount( 0 ),
nDataDimCount( 0 ),
nPageDimCount( 0 ),
bColumnGrand( true ), // default is true bColumnGrand( true ), // default is true
bRowGrand( true ), bRowGrand( true ),
bIgnoreEmptyRows( false ), bIgnoreEmptyRows( false ),
...@@ -152,33 +148,32 @@ const ::rtl::OUString* ScDPSource::GetGrandTotalName() const ...@@ -152,33 +148,32 @@ const ::rtl::OUString* ScDPSource::GetGrandTotalName() const
sal_uInt16 ScDPSource::GetOrientation(long nColumn) sal_uInt16 ScDPSource::GetOrientation(long nColumn)
{ {
long i; if (std::find(maColDims.begin(), maColDims.end(), nColumn) != maColDims.end())
for (i=0; i<nColDimCount; i++)
if (nColDims[i] == nColumn)
return sheet::DataPilotFieldOrientation_COLUMN; return sheet::DataPilotFieldOrientation_COLUMN;
for (i=0; i<nRowDimCount; i++)
if (nRowDims[i] == nColumn) if (std::find(maRowDims.begin(), maRowDims.end(), nColumn) != maRowDims.end())
return sheet::DataPilotFieldOrientation_ROW; return sheet::DataPilotFieldOrientation_ROW;
for (i=0; i<nDataDimCount; i++)
if (nDataDims[i] == nColumn) if (std::find(maDataDims.begin(), maDataDims.end(), nColumn) != maDataDims.end())
return sheet::DataPilotFieldOrientation_DATA; return sheet::DataPilotFieldOrientation_DATA;
for (i=0; i<nPageDimCount; i++)
if (nPageDims[i] == nColumn) if (std::find(maPageDims.begin(), maPageDims.end(), nColumn) != maPageDims.end())
return sheet::DataPilotFieldOrientation_PAGE; return sheet::DataPilotFieldOrientation_PAGE;
return sheet::DataPilotFieldOrientation_HIDDEN; return sheet::DataPilotFieldOrientation_HIDDEN;
} }
long ScDPSource::GetDataDimensionCount() long ScDPSource::GetDataDimensionCount()
{ {
return nDataDimCount; return maDataDims.size();
} }
ScDPDimension* ScDPSource::GetDataDimension(long nIndex) ScDPDimension* ScDPSource::GetDataDimension(long nIndex)
{ {
if (nIndex < 0 || nIndex >= nDataDimCount) if (nIndex < 0 || static_cast<size_t>(nIndex) >= maDataDims.size())
return NULL; return NULL;
long nDimIndex = nDataDims[nIndex]; long nDimIndex = maDataDims[nIndex];
return GetDimensionsObject()->getByIndex(nDimIndex); return GetDimensionsObject()->getByIndex(nDimIndex);
} }
...@@ -193,92 +188,107 @@ rtl::OUString ScDPSource::GetDataDimName(long nIndex) ...@@ -193,92 +188,107 @@ rtl::OUString ScDPSource::GetDataDimName(long nIndex)
long ScDPSource::GetPosition(long nColumn) long ScDPSource::GetPosition(long nColumn)
{ {
long i; std::vector<long>::const_iterator it, itBeg = maColDims.begin(), itEnd = maColDims.end();
for (i=0; i<nColDimCount; i++) it = std::find(itBeg, itEnd, nColumn);
if (nColDims[i] == nColumn) if (it != itEnd)
return i; return std::distance(itBeg, it);
for (i=0; i<nRowDimCount; i++)
if (nRowDims[i] == nColumn) itBeg = maRowDims.begin();
return i; itEnd = maRowDims.end();
for (i=0; i<nDataDimCount; i++) it = std::find(itBeg, itEnd, nColumn);
if (nDataDims[i] == nColumn) if (it != itEnd)
return i; return std::distance(itBeg, it);
for (i=0; i<nPageDimCount; i++)
if (nPageDims[i] == nColumn) itBeg = maDataDims.begin();
return i; itEnd = maDataDims.end();
it = std::find(itBeg, itEnd, nColumn);
if (it != itEnd)
return std::distance(itBeg, it);
itBeg = maPageDims.begin();
itEnd = maPageDims.end();
it = std::find(itBeg, itEnd, nColumn);
if (it != itEnd)
return std::distance(itBeg, it);
return 0; return 0;
} }
static sal_Bool lcl_TestSubTotal( sal_Bool& rAllowed, long nColumn, long* pArray, long nCount, ScDPSource* pSource ) namespace {
bool testSubTotal( bool& rAllowed, long nColumn, const std::vector<long>& rDims, ScDPSource* pSource )
{ {
for (long i=0; i<nCount; i++) rAllowed = true;
if (pArray[i] == nColumn) std::vector<long>::const_iterator it = rDims.begin(), itEnd = rDims.end();
for (; it != itEnd; ++it)
{ {
// no subtotals for data layout dim, no matter where if (*it != nColumn)
continue;
if ( pSource->IsDataLayoutDimension(nColumn) ) if ( pSource->IsDataLayoutDimension(nColumn) )
rAllowed = false;
else
{ {
// no subtotals if no other dim but data layout follows // no subtotals for data layout dim, no matter where
long nNextIndex = i+1;
if ( nNextIndex < nCount && pSource->IsDataLayoutDimension(pArray[nNextIndex]) )
++nNextIndex;
if ( nNextIndex >= nCount )
rAllowed = false; rAllowed = false;
return true;
} }
return sal_True; // found // no subtotals if no other dim but data layout follows
++it;
if (it != itEnd && pSource->IsDataLayoutDimension(*it))
++it;
if (it == itEnd)
rAllowed = false;
return true; // found
} }
return false; return false;
} }
void removeDim( long nRemove, std::vector<long>& rDims )
{
std::vector<long>::iterator it = std::find(rDims.begin(), rDims.end(), nRemove);
if (it != rDims.end())
rDims.erase(it);
}
}
sal_Bool ScDPSource::SubTotalAllowed(long nColumn) sal_Bool ScDPSource::SubTotalAllowed(long nColumn)
{ {
//! cache this at ScDPResultData //! cache this at ScDPResultData
sal_Bool bAllowed = sal_True; bool bAllowed = true;
if ( lcl_TestSubTotal( bAllowed, nColumn, nColDims, nColDimCount, this ) ) if ( testSubTotal(bAllowed, nColumn, maColDims, this) )
return bAllowed; return bAllowed;
if ( lcl_TestSubTotal( bAllowed, nColumn, nRowDims, nRowDimCount, this ) ) if ( testSubTotal(bAllowed, nColumn, maRowDims, this) )
return bAllowed; return bAllowed;
return bAllowed; return bAllowed;
} }
static void lcl_RemoveDim( long nRemove, long* pDims, long& rCount )
{
for (long i=0; i<rCount; i++)
if ( pDims[i] == nRemove )
{
for (long j=i; j+1<rCount; j++)
pDims[j] = pDims[j+1];
--rCount;
return;
}
}
void ScDPSource::SetOrientation(long nColumn, sal_uInt16 nNew) void ScDPSource::SetOrientation(long nColumn, sal_uInt16 nNew)
{ {
//! change to no-op if new orientation is equal to old? //! change to no-op if new orientation is equal to old?
// remove from old list // remove from old list
lcl_RemoveDim( nColumn, nColDims, nColDimCount ); removeDim(nColumn, maColDims);
lcl_RemoveDim( nColumn, nRowDims, nRowDimCount ); removeDim(nColumn, maRowDims);
lcl_RemoveDim( nColumn, nDataDims, nDataDimCount ); removeDim(nColumn, maDataDims);
lcl_RemoveDim( nColumn, nPageDims, nPageDimCount ); removeDim(nColumn, maPageDims);
// add to new list // add to new list
switch (nNew) switch (nNew)
{ {
case sheet::DataPilotFieldOrientation_COLUMN: case sheet::DataPilotFieldOrientation_COLUMN:
nColDims[nColDimCount++] = nColumn; maColDims.push_back(nColumn);
break; break;
case sheet::DataPilotFieldOrientation_ROW: case sheet::DataPilotFieldOrientation_ROW:
nRowDims[nRowDimCount++] = nColumn; maRowDims.push_back(nColumn);
break; break;
case sheet::DataPilotFieldOrientation_DATA: case sheet::DataPilotFieldOrientation_DATA:
nDataDims[nDataDimCount++] = nColumn; maDataDims.push_back(nColumn);
break; break;
case sheet::DataPilotFieldOrientation_PAGE: case sheet::DataPilotFieldOrientation_PAGE:
nPageDims[nPageDimCount++] = nColumn; maPageDims.push_back(nColumn);
break; break;
// DataPilot Migration - Cache&&Performance // DataPilot Migration - Cache&&Performance
case sheet::DataPilotFieldOrientation_HIDDEN: case sheet::DataPilotFieldOrientation_HIDDEN:
...@@ -514,8 +524,10 @@ void ScDPSource::disposeData() ...@@ -514,8 +524,10 @@ void ScDPSource::disposeData()
} }
SetDupCount( 0 ); SetDupCount( 0 );
//! Test ???? maColDims.clear();
nColDimCount = nRowDimCount = nDataDimCount = nPageDimCount = 0; maRowDims.clear();
maDataDims.clear();
maPageDims.clear();
pData->DisposeData(); // cached entries etc. pData->DisposeData(); // cached entries etc.
bPageFiltered = false; bPageFiltered = false;
...@@ -596,12 +608,11 @@ static long lcl_GetIndexFromName( const rtl::OUString rName, const uno::Sequence ...@@ -596,12 +608,11 @@ static long lcl_GetIndexFromName( const rtl::OUString rName, const uno::Sequence
void ScDPSource::FillCalcInfo(bool bIsRow, ScDPTableData::CalcInfo& rInfo, bool &rHasAutoShow) void ScDPSource::FillCalcInfo(bool bIsRow, ScDPTableData::CalcInfo& rInfo, bool &rHasAutoShow)
{ {
long* nDims = bIsRow ? nRowDims : nColDims; const std::vector<long>& rDims = bIsRow ? maRowDims : maColDims;
long nDimCount = bIsRow ? nRowDimCount : nColDimCount; std::vector<long>::const_iterator it = rDims.begin(), itEnd = rDims.end();
for (; it != itEnd; ++it)
for (long i = 0; i < nDimCount; ++i)
{ {
ScDPDimension* pDim = GetDimensionsObject()->getByIndex( nDims[i] ); ScDPDimension* pDim = GetDimensionsObject()->getByIndex(*it);
long nHierarchy = pDim->getUsedHierarchy(); long nHierarchy = pDim->getUsedHierarchy();
if ( nHierarchy >= pDim->GetHierarchiesObject()->getCount() ) if ( nHierarchy >= pDim->GetHierarchiesObject()->getCount() )
nHierarchy = 0; nHierarchy = 0;
...@@ -609,7 +620,7 @@ void ScDPSource::FillCalcInfo(bool bIsRow, ScDPTableData::CalcInfo& rInfo, bool ...@@ -609,7 +620,7 @@ void ScDPSource::FillCalcInfo(bool bIsRow, ScDPTableData::CalcInfo& rInfo, bool
long nCount = pLevels->getCount(); long nCount = pLevels->getCount();
//! Test //! Test
if ( pDim->getIsDataLayoutDimension() && nDataDimCount < 2 ) if (pDim->getIsDataLayoutDimension() && maDataDims.size() < 2)
nCount = 0; nCount = 0;
//! Test //! Test
...@@ -622,17 +633,17 @@ void ScDPSource::FillCalcInfo(bool bIsRow, ScDPTableData::CalcInfo& rInfo, bool ...@@ -622,17 +633,17 @@ void ScDPSource::FillCalcInfo(bool bIsRow, ScDPTableData::CalcInfo& rInfo, bool
pLevel->SetEnableLayout( bIsRow ); pLevel->SetEnableLayout( bIsRow );
if ( pLevel->GetAutoShow().IsEnabled ) if ( pLevel->GetAutoShow().IsEnabled )
rHasAutoShow = sal_True; rHasAutoShow = true;
if (bIsRow) if (bIsRow)
{ {
rInfo.aRowLevelDims.push_back(nDims[i]); rInfo.aRowLevelDims.push_back(*it);
rInfo.aRowDims.push_back(pDim); rInfo.aRowDims.push_back(pDim);
rInfo.aRowLevels.push_back(pLevel); rInfo.aRowLevels.push_back(pLevel);
} }
else else
{ {
rInfo.aColLevelDims.push_back(nDims[i]); rInfo.aColLevelDims.push_back(*it);
rInfo.aColDims.push_back(pDim); rInfo.aColDims.push_back(pDim);
rInfo.aColLevels.push_back(pLevel); rInfo.aColLevels.push_back(pLevel);
} }
...@@ -642,29 +653,34 @@ void ScDPSource::FillCalcInfo(bool bIsRow, ScDPTableData::CalcInfo& rInfo, bool ...@@ -642,29 +653,34 @@ void ScDPSource::FillCalcInfo(bool bIsRow, ScDPTableData::CalcInfo& rInfo, bool
} }
} }
void ScDPSource::GetCategoryDimensionIndices(boost::unordered_set<sal_Int32>& rCatDims) namespace {
class CategoryDimInserter : std::unary_function<long, void>
{ {
boost::unordered_set<sal_Int32> aCatDims; ScDPSource& mrSource;
for (long i = 0; i < nColDimCount; ++i) boost::unordered_set<sal_Int32>& mrCatDims;
{ public:
sal_Int32 nDim = static_cast<sal_Int32>(nColDims[i]); CategoryDimInserter(ScDPSource& rSource, boost::unordered_set<sal_Int32>& rCatDims) :
if (!IsDataLayoutDimension(nDim)) mrSource(rSource),
aCatDims.insert(nDim); mrCatDims(rCatDims) {}
}
for (long i = 0; i < nRowDimCount; ++i) void operator() (long nDim)
{ {
sal_Int32 nDim = static_cast<sal_Int32>(nRowDims[i]); if (!mrSource.IsDataLayoutDimension(nDim))
if (!IsDataLayoutDimension(nDim)) mrCatDims.insert(nDim);
aCatDims.insert(nDim);
} }
};
for (long i = 0; i < nPageDimCount; ++i) }
{
sal_Int32 nDim = static_cast<sal_Int32>(nPageDims[i]); void ScDPSource::GetCategoryDimensionIndices(boost::unordered_set<sal_Int32>& rCatDims)
if (!IsDataLayoutDimension(nDim)) {
aCatDims.insert(nDim); boost::unordered_set<sal_Int32> aCatDims;
}
CategoryDimInserter aInserter(*this, aCatDims);
std::for_each(maColDims.begin(), maColDims.end(), aInserter);
std::for_each(maRowDims.begin(), maRowDims.end(), aInserter);
std::for_each(maPageDims.begin(), maPageDims.end(), aInserter);
rCatDims.swap(aCatDims); rCatDims.swap(aCatDims);
} }
...@@ -688,9 +704,10 @@ void ScDPSource::FilterCacheByPageDimensions() ...@@ -688,9 +704,10 @@ void ScDPSource::FilterCacheByPageDimensions()
// filter table by page dimensions. // filter table by page dimensions.
vector<ScDPFilteredCache::Criterion> aCriteria; vector<ScDPFilteredCache::Criterion> aCriteria;
for (long i = 0; i < nPageDimCount; ++i) vector<long>::const_iterator it = maPageDims.begin(), itEnd = maPageDims.end();
for (; it != itEnd; ++it)
{ {
ScDPDimension* pDim = GetDimensionsObject()->getByIndex(nPageDims[i]); ScDPDimension* pDim = GetDimensionsObject()->getByIndex(*it);
long nField = pDim->GetDimension(); long nField = pDim->GetDimension();
ScDPMembers* pMems = pDim->GetHierarchiesObject()->getByIndex(0)-> ScDPMembers* pMems = pDim->GetHierarchiesObject()->getByIndex(0)->
...@@ -699,7 +716,7 @@ void ScDPSource::FilterCacheByPageDimensions() ...@@ -699,7 +716,7 @@ void ScDPSource::FilterCacheByPageDimensions()
long nMemCount = pMems->getCount(); long nMemCount = pMems->getCount();
ScDPFilteredCache::Criterion aFilter; ScDPFilteredCache::Criterion aFilter;
aFilter.mnFieldIndex = static_cast<sal_Int32>(nField); aFilter.mnFieldIndex = static_cast<sal_Int32>(nField);
aFilter.mpFilter.reset(new ScDPFilteredCache::GroupFilter(/*rSharedString*/)); aFilter.mpFilter.reset(new ScDPFilteredCache::GroupFilter);
ScDPFilteredCache::GroupFilter* pGrpFilter = ScDPFilteredCache::GroupFilter* pGrpFilter =
static_cast<ScDPFilteredCache::GroupFilter*>(aFilter.mpFilter.get()); static_cast<ScDPFilteredCache::GroupFilter*>(aFilter.mpFilter.get());
for (long j = 0; j < nMemCount; ++j) for (long j = 0; j < nMemCount; ++j)
...@@ -740,7 +757,7 @@ void ScDPSource::CreateRes_Impl() ...@@ -740,7 +757,7 @@ void ScDPSource::CreateRes_Impl()
return; return;
sal_uInt16 nDataOrient = GetDataLayoutOrientation(); sal_uInt16 nDataOrient = GetDataLayoutOrientation();
if ( nDataDimCount > 1 && ( nDataOrient != sheet::DataPilotFieldOrientation_COLUMN && if (maDataDims.size() > 1 && ( nDataOrient != sheet::DataPilotFieldOrientation_COLUMN &&
nDataOrient != sheet::DataPilotFieldOrientation_ROW ) ) nDataOrient != sheet::DataPilotFieldOrientation_ROW ) )
{ {
// if more than one data dimension, data layout orientation must be set // if more than one data dimension, data layout orientation must be set
...@@ -752,14 +769,9 @@ void ScDPSource::CreateRes_Impl() ...@@ -752,14 +769,9 @@ void ScDPSource::CreateRes_Impl()
// eDataFunctions into a structure and use vector instead of static // eDataFunctions into a structure and use vector instead of static
// or pointer arrays. // or pointer arrays.
vector<rtl::OUString> aDataNames; vector<rtl::OUString> aDataNames;
sheet::DataPilotFieldReference* pDataRefValues = NULL; vector<sheet::DataPilotFieldReference> aDataRefValues;
vector<ScSubTotalFunc> aDataFunctions; vector<ScSubTotalFunc> aDataFunctions;
vector<sal_uInt16> aDataRefOrient; vector<sal_uInt16> aDataRefOrient;
if (nDataDimCount)
{
aDataNames.resize(nDataDimCount);
pDataRefValues = new sheet::DataPilotFieldReference[nDataDimCount];
}
ScDPTableData::CalcInfo aInfo; ScDPTableData::CalcInfo aInfo;
...@@ -771,11 +783,11 @@ void ScDPSource::CreateRes_Impl() ...@@ -771,11 +783,11 @@ void ScDPSource::CreateRes_Impl()
// Go through all data dimensions (i.e. fields) and build their meta data // Go through all data dimensions (i.e. fields) and build their meta data
// so that they can be passed on to ScDPResultData instance later. // so that they can be passed on to ScDPResultData instance later.
// TODO: aggregate all of data dimension info into a structure. // TODO: aggregate all of data dimension info into a structure.
long i; vector<long>::const_iterator it = maDataDims.begin(), itEnd = maDataDims.end();
for (i=0; i<nDataDimCount; i++) for (; it != itEnd; ++it)
{ {
// Get function for each data field. // Get function for each data field.
long nDimIndex = nDataDims[i]; long nDimIndex = *it;
ScDPDimension* pDim = GetDimensionsObject()->getByIndex(nDimIndex); ScDPDimension* pDim = GetDimensionsObject()->getByIndex(nDimIndex);
sheet::GeneralFunction eUser = (sheet::GeneralFunction)pDim->getFunction(); sheet::GeneralFunction eUser = (sheet::GeneralFunction)pDim->getFunction();
if (eUser == sheet::GeneralFunction_AUTO) if (eUser == sheet::GeneralFunction_AUTO)
...@@ -788,16 +800,16 @@ void ScDPSource::CreateRes_Impl() ...@@ -788,16 +800,16 @@ void ScDPSource::CreateRes_Impl()
aDataFunctions.push_back(ScDataUnoConversion::GeneralToSubTotal(eUser)); aDataFunctions.push_back(ScDataUnoConversion::GeneralToSubTotal(eUser));
// Get reference field/item information. // Get reference field/item information.
pDataRefValues[i] = pDim->GetReferenceValue(); aDataRefValues.push_back(pDim->GetReferenceValue());
sal_uInt16 nDataRefOrient = sheet::DataPilotFieldOrientation_HIDDEN; // default if not used sal_uInt16 nDataRefOrient = sheet::DataPilotFieldOrientation_HIDDEN; // default if not used
sal_Int32 eRefType = pDataRefValues[i].ReferenceType; sal_Int32 eRefType = aDataRefValues.back().ReferenceType;
if ( eRefType == sheet::DataPilotFieldReferenceType::ITEM_DIFFERENCE || if ( eRefType == sheet::DataPilotFieldReferenceType::ITEM_DIFFERENCE ||
eRefType == sheet::DataPilotFieldReferenceType::ITEM_PERCENTAGE || eRefType == sheet::DataPilotFieldReferenceType::ITEM_PERCENTAGE ||
eRefType == sheet::DataPilotFieldReferenceType::ITEM_PERCENTAGE_DIFFERENCE || eRefType == sheet::DataPilotFieldReferenceType::ITEM_PERCENTAGE_DIFFERENCE ||
eRefType == sheet::DataPilotFieldReferenceType::RUNNING_TOTAL ) eRefType == sheet::DataPilotFieldReferenceType::RUNNING_TOTAL )
{ {
long nColumn = lcl_GetIndexFromName( pDataRefValues[i].ReferenceField, long nColumn = lcl_GetIndexFromName(
GetDimensionsObject()->getElementNames() ); aDataRefValues.back().ReferenceField, GetDimensionsObject()->getElementNames());
if ( nColumn >= 0 ) if ( nColumn >= 0 )
{ {
nDataRefOrient = GetOrientation(nColumn); nDataRefOrient = GetOrientation(nColumn);
...@@ -810,18 +822,18 @@ void ScDPSource::CreateRes_Impl() ...@@ -810,18 +822,18 @@ void ScDPSource::CreateRes_Impl()
aDataRefOrient.push_back(nDataRefOrient); aDataRefOrient.push_back(nDataRefOrient);
aDataNames[i] = pDim->getName(); aDataNames.push_back(pDim->getName());
//! modify user visible strings as in ScDPResultData::GetMeasureString instead! //! modify user visible strings as in ScDPResultData::GetMeasureString instead!
aDataNames[i] = ScDPUtil::getSourceDimensionName(aDataNames[i]); aDataNames.back() = ScDPUtil::getSourceDimensionName(aDataNames.back());
//! if the name is overridden by user, a flag must be set //! if the name is overridden by user, a flag must be set
//! so the user defined name replaces the function string and field name. //! so the user defined name replaces the function string and field name.
//! the complete name (function and field) must be stored at the dimension //! the complete name (function and field) must be stored at the dimension
long nSource = ((ScDPDimension*)pDim)->GetSourceDim(); long nSource = pDim->GetSourceDim();
if (nSource >= 0) if (nSource >= 0)
aInfo.aDataSrcCols.push_back(nSource); aInfo.aDataSrcCols.push_back(nSource);
else else
...@@ -829,12 +841,19 @@ void ScDPSource::CreateRes_Impl() ...@@ -829,12 +841,19 @@ void ScDPSource::CreateRes_Impl()
} }
pResData = new ScDPResultData( this ); pResData = new ScDPResultData( this );
pResData->SetMeasureData(nDataDimCount, &aDataFunctions[0], pDataRefValues, &aDataRefOrient[0], aDataNames); const ScSubTotalFunc* pDataFunctions = NULL;
const sheet::DataPilotFieldReference* pDataRefValues = NULL;
const sal_uInt16* pDataRefOrient = NULL;
if (!maDataDims.empty())
{
pDataFunctions = &aDataFunctions[0];
pDataRefValues = &aDataRefValues[0];
pDataRefOrient = &aDataRefOrient[0];
}
pResData->SetMeasureData(maDataDims.size(), pDataFunctions, pDataRefValues, pDataRefOrient, aDataNames);
pResData->SetDataLayoutOrientation(nDataOrient); pResData->SetDataLayoutOrientation(nDataOrient);
pResData->SetLateInit( bLateInit ); pResData->SetLateInit( bLateInit );
delete[] pDataRefValues;
bool bHasAutoShow = false; bool bHasAutoShow = false;
ScDPInitState aInitState; ScDPInitState aInitState;
...@@ -843,18 +862,18 @@ void ScDPSource::CreateRes_Impl() ...@@ -843,18 +862,18 @@ void ScDPSource::CreateRes_Impl()
// (both in column and row fields). aInitState is filled with the page // (both in column and row fields). aInitState is filled with the page
// field selections, they are kept across the data iterator loop. // field selections, they are kept across the data iterator loop.
for (i=0; i<nPageDimCount; i++) for (it = maPageDims.begin(), itEnd = maPageDims.end(); it != itEnd; ++it)
{ {
ScDPDimension* pDim = GetDimensionsObject()->getByIndex( nPageDims[i] ); ScDPDimension* pDim = GetDimensionsObject()->getByIndex(*it);
if ( pDim->HasSelectedPage() ) if ( pDim->HasSelectedPage() )
aInitState.AddMember( nPageDims[i], GetMemberId( nPageDims[i], pDim->GetSelectedData() ) ); aInitState.AddMember(*it, GetMemberId(*it, pDim->GetSelectedData()));
} }
// Show grand total columns only when the option is set *and* there is at // Show grand total columns only when the option is set *and* there is at
// least one column field. Same for the grand total rows. // least one column field. Same for the grand total rows.
sal_uInt16 nDataLayoutOrient = GetDataLayoutOrientation(); sal_uInt16 nDataLayoutOrient = GetDataLayoutOrientation();
long nColDimCount2 = nColDimCount - (nDataLayoutOrient == sheet::DataPilotFieldOrientation_COLUMN ? 1 : 0); long nColDimCount2 = maColDims.size() - (nDataLayoutOrient == sheet::DataPilotFieldOrientation_COLUMN ? 1 : 0);
long nRowDimCount2 = nRowDimCount - (nDataLayoutOrient == sheet::DataPilotFieldOrientation_ROW ? 1 : 0); long nRowDimCount2 = maRowDims.size() - (nDataLayoutOrient == sheet::DataPilotFieldOrientation_ROW ? 1 : 0);
bool bShowColGrand = bColumnGrand && nColDimCount2 > 0; bool bShowColGrand = bColumnGrand && nColDimCount2 > 0;
bool bShowRowGrand = bRowGrand && nRowDimCount2 > 0; bool bShowRowGrand = bRowGrand && nRowDimCount2 > 0;
pColResRoot = new ScDPResultMember(pResData, bShowColGrand); pColResRoot = new ScDPResultMember(pResData, bShowColGrand);
...@@ -879,9 +898,9 @@ void ScDPSource::CreateRes_Impl() ...@@ -879,9 +898,9 @@ void ScDPSource::CreateRes_Impl()
pRowResRoot->SetHasElements(); pRowResRoot->SetHasElements();
// initialize members object also for all page dimensions (needed for numeric groups) // initialize members object also for all page dimensions (needed for numeric groups)
for (i=0; i<nPageDimCount; i++) for (it = maPageDims.begin(), itEnd = maPageDims.end(); it != itEnd; ++it)
{ {
ScDPDimension* pDim = GetDimensionsObject()->getByIndex( nPageDims[i] ); ScDPDimension* pDim = GetDimensionsObject()->getByIndex(*it);
long nHierarchy = pDim->getUsedHierarchy(); long nHierarchy = pDim->getUsedHierarchy();
if ( nHierarchy >= pDim->GetHierarchiesObject()->getCount() ) if ( nHierarchy >= pDim->GetHierarchiesObject()->getCount() )
nHierarchy = 0; nHierarchy = 0;
...@@ -909,9 +928,9 @@ void ScDPSource::CreateRes_Impl() ...@@ -909,9 +928,9 @@ void ScDPSource::CreateRes_Impl()
FilterCacheByPageDimensions(); FilterCacheByPageDimensions();
aInfo.aPageDims.reserve(nPageDimCount); aInfo.aPageDims.reserve(maPageDims.size());
for (i = 0; i < nPageDimCount; ++i) for (it = maPageDims.begin(), itEnd = maPageDims.end(); it != itEnd; ++it)
aInfo.aPageDims.push_back(nPageDims[i]); aInfo.aPageDims.push_back(*it);
aInfo.pInitState = &aInitState; aInfo.pInitState = &aInitState;
aInfo.pColRoot = pColResRoot; aInfo.pColRoot = pColResRoot;
...@@ -963,25 +982,20 @@ void ScDPSource::FillLevelList( sal_uInt16 nOrientation, std::vector<ScDPLevel*> ...@@ -963,25 +982,20 @@ void ScDPSource::FillLevelList( sal_uInt16 nOrientation, std::vector<ScDPLevel*>
{ {
rList.clear(); rList.clear();
long nDimCount = 0; std::vector<long>* pDimIndex = NULL;
long* pDimIndex = NULL;
switch (nOrientation) switch (nOrientation)
{ {
case sheet::DataPilotFieldOrientation_COLUMN: case sheet::DataPilotFieldOrientation_COLUMN:
pDimIndex = nColDims; pDimIndex = &maColDims;
nDimCount = nColDimCount;
break; break;
case sheet::DataPilotFieldOrientation_ROW: case sheet::DataPilotFieldOrientation_ROW:
pDimIndex = nRowDims; pDimIndex = &maRowDims;
nDimCount = nRowDimCount;
break; break;
case sheet::DataPilotFieldOrientation_DATA: case sheet::DataPilotFieldOrientation_DATA:
pDimIndex = nDataDims; pDimIndex = &maDataDims;
nDimCount = nDataDimCount;
break; break;
case sheet::DataPilotFieldOrientation_PAGE: case sheet::DataPilotFieldOrientation_PAGE:
pDimIndex = nPageDims; pDimIndex = &maPageDims;
nDimCount = nPageDimCount;
break; break;
default: default:
OSL_FAIL( "ScDPSource::FillLevelList: unexpected orientation" ); OSL_FAIL( "ScDPSource::FillLevelList: unexpected orientation" );
...@@ -994,9 +1008,10 @@ void ScDPSource::FillLevelList( sal_uInt16 nOrientation, std::vector<ScDPLevel*> ...@@ -994,9 +1008,10 @@ void ScDPSource::FillLevelList( sal_uInt16 nOrientation, std::vector<ScDPLevel*>
} }
ScDPDimensions* pDims = GetDimensionsObject(); ScDPDimensions* pDims = GetDimensionsObject();
for (long nDim=0; nDim<nDimCount; nDim++) std::vector<long>::const_iterator it = pDimIndex->begin(), itEnd = pDimIndex->end();
for (; it != itEnd; ++it)
{ {
ScDPDimension* pDim = pDims->getByIndex(pDimIndex[nDim]); ScDPDimension* pDim = pDims->getByIndex(*it);
OSL_ENSURE( pDim->getOrientation() == nOrientation, "orientations are wrong" ); OSL_ENSURE( pDim->getOrientation() == nOrientation, "orientations are wrong" );
ScDPHierarchies* pHiers = pDim->GetHierarchiesObject(); ScDPHierarchies* pHiers = pDim->GetHierarchiesObject();
...@@ -1147,11 +1162,11 @@ uno::Any SAL_CALL ScDPSource::getPropertyValue( const rtl::OUString& aPropertyNa ...@@ -1147,11 +1162,11 @@ uno::Any SAL_CALL ScDPSource::getPropertyValue( const rtl::OUString& aPropertyNa
else if ( aPropertyName.equalsAscii( SC_UNO_DP_DATADESC ) ) // read-only else if ( aPropertyName.equalsAscii( SC_UNO_DP_DATADESC ) ) // read-only
aRet <<= getDataDescription(); aRet <<= getDataDescription();
else if ( aPropertyName.equalsAscii( SC_UNO_DP_ROWFIELDCOUNT ) ) // read-only else if ( aPropertyName.equalsAscii( SC_UNO_DP_ROWFIELDCOUNT ) ) // read-only
aRet <<= static_cast<sal_Int32>(nRowDimCount); aRet <<= static_cast<sal_Int32>(maRowDims.size());
else if ( aPropertyName.equalsAscii( SC_UNO_DP_COLUMNFIELDCOUNT ) ) // read-only else if ( aPropertyName.equalsAscii( SC_UNO_DP_COLUMNFIELDCOUNT ) ) // read-only
aRet <<= static_cast<sal_Int32>(nColDimCount); aRet <<= static_cast<sal_Int32>(maColDims.size());
else if ( aPropertyName.equalsAscii( SC_UNO_DP_DATAFIELDCOUNT ) ) // read-only else if ( aPropertyName.equalsAscii( SC_UNO_DP_DATAFIELDCOUNT ) ) // read-only
aRet <<= static_cast<sal_Int32>(nDataDimCount); aRet <<= static_cast<sal_Int32>(maDataDims.size());
else if (aPropertyName.equalsAscii(SC_UNO_DP_GRANDTOTAL_NAME)) else if (aPropertyName.equalsAscii(SC_UNO_DP_GRANDTOTAL_NAME))
{ {
if (mpGrandTotalName.get()) if (mpGrandTotalName.get())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment