From f9636d50e6543302f236164aeebadab2733e849b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=C5=BE=20Vajngerl?= Date: Thu, 3 Apr 2014 21:38:48 +0200 Subject: [PATCH] pivot: duplicate data field handling Change-Id: I3d367b8b638217f18143118df00324f21a0470f2 --- .../ui/dbgui/PivotLayoutTreeListData.cxx | 57 +++++++++++++++---- sc/source/ui/inc/PivotLayoutTreeListData.hxx | 2 + 2 files changed, 48 insertions(+), 11 deletions(-) diff --git a/sc/source/ui/dbgui/PivotLayoutTreeListData.cxx b/sc/source/ui/dbgui/PivotLayoutTreeListData.cxx index 012781ad78d2..e8f4805de3ea 100644 --- a/sc/source/ui/dbgui/PivotLayoutTreeListData.cxx +++ b/sc/source/ui/dbgui/PivotLayoutTreeListData.cxx @@ -88,15 +88,15 @@ bool ScPivotLayoutTreeListData::DoubleClickHdl() if (pDialog->Execute() == RET_OK) { - if (rCurrentFunctionData.mnFuncMask != pDialog->GetFuncMask()) - { - rCurrentFunctionData.mnDupCount = rCurrentFunctionData.mnDupCount + 1; - } - rCurrentFunctionData.mnFuncMask = pCurrentLabelData->mnFuncMask = pDialog->GetFuncMask(); + rCurrentFunctionData.mnFuncMask = pDialog->GetFuncMask(); + pCurrentLabelData->mnFuncMask = pDialog->GetFuncMask(); + rCurrentFunctionData.maFieldRef = pDialog->GetFieldRef(); ScDPLabelData* pDFData = mpParent->GetLabelData(rCurrentFunctionData.mnCol); + AdjustDuplicateCount(pCurrentItemValue); + OUString sDataItemName = lclCreateDataItemName( rCurrentFunctionData.mnFuncMask, pDFData->maName, @@ -132,15 +132,15 @@ void ScPivotLayoutTreeListData::FillDataField(ScPivotFieldVector& rDataFields) pItemValue->mpOriginalItemValue = pOriginalItemValue; pItemValue->maFunctionData.mnOriginalDim = rField.mnOriginalDim; - pItemValue->maFunctionData.mnDupCount = rField.mnDupCount; pItemValue->maFunctionData.maFieldRef = rField.maFieldRef; + AdjustDuplicateCount(pItemValue); + OUString sDataItemName = lclCreateDataItemName(pItemValue->maFunctionData.mnFuncMask, + pItemValue->maName, + pItemValue->maFunctionData.mnDupCount); + maDataItemValues.push_back(pItemValue); - - OUString sDataItemName = lclCreateDataItemName(rField.nFuncMask, pItemValue->maName, rField.mnDupCount); - - SvTreeListEntry* pEntry = InsertEntry(sDataItemName); - pEntry->SetUserData(pItemValue); + InsertEntry(sDataItemName, NULL, false, TREELIST_APPEND, pItemValue); } } @@ -205,6 +205,8 @@ void ScPivotLayoutTreeListData::InsertEntryForItem(ScItemValue* pItemValue, sal_ rFunctionData.mnFuncMask = PIVOT_FUNC_SUM; } + AdjustDuplicateCount(pDataItemValue); + OUString sDataName = lclCreateDataItemName( rFunctionData.mnFuncMask, pDataItemValue->maName, @@ -213,6 +215,39 @@ void ScPivotLayoutTreeListData::InsertEntryForItem(ScItemValue* pItemValue, sal_ InsertEntry(sDataName, NULL, false, nPosition, pDataItemValue); } +void ScPivotLayoutTreeListData::AdjustDuplicateCount(ScItemValue* pInputItemValue) +{ + ScPivotFuncData& rInputFunctionData = pInputItemValue->maFunctionData; + + bool bFoundDuplicate = false; + + rInputFunctionData.mnDupCount = 0; + sal_uInt8 nMaxDuplicateCount = 0; + + SvTreeListEntry* pEachEntry; + for (pEachEntry = First(); pEachEntry != NULL; pEachEntry = Next(pEachEntry)) + { + ScItemValue* pItemValue = (ScItemValue*) pEachEntry->GetUserData(); + if (pItemValue == pInputItemValue) + continue; + + ScPivotFuncData& rFunctionData = pItemValue->maFunctionData; + + if (rFunctionData.mnCol == rInputFunctionData.mnCol && + rFunctionData.mnFuncMask == rInputFunctionData.mnFuncMask) + { + bFoundDuplicate = true; + if(rFunctionData.mnDupCount > nMaxDuplicateCount) + nMaxDuplicateCount = rFunctionData.mnDupCount; + } + } + + if(bFoundDuplicate) + { + rInputFunctionData.mnDupCount = nMaxDuplicateCount + 1; + } +} + void ScPivotLayoutTreeListData::KeyInput(const KeyEvent& rKeyEvent) { KeyCode aCode = rKeyEvent.GetKeyCode(); diff --git a/sc/source/ui/inc/PivotLayoutTreeListData.hxx b/sc/source/ui/inc/PivotLayoutTreeListData.hxx index d58b077cec2b..f7d9f5cb3a8f 100644 --- a/sc/source/ui/inc/PivotLayoutTreeListData.hxx +++ b/sc/source/ui/inc/PivotLayoutTreeListData.hxx @@ -31,6 +31,8 @@ protected: virtual void InsertEntryForSourceTarget(SvTreeListEntry* pSource, SvTreeListEntry* pTarget) SAL_OVERRIDE; virtual void InsertEntryForItem(ScItemValue* pItemValue, sal_uLong nPosition) SAL_OVERRIDE; + void AdjustDuplicateCount(ScItemValue* pInputItemValue); + virtual void KeyInput(const KeyEvent& rKeyEvent) SAL_OVERRIDE; };