diff options
author | Kohei Yoshida <kohei.yoshida@suse.com> | 2012-02-17 21:43:37 -0500 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@suse.com> | 2012-02-22 14:02:04 -0500 |
commit | 518c1fd9a65b0b5567f54b481223d260b4befbb3 (patch) | |
tree | dbb3de5609f5a56193da32c59b0bdabd5e126aec /sc | |
parent | Correctly display layout name of data fields. (diff) | |
download | core-518c1fd9a65b0b5567f54b481223d260b4befbb3.tar.gz core-518c1fd9a65b0b5567f54b481223d260b4befbb3.zip |
Correctly generate data field dimensions when pressing OK.
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/pivot.hxx | 6 | ||||
-rw-r--r-- | sc/source/core/data/dpobject.cxx | 52 | ||||
-rw-r--r-- | sc/source/core/data/pivot2.cxx | 12 | ||||
-rw-r--r-- | sc/source/ui/dbgui/pvlaydlg.cxx | 7 |
4 files changed, 42 insertions, 35 deletions
diff --git a/sc/inc/pivot.hxx b/sc/inc/pivot.hxx index a73c43153261..c346aefcc00b 100644 --- a/sc/inc/pivot.hxx +++ b/sc/inc/pivot.hxx @@ -74,7 +74,7 @@ struct ScDPLabelData; struct PivotField { SCCOL nCol; /// 0-based dimension index (not source column index) - long mnOriginalDim; + long mnOriginalDim; /// >= 0 for duplicated field. sal_uInt16 nFuncMask; sal_uInt8 mnDupCount; ::com::sun::star::sheet::DataPilotFieldReference maFieldRef; @@ -82,6 +82,7 @@ struct PivotField explicit PivotField( SCCOL nNewCol = 0, sal_uInt16 nNewFuncMask = PIVOT_FUNC_NONE ); PivotField( const PivotField& r ); + long getOriginalDim() const; bool operator==( const PivotField& r ) const; }; @@ -187,13 +188,14 @@ struct ScPivotField struct ScDPFuncData { SCCOL mnCol; + long mnOriginalDim; sal_uInt16 mnFuncMask; sal_uInt8 mnDupCount; ::com::sun::star::sheet::DataPilotFieldReference maFieldRef; explicit ScDPFuncData( SCCOL nNewCol, sal_uInt16 nNewFuncMask ); explicit ScDPFuncData( - SCCOL nNewCol, sal_uInt16 nNewFuncMask, sal_uInt8 nDupCount, + SCCOL nNewCol, long nOriginalDim, sal_uInt16 nNewFuncMask, sal_uInt8 nDupCount, const ::com::sun::star::sheet::DataPilotFieldReference& rFieldRef ); bool operator== (const ScDPFuncData& r) const; diff --git a/sc/source/core/data/dpobject.cxx b/sc/source/core/data/dpobject.cxx index 9ee479e89d3a..bbfaa4a9affd 100644 --- a/sc/source/core/data/dpobject.cxx +++ b/sc/source/core/data/dpobject.cxx @@ -2163,6 +2163,17 @@ bool hasFieldColumn(const vector<PivotField>* pRefFields, SCCOL nCol) return false; } +class FindByOriginalDim : public std::unary_function<PivotField, bool> +{ + long mnDim; +public: + FindByOriginalDim(long nDim) : mnDim(nDim) {} + bool operator() (const PivotField& r) const + { + return mnDim == r.getOriginalDim(); + } +}; + } void ScDPObject::ConvertOrientation( @@ -2178,7 +2189,7 @@ void ScDPObject::ConvertOrientation( { const PivotField& rField = *itr; - SCCOL nCol = rField.nCol; + long nCol = rField.getOriginalDim(); sal_uInt16 nFuncs = rField.nFuncMask; const sheet::DataPilotFieldReference& rFieldRef = rField.maFieldRef; @@ -2187,8 +2198,8 @@ void ScDPObject::ConvertOrientation( pDim = rSaveData.GetDataLayoutDimension(); else { - String aDocStr = lcl_GetDimName( xSource, nCol ); // cols must start at 0 - if ( aDocStr.Len() ) + rtl::OUString aDocStr = lcl_GetDimName( xSource, nCol ); // cols must start at 0 + if (!aDocStr.isEmpty()) pDim = rSaveData.GetDimensionByName(aDocStr); else pDim = NULL; @@ -2217,35 +2228,18 @@ void ScDPObject::ConvertOrientation( { // if set via api, a data column may occur several times // (if the function hasn't been changed yet) -> also look for duplicate data column - for (vector<PivotField>::const_iterator itr2 = itrBeg; itr2 != itr; ++itr2) - { - if (itr2->nCol == nCol) - { - bFirst = false; - break; - } - } + bFirst = std::find_if(itrBeg, itr, FindByOriginalDim(nCol)) == itr; } - sal_uInt16 nMask = 1; - for (sal_uInt16 nBit=0; nBit<16; nBit++) - { - if ( nFuncs & nMask ) - { - sheet::GeneralFunction eFunc = ScDataPilotConversion::FirstFunc( nMask ); - ScDPSaveDimension* pCurrDim = bFirst ? pDim : rSaveData.DuplicateDimension(pDim->GetName()); - pCurrDim->SetOrientation( nOrient ); - pCurrDim->SetFunction( sal::static_int_cast<sal_uInt16>(eFunc) ); + sheet::GeneralFunction eFunc = ScDataPilotConversion::FirstFunc(rField.nFuncMask); + ScDPSaveDimension* pCurrDim = bFirst ? pDim : rSaveData.DuplicateDimension(pDim->GetName()); + pCurrDim->SetOrientation(nOrient); + pCurrDim->SetFunction(sal::static_int_cast<sal_uInt16>(eFunc)); - if( rFieldRef.ReferenceType == sheet::DataPilotFieldReferenceType::NONE ) - pCurrDim->SetReferenceValue( 0 ); - else - pCurrDim->SetReferenceValue( &rFieldRef ); - - bFirst = false; - } - nMask *= 2; - } + if( rFieldRef.ReferenceType == sheet::DataPilotFieldReferenceType::NONE ) + pCurrDim->SetReferenceValue( 0 ); + else + pCurrDim->SetReferenceValue( &rFieldRef ); } else // set SubTotals { diff --git a/sc/source/core/data/pivot2.cxx b/sc/source/core/data/pivot2.cxx index 685589e61d1a..dd65511afcbe 100644 --- a/sc/source/core/data/pivot2.cxx +++ b/sc/source/core/data/pivot2.cxx @@ -127,6 +127,11 @@ PivotField::PivotField( const PivotField& r ) : mnDupCount(r.mnDupCount), maFieldRef(r.maFieldRef) {} +long PivotField::getOriginalDim() const +{ + return mnOriginalDim >= 0 ? mnOriginalDim : static_cast<long>(nCol); +} + bool PivotField::operator==( const PivotField& r ) const { return (nCol == r.nCol) @@ -211,14 +216,17 @@ bool ScPivotParam::operator==( const ScPivotParam& r ) const ScDPFuncData::ScDPFuncData( SCCOL nCol, sal_uInt16 nFuncMask ) : mnCol( nCol ), + mnOriginalDim(-1), mnFuncMask( nFuncMask ), mnDupCount(0) { } ScDPFuncData::ScDPFuncData( - SCCOL nCol, sal_uInt16 nFuncMask, sal_uInt8 nDupCount, const DataPilotFieldReference& rFieldRef ) : + SCCOL nCol, long nOriginalDim, sal_uInt16 nFuncMask, sal_uInt8 nDupCount, + const DataPilotFieldReference& rFieldRef) : mnCol( nCol ), + mnOriginalDim(nOriginalDim), mnFuncMask( nFuncMask ), mnDupCount(nDupCount), maFieldRef( rFieldRef ) @@ -227,7 +235,7 @@ ScDPFuncData::ScDPFuncData( bool ScDPFuncData::operator== (const ScDPFuncData& r) const { - if (mnCol != r.mnCol || mnFuncMask != r.mnFuncMask || mnDupCount != r.mnDupCount) + if (mnCol != r.mnCol || mnOriginalDim != r.mnOriginalDim || mnFuncMask != r.mnFuncMask || mnDupCount != r.mnDupCount) return false; return equals(maFieldRef, r.maFieldRef); diff --git a/sc/source/ui/dbgui/pvlaydlg.cxx b/sc/source/ui/dbgui/pvlaydlg.cxx index c16c86e12966..675eb0a387b3 100644 --- a/sc/source/ui/dbgui/pvlaydlg.cxx +++ b/sc/source/ui/dbgui/pvlaydlg.cxx @@ -382,7 +382,7 @@ void ScDPLayoutDlg::InitWndData(const vector<PivotField>& rFields) size_t nFieldIndex = aDataArr.size(); aDataArr.push_back( - new ScDPFuncData(nCol, nMask, it->mnDupCount, it->maFieldRef)); + new ScDPFuncData(nCol, it->mnOriginalDim, nMask, it->mnDupCount, it->maFieldRef)); // data field - we need to concatenate function name with the field name. ScDPLabelData* pData = GetLabelData(nCol); @@ -422,7 +422,8 @@ void ScDPLayoutDlg::InitFieldWindow( const vector<PivotField>& rFields, ScDPFiel continue; size_t nFieldIndex = pInitArr->size(); - pInitArr->push_back(new ScDPFuncData(nCol, nMask, itr->mnDupCount, itr->maFieldRef)); + pInitArr->push_back( + new ScDPFuncData(nCol, itr->mnOriginalDim, nMask, itr->mnDupCount, itr->maFieldRef)); pInitWnd->AddField(GetLabelString(nCol), nFieldIndex); } pInitWnd->ResetScrollBar(); @@ -1433,6 +1434,8 @@ public: { PivotField aField; aField.nCol = r.mnCol; + aField.mnOriginalDim = r.mnOriginalDim; + aField.mnDupCount = r.mnDupCount; aField.nFuncMask = r.mnFuncMask; aField.maFieldRef = r.maFieldRef; mrFields.push_back(aField); |