diff options
author | Kohei Yoshida <kohei.yoshida@suse.com> | 2012-02-14 16:00:49 -0500 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@suse.com> | 2012-02-14 17:18:59 -0500 |
commit | 9d4b32ef3f1866fa586394c6cceed4dc4a17ca38 (patch) | |
tree | e16783b1204d3884919ce7e0601af17777ca26f2 /sc/source/filter/xml/xmldpimp.cxx | |
parent | 75d807f7b1cc9aa2ef3cf41d6f572aa5a56583a7 (diff) |
Fixed ODS import filter to correctly identify data layout dimension.
And cleaned up the code a bit. The new code should be much more
robust.
Diffstat (limited to 'sc/source/filter/xml/xmldpimp.cxx')
-rw-r--r-- | sc/source/filter/xml/xmldpimp.cxx | 117 |
1 files changed, 75 insertions, 42 deletions
diff --git a/sc/source/filter/xml/xmldpimp.cxx b/sc/source/filter/xml/xmldpimp.cxx index 4d48946d3b4c..91d19cf37169 100644 --- a/sc/source/filter/xml/xmldpimp.cxx +++ b/sc/source/filter/xml/xmldpimp.cxx @@ -230,7 +230,7 @@ ScXMLDataPilotTableContext::ScXMLDataPilotTableContext( ScXMLImport& rImport, } pDPObject = new ScDPObject(pDoc); - pDPSave = new ScDPSaveData(); + pDPSave = new ScDPSaveData(); } ScXMLDataPilotTableContext::~ScXMLDataPilotTableContext() @@ -295,14 +295,49 @@ SvXMLImportContext *ScXMLDataPilotTableContext::CreateChildContext( sal_uInt16 n return pContext; } +namespace { + +const ScDPSaveDimension* getDimension( + const std::vector<const ScDPSaveDimension*>& rRowDims, + const std::vector<const ScDPSaveDimension*>& rColDims, + ScDPOutputGeometry::FieldType eType, size_t nPos) +{ + switch (eType) + { + case ScDPOutputGeometry::Column: + { + if (rColDims.size() <= nPos) + return NULL; + + return rColDims[nPos]; + } + case ScDPOutputGeometry::Row: + { + if (rRowDims.size() <= nPos) + return NULL; + + return rRowDims[nPos]; + } + default: + ; + } + return NULL; +} + +} + void ScXMLDataPilotTableContext::SetButtons() { - ScDPOutputGeometry aGeometry(aTargetRangeAddress, bShowFilter, ScDPOutputGeometry::ODF); + ScDPOutputGeometry aGeometry(aTargetRangeAddress, bShowFilter); aGeometry.setColumnFieldCount(mnColFieldCount); aGeometry.setRowFieldCount(mnRowFieldCount); aGeometry.setPageFieldCount(mnPageFieldCount); aGeometry.setDataFieldCount(mnDataFieldCount); + std::vector<const ScDPSaveDimension*> aRowDims, aColDims, aPageDims; + pDPSave->GetAllDimensionsByOrientation(sheet::DataPilotFieldOrientation_ROW, aRowDims); + pDPSave->GetAllDimensionsByOrientation(sheet::DataPilotFieldOrientation_COLUMN, aColDims); + OUString sAddress; sal_Int32 nOffset = 0; while( nOffset >= 0 ) @@ -314,20 +349,20 @@ void ScXMLDataPilotTableContext::SetButtons() sal_Int32 nAddrOffset(0); if (pDoc && ScRangeStringConverter::GetAddressFromString( aScAddress, sAddress, pDoc, ::formula::FormulaGrammar::CONV_OOO, nAddrOffset )) { - ScDPOutputGeometry::FieldType eType = aGeometry.getFieldButtonType(aScAddress); + std::pair<ScDPOutputGeometry::FieldType, size_t> aBtnType = aGeometry.getFieldButtonType(aScAddress); + const ScDPSaveDimension* pDim = getDimension( + aRowDims, aColDims, aBtnType.first, aBtnType.second); - sal_Int16 nMFlag = SC_MF_BUTTON; - if (eType == ScDPOutputGeometry::Column || eType == ScDPOutputGeometry::Row) - nMFlag |= SC_MF_BUTTON_POPUP; + bool bDataLayout = pDim && pDim->IsDataLayout(); + bool bHasHidden = pDim && pDim->HasInvisibleMember(); - // Use the cell's string value to see if this field contains a - // hidden member. Isn't there a better way? GetString() is - // quite expensive... - String aCellStr; - pDoc->GetString(aScAddress.Col(), aScAddress.Row(), aScAddress.Tab(), aCellStr); - if (maHiddenMemberFields.count(aCellStr)) + sal_Int16 nMFlag = SC_MF_BUTTON; + if (bHasHidden) nMFlag |= SC_MF_HIDDEN_MEMBER; + if (!bDataLayout) + nMFlag |= SC_MF_BUTTON_POPUP; + pDoc->ApplyFlagsTab(aScAddress.Col(), aScAddress.Row(), aScAddress.Col(), aScAddress.Row(), aScAddress.Tab(), nMFlag); } } @@ -345,40 +380,38 @@ void ScXMLDataPilotTableContext::AddDimension(ScDPSaveDimension* pDim, bool bHas // mark the new one as duplicate if ( !pDim->IsDataLayout() && pDPSave->GetExistingDimensionByName(pDim->GetName()) ) - pDim->SetDupFlag( sal_True ); + pDim->SetDupFlag(true); - if (!pDim->IsDataLayout()) + switch (pDim->GetOrientation()) { - switch (pDim->GetOrientation()) - { - case sheet::DataPilotFieldOrientation_ROW: - ++mnRowFieldCount; - break; - case sheet::DataPilotFieldOrientation_COLUMN: - ++mnColFieldCount; - break; - case sheet::DataPilotFieldOrientation_PAGE: - ++mnPageFieldCount; - break; - case sheet::DataPilotFieldOrientation_DATA: - ++mnDataFieldCount; - break; - case sheet::DataPilotFieldOrientation_HIDDEN: - default: - ; - } + case sheet::DataPilotFieldOrientation_ROW: + ++mnRowFieldCount; + break; + case sheet::DataPilotFieldOrientation_COLUMN: + ++mnColFieldCount; + break; + case sheet::DataPilotFieldOrientation_PAGE: + ++mnPageFieldCount; + break; + case sheet::DataPilotFieldOrientation_DATA: + ++mnDataFieldCount; + break; + case sheet::DataPilotFieldOrientation_HIDDEN: + default: + ; + } - if (bHasHiddenMember) - { - // the layout name takes priority over the original name, - // since this data is used against cell values. - const OUString* pLayoutName = pDim->GetLayoutName(); - if (pLayoutName) - maHiddenMemberFields.insert(*pLayoutName); - else - maHiddenMemberFields.insert(pDim->GetName()); - } + if (bHasHiddenMember) + { + // the layout name takes priority over the original name, + // since this data is used against cell values. + const OUString* pLayoutName = pDim->GetLayoutName(); + if (pLayoutName) + maHiddenMemberFields.insert(*pLayoutName); + else + maHiddenMemberFields.insert(pDim->GetName()); } + pDPSave->AddDimension(pDim); } } |