diff options
author | Michael Meeks <michael.meeks@suse.com> | 2013-03-15 14:26:17 +0000 |
---|---|---|
committer | Michael Meeks <michael.meeks@suse.com> | 2013-03-15 14:26:17 +0000 |
commit | 0598580fa6aae966b214f0afd9c6827604a13e24 (patch) | |
tree | cee0cecb529f7cfa0885198816bc5ad2e628c89a | |
parent | xmloff: at least do something to test styles. (diff) | |
download | core-0598580fa6aae966b214f0afd9c6827604a13e24.tar.gz core-0598580fa6aae966b214f0afd9c6827604a13e24.zip |
wrap process of creating automatic styles, so it is more robust.
Change-Id: I35bf7edcc1fa2b8d8e6b6603e03fa41f3fa5e0f9
-rw-r--r-- | xmloff/inc/xmloff/xmlaustp.hxx | 25 | ||||
-rw-r--r-- | xmloff/source/style/impastp4.cxx | 81 | ||||
-rw-r--r-- | xmloff/source/style/impastpl.hxx | 7 |
3 files changed, 106 insertions, 7 deletions
diff --git a/xmloff/inc/xmloff/xmlaustp.hxx b/xmloff/inc/xmloff/xmlaustp.hxx index 2482c8026bdf..066387a3d0e8 100644 --- a/xmloff/inc/xmloff/xmlaustp.hxx +++ b/xmloff/inc/xmloff/xmlaustp.hxx @@ -27,6 +27,7 @@ #include <xmloff/uniref.hxx> class SvXMLExportPropertyMapper; +class SvXMLAutoStylePoolP; class SvXMLNamespaceMap; class SvXMLAutoStylePoolP_Impl; class SvXMLAttributeList; @@ -35,9 +36,33 @@ namespace com { namespace sun { namespace star { namespace uno { template<typename A> class Sequence; } } } } +class XMLFamilyData_Impl; + +/** + * Encapsulates the process of filtering properties and + * creating automatic styles for various families. + */ +class XMLOFF_DLLPUBLIC SvXMLAutoFilteredSet +{ + UniReference< SvXMLAutoStylePoolP > mxPool; + XMLFamilyData_Impl *mpFamily; + ::std::vector< XMLPropertyState > maProperties; + public: + SvXMLAutoFilteredSet( const UniReference< SvXMLAutoStylePoolP > &xPool, sal_Int32 nFamily ); + ~SvXMLAutoFilteredSet(); + SvXMLAutoFilteredSet &filter( const ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet > &xPropSet ); + bool hasValidContent(); + sal_Int32 countValidProperties(); + + /// Insert into the auto style pool and return the name of the new auto-style + OUString add( const OUString &rParent, bool bCache = false, bool bDontSeek = false ); +}; + class XMLOFF_DLLPUBLIC SvXMLAutoStylePoolP : public UniRefBase { friend class Test; + friend class SvXMLAutoFilteredSet; friend class SvXMLAutoStylePoolP_Impl; SvXMLAutoStylePoolP_Impl *pImpl; diff --git a/xmloff/source/style/impastp4.cxx b/xmloff/source/style/impastp4.cxx index 6f6f15c49749..ae97bd66f25b 100644 --- a/xmloff/source/style/impastp4.cxx +++ b/xmloff/source/style/impastp4.cxx @@ -161,6 +161,18 @@ void SvXMLAutoStylePoolP_Impl::GetRegisteredNames( std::copy( aNames.begin(), aNames.end(), rNames.getArray() ); } +XMLFamilyData_Impl *SvXMLAutoStylePoolP_Impl::LookupFamily( sal_Int32 nFamily ) +{ + XMLFamilyData_Impl aTemporary( nFamily ); + XMLFamilyDataList_Impl::iterator aFind = maFamilyList.find( aTemporary ); + DBG_ASSERT( aFind != maFamilyList.end(), "SvXMLAutoStylePool_Impl::LookupFamily: unknown family" ); + + if ( aFind != maFamilyList.end() ) + return &(*aFind); + else + return NULL; +} + /////////////////////////////////////////////////////////////////////////////// // // Adds a array of XMLPropertyState ( vector< XMLPropertyState > ) to list @@ -173,16 +185,25 @@ sal_Bool SvXMLAutoStylePoolP_Impl::Add(OUString& rName, sal_Int32 nFamily, sal_Bool bCache, bool bDontSeek ) { - sal_Bool bRet(sal_False); - XMLFamilyData_Impl aTemporary( nFamily ); - XMLFamilyDataList_Impl::iterator aFind = maFamilyList.find(aTemporary); - DBG_ASSERT(aFind != maFamilyList.end(), "SvXMLAutoStylePool_Impl::Add: unknown family"); + XMLFamilyData_Impl *pFamily = LookupFamily( nFamily ); + if ( pFamily ) + return Add( rName, *pFamily, rParent, rProperties, bCache, bDontSeek ); + else { + OSL_FAIL( "SvXMLAutoStylePool_Impl::Add: unknown family"); + return sal_False; + } +} - if (aFind != maFamilyList.end()) +sal_Bool SvXMLAutoStylePoolP_Impl::Add( ::rtl::OUString& rName, + XMLFamilyData_Impl &rFamily, + const ::rtl::OUString& rParent, + const ::std::vector< XMLPropertyState >& rProperties, + sal_Bool bCache, + bool bDontSeek ) +{ + sal_Bool bRet = sal_False; { - XMLFamilyData_Impl &rFamily = *aFind; - SvXMLAutoStylePoolParentP_Impl aTmp( rParent ); SvXMLAutoStylePoolParentP_Impl *pParent = 0; @@ -451,4 +472,50 @@ void SvXMLAutoStylePoolP_Impl::ClearEntries() aI->ClearEntries(); } +SvXMLAutoFilteredSet::SvXMLAutoFilteredSet( const UniReference< SvXMLAutoStylePoolP > &xPool, + sal_Int32 nFamily ) + + : mxPool( xPool ) + , mpFamily( xPool->pImpl->LookupFamily( nFamily ) ) +{ + OSL_ASSERT( mpFamily != NULL ); +} + +SvXMLAutoFilteredSet::~SvXMLAutoFilteredSet() +{ +} + +SvXMLAutoFilteredSet &SvXMLAutoFilteredSet::filter( const ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet > &xPropSet ) +{ + maProperties = mpFamily->mxMapper->Filter( xPropSet ); + return *this; +} + +bool SvXMLAutoFilteredSet::hasValidContent() +{ + return countValidProperties() > 0; +} + +sal_Int32 SvXMLAutoFilteredSet::countValidProperties() +{ + std::vector< XMLPropertyState >::iterator it = maProperties.begin(); + std::vector< XMLPropertyState >::iterator aEnd = maProperties.end(); + sal_Int32 nCount = 0; + for( ;it != aEnd; ++it ) + { + if( it->mnIndex != -1 ) + nCount++; + } + return nCount; +} + +/// Insert into the auto style pool and return the name of the (new or re-used) auto-style +OUString SvXMLAutoFilteredSet::add( const OUString &rParent, bool bCache, bool bDontSeek ) +{ + OUString aStyleName; + mxPool->pImpl->Add( aStyleName, *mpFamily, rParent, maProperties, bCache, bDontSeek ); + return aStyleName; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/impastpl.hxx b/xmloff/source/style/impastpl.hxx index 61226700f09f..46fd4f0187ee 100644 --- a/xmloff/source/style/impastpl.hxx +++ b/xmloff/source/style/impastpl.hxx @@ -187,6 +187,13 @@ public: com::sun::star::uno::Sequence<sal_Int32>& aFamilies, com::sun::star::uno::Sequence<rtl::OUString>& aNames ); + XMLFamilyData_Impl *LookupFamily( sal_Int32 nFamily ); + sal_Bool Add( ::rtl::OUString& rName, XMLFamilyData_Impl &rFamily, + const ::rtl::OUString& rParent, + const ::std::vector< XMLPropertyState >& rProperties, + sal_Bool bCache = sal_False, + bool bDontSeek = false ); + sal_Bool Add( ::rtl::OUString& rName, sal_Int32 nFamily, const ::rtl::OUString& rParent, const ::std::vector< XMLPropertyState >& rProperties, |