sc/inc/dapiuno.hxx | 15 ++++ sc/source/filter/inc/pivotcachebuffer.hxx | 12 +-- sc/source/filter/inc/pivottablebuffer.hxx | 16 ++--- sc/source/filter/oox/pivotcachebuffer.cxx | 32 ++++------ sc/source/filter/oox/pivottablebuffer.cxx | 93 ++++++++++++++---------------- sc/source/ui/unoobj/dapiuno.cxx | 78 ++++++++++++++++++------- 6 files changed, 143 insertions(+), 103 deletions(-)
New commits: commit 56384aa312dff642962db8d2792c9f66d0b08707 Author: Noel Grandin <[email protected]> AuthorDate: Sat Dec 20 13:50:57 2025 +0200 Commit: Noel Grandin <[email protected]> CommitDate: Sun Dec 21 07:43:05 2025 +0100 use more concrete UNO in pivot cache Change-Id: I98934d9195a926c16481e14922d3a3022dad9d53 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/195994 Tested-by: Jenkins Reviewed-by: Noel Grandin <[email protected]> diff --git a/sc/inc/dapiuno.hxx b/sc/inc/dapiuno.hxx index c3f504dfe894..f62738d81cdc 100644 --- a/sc/inc/dapiuno.hxx +++ b/sc/inc/dapiuno.hxx @@ -126,6 +126,8 @@ public: virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; }; +class ScDataPilotFieldsObj; + // ScDataPilotDescriptorBase is never instantiated directly class SAL_DLLPUBLIC_RTTI ScDataPilotDescriptorBase : public cppu::WeakImplHelper< css::sheet::XDataPilotDescriptor, @@ -191,6 +193,9 @@ public: SAL_CALL getDataLayoutField() override; // XServiceInfo is in derived classes + + SC_DLLPUBLIC rtl::Reference<ScDataPilotFieldsObj> getScDataPilotFields(); + SC_DLLPUBLIC rtl::Reference<ScDataPilotFieldObj> getScDataLayoutField(); }; class ScDataPilotDescriptor final : public ScDataPilotDescriptorBase @@ -364,6 +369,9 @@ public: virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override; virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; + SC_DLLPUBLIC rtl::Reference<ScDataPilotFieldObj> getScDataPilotFieldObjByIndex( sal_Int32 nIndex ); + SC_DLLPUBLIC rtl::Reference<ScDataPilotFieldObj> getScDataPilotFieldObjByName( const OUString& aName ); + private: rtl::Reference<ScDataPilotFieldObj> GetObjectByIndex_Impl( sal_Int32 nIndex ) const; rtl::Reference<ScDataPilotFieldObj> GetObjectByName_Impl( const OUString& rName ) const; @@ -398,7 +406,7 @@ public: virtual ~ScDataPilotFieldObj() override; // XNamed - virtual OUString SAL_CALL getName() override; + SC_DLLPUBLIC virtual OUString SAL_CALL getName() override; virtual void SAL_CALL setName(const OUString& aName) override; // XPropertySet @@ -457,6 +465,11 @@ public: virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override; virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; + SC_DLLPUBLIC rtl::Reference< ScDataPilotFieldObj > + createNameGroup(const std::vector< OUString >& aItems); + SC_DLLPUBLIC rtl::Reference< ScDataPilotFieldObj > + createScDateGroup(const css::sheet::DataPilotFieldGroupInfo& rInfo); + private: css::uno::Reference< css::container::XIndexAccess > mxItems; diff --git a/sc/source/filter/inc/pivotcachebuffer.hxx b/sc/source/filter/inc/pivotcachebuffer.hxx index 35f266cb9068..14dd13ab886f 100644 --- a/sc/source/filter/inc/pivotcachebuffer.hxx +++ b/sc/source/filter/inc/pivotcachebuffer.hxx @@ -26,16 +26,12 @@ namespace oox { class AttributeList; } namespace oox { class SequenceInputStream; } - -namespace com::sun::star { - namespace sheet { class XDataPilotField; } -} - namespace oox::core { class Relations; } class ScDPSaveDimension; class ScDPObject; class Date; +class ScDataPilotFieldObj; namespace oox::xls { @@ -268,13 +264,13 @@ public: /** Creates inplace numeric grouping settings. */ void convertNumericGrouping( - const css::uno::Reference< css::sheet::XDataPilotField >& rxDPField ) const; + const rtl::Reference< ScDataPilotFieldObj >& rxDPField ) const; /** Creates inplace date grouping settings or a new date group field. */ OUString createDateGroupField( - const css::uno::Reference< css::sheet::XDataPilotField >& rxBaseDPField ) const; + const rtl::Reference< ScDataPilotFieldObj >& rxBaseDPField ) const; /** Creates a new grouped DataPilot field and returns its name. */ OUString createParentGroupField( - const css::uno::Reference< css::sheet::XDataPilotField >& rxBaseDPField, + const rtl::Reference< ScDataPilotFieldObj >& rxBaseDPField, const PivotCacheField& rBaseCacheField, PivotCacheGroupItemVector& orItemNames ) const; diff --git a/sc/source/filter/inc/pivottablebuffer.hxx b/sc/source/filter/inc/pivottablebuffer.hxx index fe304a8e3083..a82c64cb5fcd 100644 --- a/sc/source/filter/inc/pivottablebuffer.hxx +++ b/sc/source/filter/inc/pivottablebuffer.hxx @@ -143,11 +143,11 @@ public: void finalizeImport(const rtl::Reference<ScDataPilotDescriptorBase>& rxDPDesc); /** Finalizes the grouped date field after import. */ void finalizeDateGroupingImport( - const css::uno::Reference< css::sheet::XDataPilotField >& rxBaseDPField, + const rtl::Reference< ScDataPilotFieldObj >& rxBaseDPField, sal_Int32 nBaseFieldIdx ); /** Finalizes the grouped field after import. */ void finalizeParentGroupingImport( - const css::uno::Reference< css::sheet::XDataPilotField >& rxBaseDPField, + const rtl::Reference< ScDataPilotFieldObj >& rxBaseDPField, const PivotCacheField& rBaseCacheField, PivotCacheGroupItemVector& orItemNames ); void finalizeImportBasedOnCache(const rtl::Reference<ScDataPilotDescriptorBase>& rxDPDesc); @@ -168,7 +168,7 @@ public: private: /** Converts dimension and other settings for row, column, page, or hidden fields. */ - css::uno::Reference< css::sheet::XDataPilotField > + rtl::Reference< ScDataPilotFieldObj > convertRowColPageField( sal_Int32 nAxis ); private: @@ -323,22 +323,22 @@ public: void finalizeFieldsImport(); /** Creates all date group fields for the specified cache field after import. */ void finalizeDateGroupingImport( - const css::uno::Reference< css::sheet::XDataPilotField >& rxBaseDPField, + const rtl::Reference< ScDataPilotFieldObj >& rxBaseDPField, sal_Int32 nBaseFieldIdx ); /** Creates all grouped fields for the specified cache field after import. */ void finalizeParentGroupingImport( - const css::uno::Reference< css::sheet::XDataPilotField >& rxBaseDPField, + const rtl::Reference< ScDataPilotFieldObj >& rxBaseDPField, const PivotCacheField& rBaseCacheField, PivotCacheGroupItemVector& orItemNames ); /** Returns the associated data pilot field for the specified pivot table field. */ - css::uno::Reference< css::sheet::XDataPilotField > + rtl::Reference< ScDataPilotFieldObj > getDataPilotField( const OUString& rFieldName ) const; /** Returns the associated data pilot field for the specified pivot table field. */ - css::uno::Reference< css::sheet::XDataPilotField > + rtl::Reference< ScDataPilotFieldObj > getDataPilotField( sal_Int32 nFieldIdx ) const; /** Returns the data layout field used to store all data fields in row/col dimension. */ - css::uno::Reference< css::sheet::XDataPilotField > + rtl::Reference< ScDataPilotFieldObj > getDataLayoutField() const; /** Returns the cache field with the specified index. */ diff --git a/sc/source/filter/oox/pivotcachebuffer.cxx b/sc/source/filter/oox/pivotcachebuffer.cxx index d6173e12f64e..e5b3bf37aa03 100644 --- a/sc/source/filter/oox/pivotcachebuffer.cxx +++ b/sc/source/filter/oox/pivotcachebuffer.cxx @@ -50,6 +50,7 @@ #include <tools/datetime.hxx> #include <addressconverter.hxx> #include <biffhelper.hxx> +#include <dapiuno.hxx> namespace oox::xls { @@ -598,10 +599,10 @@ const PivotCacheItemList& PivotCacheField::getCacheItems() const return maSharedItems; } -void PivotCacheField::convertNumericGrouping( const Reference< XDataPilotField >& rxDPField ) const +void PivotCacheField::convertNumericGrouping( const rtl::Reference< ScDataPilotFieldObj >& rxDPField ) const { OSL_ENSURE( hasGroupItems() && hasNumericGrouping(), "PivotCacheField::convertNumericGrouping - not a numeric group field" ); - PropertySet aPropSet( rxDPField ); + PropertySet aPropSet(( css::uno::Reference< css::beans::XPropertySet >(rxDPField) )); if( hasGroupItems() && hasNumericGrouping() && aPropSet.is() ) { DataPilotFieldGroupInfo aGroupInfo; @@ -616,11 +617,11 @@ void PivotCacheField::convertNumericGrouping( const Reference< XDataPilotField > } } -OUString PivotCacheField::createDateGroupField( const Reference< XDataPilotField >& rxBaseDPField ) const +OUString PivotCacheField::createDateGroupField( const rtl::Reference< ScDataPilotFieldObj >& rxBaseDPField ) const { OSL_ENSURE( hasGroupItems() && hasDateGrouping(), "PivotCacheField::createDateGroupField - not a numeric group field" ); - Reference< XDataPilotField > xDPGroupField; - PropertySet aPropSet( rxBaseDPField ); + rtl::Reference< ScDataPilotFieldObj > xDPGroupField; + PropertySet aPropSet(( css::uno::Reference< css::beans::XPropertySet >(rxBaseDPField) )); if( hasGroupItems() && hasDateGrouping() && aPropSet.is() ) { bool bDayRanges = (maFieldGroupModel.mnGroupBy == XML_days) && (maFieldGroupModel.mfInterval >= 2.0); @@ -648,24 +649,22 @@ OUString PivotCacheField::createDateGroupField( const Reference< XDataPilotField try { - Reference< XDataPilotFieldGrouping > xDPGrouping( rxBaseDPField, UNO_QUERY_THROW ); - xDPGroupField = xDPGrouping->createDateGroup( aGroupInfo ); + xDPGroupField = rxBaseDPField->createScDateGroup( aGroupInfo ); } catch( Exception& ) { } } - Reference< XNamed > xFieldName( xDPGroupField, UNO_QUERY ); - return xFieldName.is() ? xFieldName->getName() : OUString(); + return xDPGroupField.is() ? xDPGroupField->getName() : OUString(); } -OUString PivotCacheField::createParentGroupField( const Reference< XDataPilotField >& rxBaseDPField, const PivotCacheField& rBaseCacheField, PivotCacheGroupItemVector& orItemNames ) const +OUString PivotCacheField::createParentGroupField( const rtl::Reference< ScDataPilotFieldObj >& rxBaseDPField, const PivotCacheField& rBaseCacheField, PivotCacheGroupItemVector& orItemNames ) const { SAL_WARN_IF( !hasGroupItems() || maDiscreteItems.empty(), "sc", "PivotCacheField::createParentGroupField - not a group field" ); SAL_WARN_IF( maDiscreteItems.size() != orItemNames.size(), "sc", "PivotCacheField::createParentGroupField - number of item names does not match grouping info" ); - Reference< XDataPilotFieldGrouping > xDPGrouping( rxBaseDPField, UNO_QUERY ); - if( !xDPGrouping.is() ) return OUString(); + if( !rxBaseDPField.is() ) + return OUString(); // map the group item indexes from maGroupItems to all item indexes from maDiscreteItems std::vector< std::vector<sal_Int32> > aItemMap( maGroupItems.size() ); @@ -686,7 +685,7 @@ OUString PivotCacheField::createParentGroupField( const Reference< XDataPilotFie } // process all groups - Reference< XDataPilotField > xDPGroupField; + rtl::Reference< ScDataPilotFieldObj > xDPGroupField; nIndex = 0; for( const auto& rItems : aItemMap ) { @@ -711,14 +710,14 @@ OUString PivotCacheField::createParentGroupField( const Reference< XDataPilotFie if( !aMembers.empty() ) try { // only the first call of createNameGroup() returns the new field - Reference< XDataPilotField > xDPNewField = xDPGrouping->createNameGroup( comphelper::containerToSequence( aMembers ) ); + rtl::Reference< ScDataPilotFieldObj > xDPNewField = rxBaseDPField->createNameGroup( aMembers ); SAL_WARN_IF( xDPGroupField.is() == xDPNewField.is(), "sc", "PivotCacheField::createParentGroupField - missing group field" ); if( !xDPGroupField.is() ) xDPGroupField = std::move(xDPNewField); // get current grouping info DataPilotFieldGroupInfo aGroupInfo; - PropertySet aPropSet( xDPGroupField ); + PropertySet aPropSet(( css::uno::Reference< css::beans::XPropertySet >(xDPGroupField) )); aPropSet.getProperty( aGroupInfo, PROP_GroupInfo ); /* Find the group object and the auto-generated group name. @@ -782,8 +781,7 @@ OUString PivotCacheField::createParentGroupField( const Reference< XDataPilotFie ++nIndex; } - Reference< XNamed > xFieldName( xDPGroupField, UNO_QUERY ); - return xFieldName.is() ? xFieldName->getName() : OUString(); + return xDPGroupField.is() ? xDPGroupField->getName() : OUString(); } void PivotCacheField::writeSourceHeaderCell( const WorksheetHelper& rSheetHelper, sal_Int32 nCol, sal_Int32 nRow ) const diff --git a/sc/source/filter/oox/pivottablebuffer.cxx b/sc/source/filter/oox/pivottablebuffer.cxx index 37a1ddfaf3ce..c72d79570817 100644 --- a/sc/source/filter/oox/pivottablebuffer.cxx +++ b/sc/source/filter/oox/pivottablebuffer.cxx @@ -388,7 +388,7 @@ void PivotTableField::finalizeImport(const rtl::Reference<ScDataPilotDescriptorB /* Process all fields based on source data, other fields (e.g. group fields) are processed from here. PivotCache::getCacheDatabaseIndex() returns -1 for all fields not based on source data. */ - Reference< XDataPilotField > xDPField; + rtl::Reference< ScDataPilotFieldObj > xDPField; sal_Int32 nDatabaseIdx = mrPivotTable.getCacheDatabaseIndex( mnFieldIndex ); if( !((nDatabaseIdx >= 0) && rxDPDesc.is()) ) return; @@ -396,8 +396,8 @@ void PivotTableField::finalizeImport(const rtl::Reference<ScDataPilotDescriptorB try { // try to get the source field and its name from passed DataPilot descriptor - Reference< XIndexAccess > xDPFieldsIA( rxDPDesc->getDataPilotFields(), UNO_SET_THROW ); - xDPField.set( xDPFieldsIA->getByIndex( nDatabaseIdx ), UNO_QUERY_THROW ); + rtl::Reference< ScDataPilotFieldsObj > xDPFieldsIA( rxDPDesc->getScDataPilotFields() ); + xDPField = xDPFieldsIA->getScDataPilotFieldObjByIndex( nDatabaseIdx ); } catch( Exception& ) { @@ -438,8 +438,7 @@ void PivotTableField::finalizeImport(const rtl::Reference<ScDataPilotDescriptorB else { // No choice - check the sheet for field name - Reference< XNamed > xDPFieldName( xDPField, UNO_QUERY_THROW ); - maDPFieldName = xDPFieldName->getName(); + maDPFieldName = xDPField->getName(); OSL_ENSURE( !maDPFieldName.isEmpty(), "PivotTableField::finalizeImport - no field name in source data found" ); } } @@ -448,7 +447,7 @@ void PivotTableField::finalizeImport(const rtl::Reference<ScDataPilotDescriptorB } } -void PivotTableField::finalizeDateGroupingImport( const Reference< XDataPilotField >& rxBaseDPField, sal_Int32 nBaseFieldIdx ) +void PivotTableField::finalizeDateGroupingImport( const rtl::Reference< ScDataPilotFieldObj >& rxBaseDPField, sal_Int32 nBaseFieldIdx ) { if( maDPFieldName.isEmpty() ) // prevent endless loops if file format is broken { @@ -464,7 +463,7 @@ void PivotTableField::finalizeDateGroupingImport( const Reference< XDataPilotFie } } -void PivotTableField::finalizeParentGroupingImport( const Reference< XDataPilotField >& rxBaseDPField, const PivotCacheField& rBaseCacheField, PivotCacheGroupItemVector& orItemNames ) +void PivotTableField::finalizeParentGroupingImport( const rtl::Reference< ScDataPilotFieldObj >& rxBaseDPField, const PivotCacheField& rBaseCacheField, PivotCacheGroupItemVector& orItemNames ) { if( !maDPFieldName.isEmpty() ) // prevent endless loops if file format is broken return; @@ -487,7 +486,7 @@ void PivotTableField::finalizeParentGroupingImport( const Reference< XDataPilotF maDPFieldName = pCacheField->createParentGroupField( rxBaseDPField, rBaseCacheField, orItemNames ); pCacheField->setFinalGroupName(maDPFieldName); // on success, try to create nested group fields - Reference< XDataPilotField > xDPField = mrPivotTable.getDataPilotField( maDPFieldName ); + rtl::Reference< ScDataPilotFieldObj > xDPField = mrPivotTable.getDataPilotField( maDPFieldName ); if( xDPField.is() ) mrPivotTable.finalizeParentGroupingImport( xDPField, *pCacheField, orItemNames ); } @@ -497,20 +496,19 @@ void PivotTableField::finalizeImportBasedOnCache( { /* Process all fields based on source data, other fields (e.g. group fields) are processed based on cache fields.*/ - Reference< XDataPilotField > xDPField; + rtl::Reference< ScDataPilotFieldObj > xDPField; sal_Int32 nDatabaseIdx = mrPivotTable.getCacheDatabaseIndex( mnFieldIndex ); - if( (nDatabaseIdx >= 0) && rxDPDesc.is() ) try - { - // Try to get the source field and its name from passed DataPilot descriptor - Reference< XIndexAccess > xDPFieldsIA( rxDPDesc->getDataPilotFields(), UNO_SET_THROW ); - xDPField.set( xDPFieldsIA->getByIndex( nDatabaseIdx ), UNO_QUERY_THROW ); - Reference< XNamed > xDPFieldName( xDPField, UNO_QUERY_THROW ); - maDPFieldName = xDPFieldName->getName(); - SAL_WARN_IF( maDPFieldName.isEmpty(), "sc.filter", "PivotTableField::finalizeImportBasedOnCache - no field name in source data found" ); - } - catch( Exception& ) - { - } + if( (nDatabaseIdx >= 0) && rxDPDesc.is() ) + try + { + // Try to get the source field and its name from passed DataPilot descriptor + xDPField = rxDPDesc->getScDataPilotFields()->getScDataPilotFieldObjByIndex( nDatabaseIdx ); + maDPFieldName = xDPField->getName(); + SAL_WARN_IF( maDPFieldName.isEmpty(), "sc.filter", "PivotTableField::finalizeImportBasedOnCache - no field name in source data found" ); + } + catch( Exception& ) + { + } // Use group names already generated for another table using the same group field. if( const PivotCacheField* pCacheField = mrPivotTable.getCacheField( mnFieldIndex ) ) @@ -539,12 +537,12 @@ void PivotTableField::convertPageField( const PTPageFieldModel& rPageField ) { OSL_ENSURE( rPageField.mnField == mnFieldIndex, "PivotTableField::convertPageField - wrong field index" ); // convert all settings common for row/column/page fields - Reference< XDataPilotField > xDPField = convertRowColPageField( XML_axisPage ); + rtl::Reference< ScDataPilotFieldObj > xDPField = convertRowColPageField( XML_axisPage ); if( !xDPField.is() ) return; - PropertySet aPropSet( xDPField ); + PropertySet aPropSet(( css::uno::Reference< css::beans::XPropertySet >(xDPField) )); // find cache item used as 'selected page' sal_Int32 nCacheItem = -1; @@ -593,11 +591,11 @@ void PivotTableField::convertDataField( const PTDataFieldModel& rDataField ) { OSL_ENSURE( rDataField.mnField == mnFieldIndex, "PivotTableField::convertDataField - wrong field index" ); OSL_ENSURE( maModel.mbDataField, "PivotTableField::convertDataField - not a data field" ); - Reference< XDataPilotField > xDPField = mrPivotTable.getDataPilotField( maDPFieldName ); + rtl::Reference< ScDataPilotFieldObj > xDPField = mrPivotTable.getDataPilotField( maDPFieldName ); if( !xDPField.is() ) return; - PropertySet aPropSet( xDPField ); + PropertySet aPropSet(( css::uno::Reference< css::beans::XPropertySet >(xDPField) )); // field orientation aPropSet.setProperty( PROP_Orientation, DataPilotFieldOrientation_DATA ); @@ -671,10 +669,10 @@ void PivotTableField::convertDataField( const PTDataFieldModel& rDataField ) // private -------------------------------------------------------------------- -Reference< XDataPilotField > PivotTableField::convertRowColPageField( sal_Int32 nAxis ) +rtl::Reference< ScDataPilotFieldObj > PivotTableField::convertRowColPageField( sal_Int32 nAxis ) { bool bDataLayout = mnFieldIndex == OOX_PT_DATALAYOUTFIELD; - Reference< XDataPilotField > xDPField = bDataLayout ? mrPivotTable.getDataLayoutField() : mrPivotTable.getDataPilotField( maDPFieldName ); + rtl::Reference< ScDataPilotFieldObj > xDPField = bDataLayout ? mrPivotTable.getDataLayoutField() : mrPivotTable.getDataPilotField( maDPFieldName ); OSL_ENSURE( bDataLayout || (nAxis == maModel.mnAxis), "PivotTableField::convertRowColPageField - field axis mismatch" ); if( xDPField.is() ) @@ -682,7 +680,7 @@ Reference< XDataPilotField > PivotTableField::convertRowColPageField( sal_Int32 // TODO: Use this to set properties directly, bypassing the slow uno layer. ScDPObject* pDPObj = mrPivotTable.getDPObject(); - PropertySet aPropSet( xDPField ); + PropertySet aPropSet(( css::uno::Reference< css::beans::XPropertySet >(xDPField) )); // field orientation DataPilotFieldOrientation eFieldOrient = DataPilotFieldOrientation_HIDDEN; @@ -926,7 +924,7 @@ void PivotTableFilter::finalizeImport() if( maModel.mnType != XML_count ) return; - PropertySet aPropSet( mrPivotTable.getDataPilotField( maModel.mnField ) ); + PropertySet aPropSet( css::uno::Reference< css::beans::XPropertySet >(mrPivotTable.getDataPilotField( maModel.mnField )) ); if( aPropSet.is() ) { DataPilotFieldAutoShowInfo aAutoShowInfo; @@ -1387,13 +1385,14 @@ void PivotTable::finalizeFieldsImport() maFields.forEachMem(&PivotTableField::finalizeImport, ::std::cref(mxDPDescriptor)); } -void PivotTable::finalizeDateGroupingImport( const Reference< XDataPilotField >& rxBaseDPField, sal_Int32 nBaseFieldIdx ) +void PivotTable::finalizeDateGroupingImport( const rtl::Reference< ScDataPilotFieldObj >& rxBaseDPField, sal_Int32 nBaseFieldIdx ) { // process all fields, there is no chaining information in the cache fields - maFields.forEachMem( &PivotTableField::finalizeDateGroupingImport, ::std::cref(rxBaseDPField), nBaseFieldIdx ); + for (const auto & rField : maFields) + rField->finalizeDateGroupingImport( rxBaseDPField, nBaseFieldIdx ); } -void PivotTable::finalizeParentGroupingImport( const Reference< XDataPilotField >& rxBaseDPField, +void PivotTable::finalizeParentGroupingImport( const rtl::Reference< ScDataPilotFieldObj >& rxBaseDPField, const PivotCacheField& rBaseCacheField, PivotCacheGroupItemVector& orItemNames ) { // try to create parent group fields that group the items of the passed base field @@ -1401,35 +1400,35 @@ void PivotTable::finalizeParentGroupingImport( const Reference< XDataPilotField pParentTableField->finalizeParentGroupingImport( rxBaseDPField, rBaseCacheField, orItemNames ); } -Reference< XDataPilotField > PivotTable::getDataPilotField( const OUString& rFieldName ) const +rtl::Reference< ScDataPilotFieldObj > PivotTable::getDataPilotField( const OUString& rFieldName ) const { - Reference< XDataPilotField > xDPField; - if( !rFieldName.isEmpty() && mxDPDescriptor.is() ) try - { - Reference< XNameAccess > xDPFieldsNA( mxDPDescriptor->getDataPilotFields(), UNO_QUERY_THROW ); - xDPField.set( xDPFieldsNA->getByName( rFieldName ), UNO_QUERY ); - } - catch( Exception& ) - { - } + rtl::Reference< ScDataPilotFieldObj > xDPField; + if( !rFieldName.isEmpty() && mxDPDescriptor.is() ) + try + { + xDPField = mxDPDescriptor->getScDataPilotFields()->getScDataPilotFieldObjByName(rFieldName); + } + catch( Exception& ) + { + } return xDPField; } -Reference< XDataPilotField > PivotTable::getDataPilotField( sal_Int32 nFieldIdx ) const +rtl::Reference< ScDataPilotFieldObj > PivotTable::getDataPilotField( sal_Int32 nFieldIdx ) const { - Reference< XDataPilotField > xDPField; + rtl::Reference< ScDataPilotFieldObj > xDPField; if( const PivotTableField* pTableField = maFields.get( nFieldIdx ).get() ) xDPField = getDataPilotField( pTableField->getDPFieldName() ); return xDPField; } -Reference< XDataPilotField > PivotTable::getDataLayoutField() const +rtl::Reference< ScDataPilotFieldObj > PivotTable::getDataLayoutField() const { - Reference< XDataPilotField > xDPField; + rtl::Reference< ScDataPilotFieldObj > xDPField; try { if (mxDPDescriptor) - xDPField = mxDPDescriptor->getDataLayoutField(); + xDPField = mxDPDescriptor->getScDataLayoutField(); } catch( Exception& ) { diff --git a/sc/source/ui/unoobj/dapiuno.cxx b/sc/source/ui/unoobj/dapiuno.cxx index ed95a593bd54..8d0b5bd9605b 100644 --- a/sc/source/ui/unoobj/dapiuno.cxx +++ b/sc/source/ui/unoobj/dapiuno.cxx @@ -649,6 +649,12 @@ Reference<XIndexAccess> SAL_CALL ScDataPilotDescriptorBase::getDataPilotFields() return new ScDataPilotFieldsObj( *this ); } +rtl::Reference<ScDataPilotFieldsObj> ScDataPilotDescriptorBase::getScDataPilotFields() +{ + SolarMutexGuard aGuard; + return new ScDataPilotFieldsObj( *this ); +} + Reference<XIndexAccess> SAL_CALL ScDataPilotDescriptorBase::getColumnFields() { SolarMutexGuard aGuard; @@ -957,6 +963,11 @@ void SAL_CALL ScDataPilotDescriptorBase::removeVetoableChangeListener( // XDataPilotDataLayoutFieldSupplier Reference< XDataPilotField > SAL_CALL ScDataPilotDescriptorBase::getDataLayoutField() +{ + return getScDataLayoutField(); +} + +rtl::Reference< ScDataPilotFieldObj > ScDataPilotDescriptorBase::getScDataLayoutField() { SolarMutexGuard aGuard; if( ScDPObject* pDPObject = GetDPObject() ) @@ -1565,6 +1576,15 @@ Any SAL_CALL ScDataPilotFieldsObj::getByIndex( sal_Int32 nIndex ) return Any( Reference< XPropertySet >(xField) ); } +rtl::Reference<ScDataPilotFieldObj> ScDataPilotFieldsObj::getScDataPilotFieldObjByIndex( sal_Int32 nIndex ) +{ + SolarMutexGuard aGuard; + rtl::Reference< ScDataPilotFieldObj > xField( GetObjectByIndex_Impl( nIndex ) ); + if (!xField.is()) + throw IndexOutOfBoundsException(); + return xField; +} + // XElementAccess uno::Type SAL_CALL ScDataPilotFieldsObj::getElementType() @@ -1589,6 +1609,15 @@ Any SAL_CALL ScDataPilotFieldsObj::getByName( const OUString& aName ) return Any( Reference<XPropertySet>(xField) ); } +rtl::Reference<ScDataPilotFieldObj> ScDataPilotFieldsObj::getScDataPilotFieldObjByName( const OUString& aName ) +{ + SolarMutexGuard aGuard; + rtl::Reference<ScDataPilotFieldObj> xField(GetObjectByName_Impl(aName)); + if (!xField.is()) + throw NoSuchElementException(); + return xField; +} + Sequence<OUString> SAL_CALL ScDataPilotFieldsObj::getElementNames() { SolarMutexGuard aGuard; @@ -2384,10 +2413,15 @@ void ScDataPilotFieldObj::setGroupInfo( const DataPilotFieldGroupInfo* pInfo ) // XDataPilotFieldGrouping Reference< XDataPilotField > SAL_CALL ScDataPilotFieldObj::createNameGroup( const Sequence< OUString >& rItems ) +{ + return createNameGroup(comphelper::sequenceToContainer<std::vector<OUString>>(rItems)); +} + +rtl::Reference< ScDataPilotFieldObj > ScDataPilotFieldObj::createNameGroup( const std::vector< OUString >& rItems ) { SolarMutexGuard aGuard; - if( !rItems.hasElements() ) + if( rItems.empty() ) throw IllegalArgumentException(u"rItems is empty"_ustr, getXWeak(), 0); Reference< XMembersAccess > xMembers = GetMembers(); @@ -2406,7 +2440,7 @@ Reference< XDataPilotField > SAL_CALL ScDataPilotFieldObj::createNameGroup( cons } } - Reference< XDataPilotField > xRet; + rtl::Reference< ScDataPilotFieldObj > xRet; OUString sNewDim; ScDPObject* pDPObj = nullptr; if( ScDPSaveDimension* pDim = GetDPDimension( &pDPObj ) ) @@ -2473,7 +2507,7 @@ Reference< XDataPilotField > SAL_CALL ScDataPilotFieldObj::createNameGroup( cons { const ScDPSaveGroupItem& rBaseGroup = pBaseGroupDim->GetGroupByIndex( nGroup ); - if (comphelper::findValue(rItems, rBaseGroup.GetGroupName()) == -1) //! ignore case? + if (std::find(rItems.begin(), rItems.end(), rBaseGroup.GetGroupName()) == rItems.end()) //! ignore case? { // add an additional group for each item that is not in the selection ScDPSaveGroupItem aGroup( rBaseGroup.GetGroupName() ); @@ -2528,29 +2562,30 @@ Reference< XDataPilotField > SAL_CALL ScDataPilotFieldObj::createNameGroup( cons // if new grouping field has been created (on first group), return it if( !sNewDim.isEmpty() ) { - Reference< XNameAccess > xFields(mxParent->getDataPilotFields(), UNO_QUERY); - if (xFields.is()) + try { - try - { - xRet.set(xFields->getByName(sNewDim), UNO_QUERY); - SAL_WARN_IF(!xRet.is(), "sc.ui", "there is a name, so there should be also a field"); - } - catch (const container::NoSuchElementException&) - { - css::uno::Any anyEx = cppu::getCaughtException(); - SAL_WARN("sc.ui", "Cannot find field with that name: " + sNewDim + "."); - // Avoid throwing exception that's not specified in the method signature. - throw css::lang::WrappedTargetRuntimeException( - "Cannot find field with name \"" + sNewDim + "\"", - getXWeak(), anyEx ); - } + xRet = mxParent->getScDataPilotFields()->getScDataPilotFieldObjByName(sNewDim); + SAL_WARN_IF(!xRet.is(), "sc.ui", "there is a name, so there should be also a field"); + } + catch (const container::NoSuchElementException&) + { + css::uno::Any anyEx = cppu::getCaughtException(); + SAL_WARN("sc.ui", "Cannot find field with that name: " + sNewDim + "."); + // Avoid throwing exception that's not specified in the method signature. + throw css::lang::WrappedTargetRuntimeException( + "Cannot find field with name \"" + sNewDim + "\"", + getXWeak(), anyEx ); } } return xRet; } Reference < XDataPilotField > SAL_CALL ScDataPilotFieldObj::createDateGroup( const DataPilotFieldGroupInfo& rInfo ) +{ + return createScDateGroup(rInfo); +} + +rtl::Reference < ScDataPilotFieldObj > ScDataPilotFieldObj::createScDateGroup( const DataPilotFieldGroupInfo& rInfo ) { SolarMutexGuard aGuard; using namespace ::com::sun::star::sheet::DataPilotFieldGroupBy; @@ -2652,12 +2687,11 @@ Reference < XDataPilotField > SAL_CALL ScDataPilotFieldObj::createDateGroup( con } // return the UNO object of the new dimension, after writing back saved data - Reference< XDataPilotField > xRet; + rtl::Reference< ScDataPilotFieldObj > xRet; if( !aGroupDimName.isEmpty() ) try { - Reference< XNameAccess > xFields( mxParent->getDataPilotFields(), UNO_QUERY_THROW ); - xRet.set( xFields->getByName( aGroupDimName ), UNO_QUERY ); + xRet = mxParent->getScDataPilotFields()->getScDataPilotFieldObjByName( aGroupDimName ); } catch( Exception& ) {
