diff options
author | Maxim Monastirsky <momonasmon@gmail.com> | 2022-12-04 16:21:27 +0200 |
---|---|---|
committer | Maxim Monastirsky <momonasmon@gmail.com> | 2022-12-05 07:26:11 +0000 |
commit | 1c3dc6cdc53a2463af12688918d222d44039a96c (patch) | |
tree | 6f8d712b4c2d4446899832425c816b1e7d06b6f8 | |
parent | 05eb5e487455dfaa0947c704c2ae06544d1f9253 (diff) |
Simplify SdStyleSheetPool::CopyTableStyles a bit
Change-Id: Ib8bbc8f71b310c1b968f36a94e99cce6019dd6cc
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143643
Tested-by: Jenkins
Reviewed-by: Maxim Monastirsky <momonasmon@gmail.com>
-rw-r--r-- | sd/source/core/stlpool.cxx | 53 |
1 files changed, 21 insertions, 32 deletions
diff --git a/sd/source/core/stlpool.cxx b/sd/source/core/stlpool.cxx index 79f07b0b614a..ad4733f96189 100644 --- a/sd/source/core/stlpool.cxx +++ b/sd/source/core/stlpool.cxx @@ -526,47 +526,36 @@ void SdStyleSheetPool::CopyTableStyles(SdStyleSheetPool const & rSourcePool) Reference< XNameContainer > xTarget( mxTableFamily, UNO_QUERY ); Reference< XSingleServiceFactory > xFactory( mxTableFamily, UNO_QUERY ); - if( !(xSource.is() && xFactory.is() && mxTableFamily.is()) ) + if( !xSource || !xFactory ) return; for( sal_Int32 nIndex = 0; nIndex < xSource->getCount(); nIndex++ ) try { - Reference< XStyle > xSourceTableStyle( xSource->getByIndex( nIndex ), UNO_QUERY ); - if( xSourceTableStyle.is() ) + Reference< XNameAccess > xSourceTableStyle( xSource->getByIndex( nIndex ), UNO_QUERY_THROW ); + Reference< XNameReplace > xNewTableStyle( xFactory->createInstance(), UNO_QUERY_THROW ); + + const Sequence< OUString > aStyleNames( xSourceTableStyle->getElementNames() ); + for( const OUString& aName : aStyleNames ) { - Reference< XStyle > xNewTableStyle( xFactory->createInstance(), UNO_QUERY ); - if( xNewTableStyle.is() ) + Reference< XStyle > xSourceStyle( xSourceTableStyle->getByName( aName ), UNO_QUERY ); + Reference< XStyle > xTargetStyle; + if( xSourceStyle.is() ) try { - Reference< XNameAccess> xSourceNames( xSourceTableStyle, UNO_QUERY_THROW ); - - const Sequence< OUString > aStyleNames( xSourceNames->getElementNames() ); - - Reference< XNameReplace > xTargetNames( xNewTableStyle, UNO_QUERY ); - - for( const OUString& aName : aStyleNames ) - { - Reference< XStyle > xSourceStyle( xSourceNames->getByName( aName ), UNO_QUERY ); - Reference< XStyle > xTargetStyle; - if( xSourceStyle.is() ) try - { - mxCellFamily->getByName( xSourceStyle->getName() ) >>= xTargetStyle; - } - catch( Exception& ) - { - TOOLS_WARN_EXCEPTION( "sd", "sd::SdStyleSheetPool::CopyTableStyles()" ); - } - - if( xTargetStyle.is() ) - xTargetNames->replaceByName( aName, Any( xTargetStyle ) ); - } + mxCellFamily->getByName( xSourceStyle->getName() ) >>= xTargetStyle; + } + catch( Exception& ) + { + TOOLS_WARN_EXCEPTION( "sd", "sd::SdStyleSheetPool::CopyTableStyles()" ); } - OUString sName( xSourceTableStyle->getName() ); - if( xTarget->hasByName( sName ) ) - xTarget->replaceByName( sName, Any( xNewTableStyle ) ); - else - xTarget->insertByName( sName, Any( xNewTableStyle ) ); + xNewTableStyle->replaceByName( aName, Any( xTargetStyle ) ); } + + const OUString sName(Reference<XStyle>(xSourceTableStyle, UNO_QUERY_THROW)->getName()); + if( xTarget->hasByName( sName ) ) + xTarget->replaceByName( sName, Any( xNewTableStyle ) ); + else + xTarget->insertByName( sName, Any( xNewTableStyle ) ); } catch( Exception& ) { |