diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2014-04-03 11:33:04 +0200 |
---|---|---|
committer | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2014-04-03 12:19:37 +0200 |
commit | 19d71217aba8700dac913c278767d6e387ce65a1 (patch) | |
tree | 453a8d52527921cef76d2db6e68c6828d00888aa | |
parent | e748cf70977bbdd2d869bdeab1921ee68238dca4 (diff) |
pivot: Apply changes made in "Data Field" and "Data Field Options"
Change-Id: If8560d47c5b4e64367c441237c1e38f964cf6825
-rw-r--r-- | sc/source/ui/dbgui/PivotLayoutDialog.cxx | 117 | ||||
-rw-r--r-- | sc/source/ui/dbgui/PivotLayoutTreeList.cxx | 41 | ||||
-rw-r--r-- | sc/source/ui/dbgui/PivotLayoutTreeListBase.cxx | 18 | ||||
-rw-r--r-- | sc/source/ui/dbgui/PivotLayoutTreeListData.cxx | 28 | ||||
-rw-r--r-- | sc/source/ui/dbgui/PivotLayoutTreeListLabel.cxx | 2 | ||||
-rw-r--r-- | sc/source/ui/inc/PivotLayoutDialog.hxx | 5 | ||||
-rw-r--r-- | sc/source/ui/inc/PivotLayoutTreeListData.hxx | 2 | ||||
-rw-r--r-- | sc/source/ui/inc/PivotLayoutTreeListLabel.hxx | 2 |
8 files changed, 150 insertions, 65 deletions
diff --git a/sc/source/ui/dbgui/PivotLayoutDialog.cxx b/sc/source/ui/dbgui/PivotLayoutDialog.cxx index 48b4874a79c7..4acc7585c74f 100644 --- a/sc/source/ui/dbgui/PivotLayoutDialog.cxx +++ b/sc/source/ui/dbgui/PivotLayoutDialog.cxx @@ -16,8 +16,12 @@ #include "rangeutl.hxx" #include "uiitems.hxx" +#include "dputil.hxx" + +#include <vector> #include <com/sun/star/sheet/DataPilotFieldOrientation.hpp> +#include <com/sun/star/sheet/DataPilotFieldSortMode.hpp> using namespace css::uno; using namespace css::sheet; @@ -156,6 +160,7 @@ ScPivotLayoutDialog::ScPivotLayoutDialog( FillValuesToListBoxes(); + // Initialize Options const ScDPSaveData* pSaveData = maPivotTableObject.GetSaveData(); if (pSaveData == NULL) { @@ -446,65 +451,108 @@ void ScPivotLayoutDialog::UpdateSourceRange() bool ScPivotLayoutDialog::ApplyChanges() { ScDPSaveData aSaveData; - aSaveData.SetIgnoreEmptyRows(mpCheckIgnoreEmptyRows->IsChecked()); - aSaveData.SetRepeatIfEmpty(mpCheckIdentifyCategories->IsChecked()); - aSaveData.SetColumnGrand(mpCheckTotalColumns->IsChecked()); - aSaveData.SetRowGrand(mpCheckTotalRows->IsChecked()); - aSaveData.SetFilterButton(mpCheckAddFilter->IsChecked()); - aSaveData.SetDrillDown(mpCheckDrillToDetail->IsChecked()); + ApplySaveData(aSaveData); + ApplyLabelData(aSaveData); + + ScRange aDestinationRange; + bool bToNewSheet = false; + + if (!GetDestination(aDestinationRange, bToNewSheet)) + return false; + + SetDispatcherLock(false); + SwitchToDocument(); + + sal_uInt16 nWhichPivot = SC_MOD()->GetPool().GetWhich(SID_PIVOT_TABLE); + ScPivotItem aPivotItem(nWhichPivot, &aSaveData, &aDestinationRange, bToNewSheet); + mpViewData->GetViewShell()->SetDialogDPObject(&maPivotTableObject); + + SfxDispatcher* pDispatcher = GetBindings().GetDispatcher(); + SfxCallMode nCallMode = SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD; + const SfxPoolItem* pResult = pDispatcher->Execute(SID_PIVOT_TABLE, nCallMode, &aPivotItem, NULL, 0); + + if (pResult != NULL) + { + const SfxBoolItem* pItem = reinterpret_cast<const SfxBoolItem*>(pResult); + if (pItem) + { + return pItem->GetValue(); + } + } + + SetDispatcherLock(true); + return true; +} + +void ScPivotLayoutDialog::ApplySaveData(ScDPSaveData& rSaveData) +{ + rSaveData.SetIgnoreEmptyRows(mpCheckIgnoreEmptyRows->IsChecked()); + rSaveData.SetRepeatIfEmpty(mpCheckIdentifyCategories->IsChecked()); + rSaveData.SetColumnGrand(mpCheckTotalColumns->IsChecked()); + rSaveData.SetRowGrand(mpCheckTotalRows->IsChecked()); + rSaveData.SetFilterButton(mpCheckAddFilter->IsChecked()); + rSaveData.SetDrillDown(mpCheckDrillToDetail->IsChecked()); Reference<XDimensionsSupplier> xSource = maPivotTableObject.GetSource(); ScPivotFieldVector aPageFieldVector; mpListBoxPage->PushEntriesToPivotFieldVector(aPageFieldVector); - ScDPObject::ConvertOrientation(aSaveData, aPageFieldVector, DataPilotFieldOrientation_PAGE, + ScDPObject::ConvertOrientation(rSaveData, aPageFieldVector, DataPilotFieldOrientation_PAGE, xSource, maPivotParameters.maLabelArray); ScPivotFieldVector aColFieldVector; mpListBoxColumn->PushEntriesToPivotFieldVector(aColFieldVector); - ScDPObject::ConvertOrientation(aSaveData, aColFieldVector, DataPilotFieldOrientation_COLUMN, + ScDPObject::ConvertOrientation(rSaveData, aColFieldVector, DataPilotFieldOrientation_COLUMN, xSource, maPivotParameters.maLabelArray); ScPivotFieldVector aRowFieldVector; mpListBoxRow->PushEntriesToPivotFieldVector(aRowFieldVector); - ScDPObject::ConvertOrientation(aSaveData, aRowFieldVector, DataPilotFieldOrientation_ROW, + ScDPObject::ConvertOrientation(rSaveData, aRowFieldVector, DataPilotFieldOrientation_ROW, xSource, maPivotParameters.maLabelArray); ScPivotFieldVector aDataFieldVector; mpListBoxData->PushEntriesToPivotFieldVector(aDataFieldVector); - ScDPObject::ConvertOrientation(aSaveData, aDataFieldVector, DataPilotFieldOrientation_DATA, + ScDPObject::ConvertOrientation(rSaveData, aDataFieldVector, DataPilotFieldOrientation_DATA, xSource, maPivotParameters.maLabelArray, &aColFieldVector, &aRowFieldVector, &aPageFieldVector); +} +void ScPivotLayoutDialog::ApplyLabelData(ScDPSaveData& rSaveData) +{ + ScDPLabelDataVector::const_iterator it; + ScDPLabelDataVector& rLabelDataVector = GetLabelDataVector(); - ScRange aDestinationRange; - bool bToNewSheet = false; + for (it = rLabelDataVector.begin(); it != rLabelDataVector.end(); ++it) + { + const ScDPLabelData& pLabelData = *it; - if (!GetDestination(aDestinationRange, bToNewSheet)) - return false; + OUString aUnoName = ScDPUtil::createDuplicateDimensionName(pLabelData.maName, pLabelData.mnDupCount); + ScDPSaveDimension* pSaveDimensions = rSaveData.GetExistingDimensionByName(aUnoName); - SetDispatcherLock(false); - SwitchToDocument(); + if (pSaveDimensions == NULL) + continue; - sal_uInt16 nWhichPivot = SC_MOD()->GetPool().GetWhich(SID_PIVOT_TABLE); - ScPivotItem aPivotItem(nWhichPivot, &aSaveData, &aDestinationRange, bToNewSheet); - mpViewData->GetViewShell()->SetDialogDPObject(new ScDPObject(maPivotTableObject)); + pSaveDimensions->SetUsedHierarchy(pLabelData.mnUsedHier); + pSaveDimensions->SetShowEmpty(pLabelData.mbShowAll); + pSaveDimensions->SetSortInfo(&pLabelData.maSortInfo); + pSaveDimensions->SetLayoutInfo(&pLabelData.maLayoutInfo); + pSaveDimensions->SetAutoShowInfo(&pLabelData.maShowInfo); - SfxDispatcher* pDispatcher = GetBindings().GetDispatcher(); - SfxCallMode nCallMode = SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD; - const SfxPoolItem* pResult = pDispatcher->Execute(SID_PIVOT_TABLE, nCallMode, &aPivotItem, NULL, 0); + bool bManualSort = (pLabelData.maSortInfo.Mode == DataPilotFieldSortMode::MANUAL); - if (pResult != NULL) - { - const SfxBoolItem* pItem = reinterpret_cast<const SfxBoolItem*>(pResult); - if (pItem) + std::vector<ScDPLabelData::Member>::const_iterator itMember; + for (itMember = pLabelData.maMembers.begin(); itMember != pLabelData.maMembers.end(); ++itMember) { - return pItem->GetValue(); + const ScDPLabelData::Member& rLabelMember = *itMember; + ScDPSaveMember* pMember = pSaveDimensions->GetMemberByName(rLabelMember.maName); + + if (bManualSort || !rLabelMember.mbVisible || !rLabelMember.mbShowDetails) + { + pMember->SetIsVisible(rLabelMember.mbVisible); + pMember->SetShowDetails(rLabelMember.mbShowDetails); + } } } - - SetDispatcherLock(true); - return true; } bool ScPivotLayoutDialog::GetDestination(ScRange& aDestinationRange, bool& bToNewSheet) @@ -537,9 +585,9 @@ ScItemValue* ScPivotLayoutDialog::GetItem(SCCOL nColumn) return mpListBoxField->GetItem(nColumn); } -bool ScPivotLayoutDialog::IsDataItem(SCCOL nColumn) +bool ScPivotLayoutDialog::IsDataElement(SCCOL nColumn) { - return mpListBoxField->IsDataItem(nColumn); + return mpListBoxField->IsDataElement(nColumn); } ScDPLabelData* ScPivotLayoutDialog::GetLabelData(SCCOL nColumn) @@ -552,6 +600,11 @@ ScDPLabelDataVector& ScPivotLayoutDialog::GetLabelDataVector() return maPivotParameters.maLabelArray; } +void ScPivotLayoutDialog::PushDataFieldNames(std::vector<ScDPName>& rDataFieldNames) +{ + return mpListBoxData->PushDataFieldNames(rDataFieldNames); +} + IMPL_LINK( ScPivotLayoutDialog, OkClicked, PushButton*, /*pButton*/ ) { if (ApplyChanges()) diff --git a/sc/source/ui/dbgui/PivotLayoutTreeList.cxx b/sc/source/ui/dbgui/PivotLayoutTreeList.cxx index 9eae737eeffd..bdfae545a399 100644 --- a/sc/source/ui/dbgui/PivotLayoutTreeList.cxx +++ b/sc/source/ui/dbgui/PivotLayoutTreeList.cxx @@ -36,11 +36,35 @@ void ScPivotLayoutTreeList::Setup(ScPivotLayoutDialog* pParent, SvPivotTreeListT meType = eType; } +OUString lclFunctName(const sal_uInt16 nFunctionMask) +{ + switch (nFunctionMask) + { + case PIVOT_FUNC_SUM: return OUString("Sum"); + case PIVOT_FUNC_COUNT: return OUString("Count"); + case PIVOT_FUNC_AVERAGE: return OUString("Mean"); + case PIVOT_FUNC_MAX: return OUString("Max"); + case PIVOT_FUNC_MIN: return OUString("Min"); + case PIVOT_FUNC_PRODUCT: return OUString("Product"); + case PIVOT_FUNC_COUNT_NUM: return OUString("Count"); + case PIVOT_FUNC_STD_DEV: return OUString("StDev"); + case PIVOT_FUNC_STD_DEVP: return OUString("StDevP"); + case PIVOT_FUNC_STD_VAR: return OUString("Var"); + case PIVOT_FUNC_STD_VARP: return OUString("VarP"); + default: + break; + } + return OUString(); +} + bool ScPivotLayoutTreeList::DoubleClickHdl() { ScItemValue* pCurrentItemValue = (ScItemValue*) GetCurEntry()->GetUserData(); ScPivotFuncData& rCurrentFunctionData = pCurrentItemValue->maFunctionData; + if (mpParent->IsDataElement(rCurrentFunctionData.mnCol)) + return false; + SCCOL nCurrentColumn = rCurrentFunctionData.mnCol; ScDPLabelData* pCurrentLabelData = mpParent->GetLabelData(nCurrentColumn); if (!pCurrentLabelData) @@ -49,18 +73,7 @@ bool ScPivotLayoutTreeList::DoubleClickHdl() ScAbstractDialogFactory* pFactory = ScAbstractDialogFactory::Create(); vector<ScDPName> aDataFieldNames; - SvTreeListEntry* pLoopEntry; - for (pLoopEntry = First(); pLoopEntry != NULL; pLoopEntry = Next(pLoopEntry)) - { - ScItemValue* pEachItemValue = (ScItemValue*) pLoopEntry->GetUserData(); - SCCOL nColumn = pEachItemValue->maFunctionData.mnCol; - - ScDPLabelData* pDFData = mpParent->GetLabelData(nColumn); - if (pDFData == NULL && pDFData->maName.isEmpty()) - continue; - - aDataFieldNames.push_back(ScDPName(pDFData->maName, pDFData->maLayoutName, pDFData->mnDupCount)); - } + mpParent->PushDataFieldNames(aDataFieldNames); boost::scoped_ptr<AbstractScDPSubtotalDlg> pDialog( pFactory->CreateScDPSubtotalDlg(this, mpParent->maPivotTableObject, *pCurrentLabelData, rCurrentFunctionData, aDataFieldNames, true)); @@ -68,7 +81,7 @@ bool ScPivotLayoutTreeList::DoubleClickHdl() if (pDialog->Execute() == RET_OK) { pDialog->FillLabelData(*pCurrentLabelData); - rCurrentFunctionData.mnFuncMask = pCurrentLabelData->mnFuncMask; + rCurrentFunctionData.mnFuncMask = pDialog->GetFuncMask(); } return true; @@ -93,7 +106,7 @@ void ScPivotLayoutTreeList::InsertEntryForSourceTarget(SvTreeListEntry* pSource, ScItemValue* pOriginalItemValue = pItemValue->mpOriginalItemValue; // Don't allow to add "Data" element to page fields - if(meType == PAGE_LIST && mpParent->IsDataItem(pItemValue->maFunctionData.mnCol)) + if(meType == PAGE_LIST && mpParent->IsDataElement(pItemValue->maFunctionData.mnCol)) return; mpParent->ItemInserted(pOriginalItemValue, meType); diff --git a/sc/source/ui/dbgui/PivotLayoutTreeListBase.cxx b/sc/source/ui/dbgui/PivotLayoutTreeListBase.cxx index ee5b44a5dd7c..5e1f320296e9 100644 --- a/sc/source/ui/dbgui/PivotLayoutTreeListBase.cxx +++ b/sc/source/ui/dbgui/PivotLayoutTreeListBase.cxx @@ -86,23 +86,11 @@ void ScPivotLayoutTreeListBase::PushEntriesToPivotFieldVector(ScPivotFieldVector ScPivotFuncData& rFunctionData = pItemValue->maFunctionData; ScPivotField aField; - aField.nCol = rFunctionData.mnCol; aField.mnOriginalDim = rFunctionData.mnOriginalDim; - - if (rFunctionData.mnFuncMask == PIVOT_FUNC_NONE || - rFunctionData.mnFuncMask == PIVOT_FUNC_AUTO) - { - aField.nFuncMask = PIVOT_FUNC_SUM; - } - else - { - aField.nFuncMask = rFunctionData.mnFuncMask; - } - - aField.mnDupCount = rFunctionData.mnDupCount; - aField.maFieldRef = rFunctionData.maFieldRef; - + aField.nFuncMask = rFunctionData.mnFuncMask; + aField.mnDupCount = rFunctionData.mnDupCount; + aField.maFieldRef = rFunctionData.maFieldRef; rVector.push_back(aField); } } diff --git a/sc/source/ui/dbgui/PivotLayoutTreeListData.cxx b/sc/source/ui/dbgui/PivotLayoutTreeListData.cxx index 8ef80b0c0199..012781ad78d2 100644 --- a/sc/source/ui/dbgui/PivotLayoutTreeListData.cxx +++ b/sc/source/ui/dbgui/PivotLayoutTreeListData.cxx @@ -144,11 +144,37 @@ void ScPivotLayoutTreeListData::FillDataField(ScPivotFieldVector& rDataFields) } } +void ScPivotLayoutTreeListData::PushDataFieldNames(vector<ScDPName>& rDataFieldNames) +{ + SvTreeListEntry* pLoopEntry; + for (pLoopEntry = First(); pLoopEntry != NULL; pLoopEntry = Next(pLoopEntry)) + { + ScItemValue* pEachItemValue = (ScItemValue*) pLoopEntry->GetUserData(); + SCCOL nColumn = pEachItemValue->maFunctionData.mnCol; + + ScDPLabelData* pLabelData = mpParent->GetLabelData(nColumn); + + if (pLabelData == NULL && pLabelData->maName.isEmpty()) + continue; + + OUString sLayoutName = pLabelData->maLayoutName; + if (sLayoutName.isEmpty()) + { + sLayoutName = lclCreateDataItemName( + pEachItemValue->maFunctionData.mnFuncMask, + pEachItemValue->maName, + pEachItemValue->maFunctionData.mnDupCount); + } + + rDataFieldNames.push_back(ScDPName(pLabelData->maName, sLayoutName, pLabelData->mnDupCount)); + } +} + void ScPivotLayoutTreeListData::InsertEntryForSourceTarget(SvTreeListEntry* pSource, SvTreeListEntry* pTarget) { ScItemValue* pItemValue = (ScItemValue*) pSource->GetUserData(); - if(mpParent->IsDataItem(pItemValue->maFunctionData.mnCol)) + if(mpParent->IsDataElement(pItemValue->maFunctionData.mnCol)) return; if (HasEntry(pSource)) diff --git a/sc/source/ui/dbgui/PivotLayoutTreeListLabel.cxx b/sc/source/ui/dbgui/PivotLayoutTreeListLabel.cxx index 023f3ce56fb4..6617b0b03c4a 100644 --- a/sc/source/ui/dbgui/PivotLayoutTreeListLabel.cxx +++ b/sc/source/ui/dbgui/PivotLayoutTreeListLabel.cxx @@ -61,7 +61,7 @@ void ScPivotLayoutTreeListLabel::InsertEntryForSourceTarget(SvTreeListEntry* /*p mpParent->mpPreviouslyFocusedListBox->RemoveSelection(); } -bool ScPivotLayoutTreeListLabel::IsDataItem(SCCOL nColumn) +bool ScPivotLayoutTreeListLabel::IsDataElement(SCCOL nColumn) { return (nColumn == PIVOT_DATA_FIELD || nColumn == maDataItem); } diff --git a/sc/source/ui/inc/PivotLayoutDialog.hxx b/sc/source/ui/inc/PivotLayoutDialog.hxx index b7ad9cd792b0..23099a44c492 100644 --- a/sc/source/ui/inc/PivotLayoutDialog.hxx +++ b/sc/source/ui/inc/PivotLayoutDialog.hxx @@ -122,12 +122,15 @@ public: void UpdateSourceRange(); bool ApplyChanges(); + void ApplySaveData(ScDPSaveData& rSaveData); + void ApplyLabelData(ScDPSaveData& rSaveData); ScItemValue* GetItem(SCCOL nColumn); - bool IsDataItem(SCCOL nColumn); + bool IsDataElement(SCCOL nColumn); ScDPLabelData* GetLabelData(SCCOL nColumn); ScDPLabelDataVector& GetLabelDataVector(); + void PushDataFieldNames(std::vector<ScDPName>& rDataFieldNames); }; diff --git a/sc/source/ui/inc/PivotLayoutTreeListData.hxx b/sc/source/ui/inc/PivotLayoutTreeListData.hxx index 8ba556994980..d58b077cec2b 100644 --- a/sc/source/ui/inc/PivotLayoutTreeListData.hxx +++ b/sc/source/ui/inc/PivotLayoutTreeListData.hxx @@ -25,6 +25,8 @@ public: virtual bool DoubleClickHdl() SAL_OVERRIDE; void FillDataField(ScPivotFieldVector& rDataFields); + void PushDataFieldNames(std::vector<ScDPName>& rDataFieldNames); + protected: virtual void InsertEntryForSourceTarget(SvTreeListEntry* pSource, SvTreeListEntry* pTarget) SAL_OVERRIDE; virtual void InsertEntryForItem(ScItemValue* pItemValue, sal_uLong nPosition) SAL_OVERRIDE; diff --git a/sc/source/ui/inc/PivotLayoutTreeListLabel.hxx b/sc/source/ui/inc/PivotLayoutTreeListLabel.hxx index 7eb8f52158f8..656fb4905715 100644 --- a/sc/source/ui/inc/PivotLayoutTreeListLabel.hxx +++ b/sc/source/ui/inc/PivotLayoutTreeListLabel.hxx @@ -25,7 +25,7 @@ public: virtual ~ScPivotLayoutTreeListLabel(); void FillLabelFields(ScDPLabelDataVector& rLabelVector); ScItemValue* GetItem(SCCOL nColumn); - bool IsDataItem(SCCOL nColumn); + bool IsDataElement(SCCOL nColumn); protected: virtual void InsertEntryForSourceTarget(SvTreeListEntry* pSource, SvTreeListEntry* pTarget) SAL_OVERRIDE; |