cui/source/inc/cuitabarea.hxx | 2 + cui/source/tabpages/tpgradnt.cxx | 66 ++++++++++++++++------------------- cui/source/tabpages/tphatch.cxx | 72 ++++++++++++++++++--------------------- 3 files changed, 68 insertions(+), 72 deletions(-)
New commits: commit 6b3eb4788f63602c0a446ad8f56539d3b65bb302 Author: Rishabh Kumar <[email protected]> Date: Thu Jun 16 19:18:20 2016 +0530 Reduce duplicate code and remove DBG_ASSERT Change-Id: I2abf050bd6627cda993ff03bdf1d1867e209bda5 Reviewed-on: https://gerrit.libreoffice.org/26392 Tested-by: Jenkins <[email protected]> Reviewed-by: Katarina Behrens <[email protected]> diff --git a/cui/source/inc/cuitabarea.hxx b/cui/source/inc/cuitabarea.hxx index 9e1da38..98f2c32 100644 --- a/cui/source/inc/cuitabarea.hxx +++ b/cui/source/inc/cuitabarea.hxx @@ -429,6 +429,7 @@ private: long CheckChanges_Impl(); void SetControlState_Impl( css::awt::GradientStyle eXGS ); + sal_Int32 SearchGradientList(OUString aGradientName); public: SvxGradientTabPage( vcl::Window* pParent, const SfxItemSet& rInAttrs ); @@ -511,6 +512,7 @@ private: DECL_LINK_TYPED( ClickSaveHdl_Impl, Button*, void ); long CheckChanges_Impl(); + sal_Int32 SearchHatchList(OUString aHatchName); public: SvxHatchTabPage( vcl::Window* pParent, const SfxItemSet& rInAttrs ); diff --git a/cui/source/tabpages/tpgradnt.cxx b/cui/source/tabpages/tpgradnt.cxx index 8d87220..6ab4d12 100644 --- a/cui/source/tabpages/tpgradnt.cxx +++ b/cui/source/tabpages/tpgradnt.cxx @@ -240,7 +240,7 @@ void SvxGradientTabPage::ActivatePage( const SfxItemSet& ) INetURLObject aURL( m_pGradientList->GetPath() ); aURL.Append( m_pGradientList->GetName() ); - DBG_ASSERT( aURL.GetProtocol() != INetProtocol::NotValid, "invalid URL" ); + SAL_WARN_IF( aURL.GetProtocol() == INetProtocol::NotValid, "cui.tabpages", "invalid URL" ); if ( aURL.getBase().getLength() > 18 ) { @@ -302,7 +302,7 @@ long SvxGradientTabPage::CheckChanges_Impl() SVX_RESSTR( RID_SVXSTR_GRADIENT ), CUI_RESSTR( RID_SVXSTR_ASK_CHANGE_GRADIENT ), &aWarningBoxImage ); - DBG_ASSERT(aMessDlg, "Dialog creation failed!"); + assert(aMessDlg && "Dialog creation failed!"); aMessDlg->SetButtonText( SvxMessDialogButton::N1, OUString( ResId( RID_SVXSTR_CHANGE, rMgr ) ) ); aMessDlg->SetButtonText( SvxMessDialogButton::N2, @@ -370,7 +370,7 @@ bool SvxGradientTabPage::FillItemSet( SfxItemSet* rSet ) (sal_uInt16) m_pMtrColorFrom->GetValue(), (sal_uInt16) m_pMtrColorTo->GetValue() )); } - DBG_ASSERT( pXGradient, "XGradient konnte nicht erzeugt werden" ); + assert( pXGradient && "XGradient could not be created" ); rSet->Put( XFillStyleItem( drawing::FillStyle_GRADIENT ) ); rSet->Put( XFillGradientItem( aString, *pXGradient ) ); rSet->Put( XGradientStepCountItem( nValue ) ); @@ -465,18 +465,12 @@ IMPL_LINK_NOARG_TYPED(SvxGradientTabPage, ClickAddHdl_Impl, Button*, void) long nCount = m_pGradientList->Count(); long j = 1; - bool bDifferent = false; + bool bValidGradientName = false; - while( !bDifferent ) + while( !bValidGradientName ) { - aName = aNewName; - aName += " "; - aName += OUString::number( j++ ); - bDifferent = true; - - for( long i = 0; i < nCount && bDifferent; i++ ) - if( aName == m_pGradientList->GetGradient( i )->GetName() ) - bDifferent = false; + aName = aNewName + " " + OUString::number( j++ ); + bValidGradientName = (SearchGradientList(aName) == LISTBOX_ENTRY_NOTFOUND); } SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); @@ -488,15 +482,9 @@ IMPL_LINK_NOARG_TYPED(SvxGradientTabPage, ClickAddHdl_Impl, Button*, void) { pDlg->GetName( aName ); - bDifferent = true; + bValidGradientName = (SearchGradientList(aName) == LISTBOX_ENTRY_NOTFOUND); - for (long i = 0; i < nCount && bDifferent; ++i) - { - if( aName == m_pGradientList->GetGradient( i )->GetName() ) - bDifferent = false; - } - - if (bDifferent) + if (bValidGradientName) { nError = 0; break; @@ -566,29 +554,21 @@ IMPL_LINK_NOARG_TYPED(SvxGradientTabPage, ClickModifyHdl_Impl, Button*, void) { OUString aDesc( CUI_RES( RID_SVXSTR_DESC_GRADIENT ) ); OUString aName( m_pGradientList->GetGradient( nPos )->GetName() ); - OUString aOldName = aName; SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); - DBG_ASSERT(pFact, "Dialog creation failed!"); + assert(pFact && "Dialog creation failed!"); std::unique_ptr<AbstractSvxNameDialog> pDlg(pFact->CreateSvxNameDialog( GetParentDialog(), aName, aDesc )); - DBG_ASSERT(pDlg, "Dialog creation failed!"); + assert(pDlg && "Dialog creation failed!"); - long nCount = m_pGradientList->Count(); bool bLoop = true; while( bLoop && pDlg->Execute() == RET_OK ) { pDlg->GetName( aName ); - bool bDifferent = true; + sal_Int32 nGradientPos = SearchGradientList(aName); + bool bValidGradientName = (nGradientPos == nPos) || (nGradientPos == LISTBOX_ENTRY_NOTFOUND); - for( long i = 0; i < nCount && bDifferent; i++ ) - { - if( aName == m_pGradientList->GetGradient( i )->GetName() && - aName != aOldName ) - bDifferent = false; - } - - if( bDifferent ) + if( bValidGradientName ) { bLoop = false; XGradient aXGradient( m_pLbColorFrom->GetSelectEntryColor(), @@ -776,7 +756,7 @@ IMPL_LINK_NOARG_TYPED(SvxGradientTabPage, ClickSaveHdl_Impl, Button*, void) while (nIndex >= 0); INetURLObject aFile(aLastDir); - DBG_ASSERT( aFile.GetProtocol() != INetProtocol::NotValid, "invalid URL" ); + SAL_WARN_IF( aFile.GetProtocol() == INetProtocol::NotValid, "cui.tabpages", "invalid URL" ); if( !m_pGradientList->GetName().isEmpty() ) { @@ -947,5 +927,21 @@ void SvxGradientTabPage::SetControlState_Impl( css::awt::GradientStyle eXGS ) } } +sal_Int32 SvxGradientTabPage::SearchGradientList(OUString aGradientName) +{ + long nCount = m_pGradientList->Count(); + bool bValidGradientName = true; + sal_Int32 nPos = LISTBOX_ENTRY_NOTFOUND; + + for(long i = 0;i < nCount && bValidGradientName;i++) + { + if(aGradientName == m_pGradientList->GetGradient( i )->GetName()) + { + nPos = i; + bValidGradientName = false; + } + } + return nPos; +} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cui/source/tabpages/tphatch.cxx b/cui/source/tabpages/tphatch.cxx index de983a7..a1a2c2b 100644 --- a/cui/source/tabpages/tphatch.cxx +++ b/cui/source/tabpages/tphatch.cxx @@ -105,7 +105,7 @@ SvxHatchTabPage::SvxHatchTabPage // determine PoolUnit SfxItemPool* pPool = m_rOutAttrs.GetPool(); - DBG_ASSERT( pPool, "Wo ist der Pool?" ); + assert( pPool && "Where is the pool?" ); m_ePoolUnit = pPool->GetMetric( SID_ATTR_FILL_HATCH ); // setting the slider range @@ -212,7 +212,7 @@ void SvxHatchTabPage::ActivatePage( const SfxItemSet& rSet ) INetURLObject aURL( m_pHatchingList->GetPath() ); aURL.Append( m_pHatchingList->GetName() ); - DBG_ASSERT( aURL.GetProtocol() != INetProtocol::NotValid, "invalid URL" ); + SAL_WARN_IF( aURL.GetProtocol() == INetProtocol::NotValid, "cui.tabpages", "invalid URL" ); if ( aURL.getBase().getLength() > 18 ) { @@ -280,7 +280,7 @@ long SvxHatchTabPage::CheckChanges_Impl() SVX_RESSTR( RID_SVXSTR_HATCH ), CUI_RESSTR( RID_SVXSTR_ASK_CHANGE_HATCH ), &aWarningBoxImage ); - DBG_ASSERT(aMessDlg, "Dialog creation failed!"); + assert(aMessDlg && "Dialog creation failed!"); aMessDlg->SetButtonText( SvxMessDialogButton::N1, OUString( ResId( RID_SVXSTR_CHANGE, rMgr ) ) ); aMessDlg->SetButtonText( SvxMessDialogButton::N2, @@ -313,6 +313,22 @@ long SvxHatchTabPage::CheckChanges_Impl() return 0L; } +sal_Int32 SvxHatchTabPage::SearchHatchList(OUString aHatchName) +{ + long nCount = m_pHatchingList->Count(); + bool bValidHatchName = true; + sal_Int32 nPos = LISTBOX_ENTRY_NOTFOUND; + + for(long i = 0;i < nCount && bValidHatchName;i++) + { + if(aHatchName == m_pHatchingList->GetHatch( i )->GetName()) + { + nPos = i; + bValidHatchName = false; + } + } + return nPos; +} bool SvxHatchTabPage::FillItemSet( SfxItemSet* rSet ) { @@ -338,7 +354,7 @@ bool SvxHatchTabPage::FillItemSet( SfxItemSet* rSet ) GetCoreValue( *m_pMtrDistance, m_ePoolUnit ), static_cast<long>(m_pMtrAngle->GetValue() * 10) )); } - DBG_ASSERT( pXHatch, "XHatch konnte nicht erzeugt werden" ); + assert( pXHatch && "XHatch couldn't be created" ); rSet->Put( XFillStyleItem( drawing::FillStyle_HATCH ) ); rSet->Put( XFillHatchItem( aString, *pXHatch ) ); @@ -501,24 +517,18 @@ IMPL_LINK_NOARG_TYPED(SvxHatchTabPage, ClickAddHdl_Impl, Button*, void) long nCount = m_pHatchingList->Count(); long j = 1; - bool bDifferent = false; + bool bValidHatchName = false; - while( !bDifferent ) + while( !bValidHatchName ) { - aName = aNewName; - aName += " "; - aName += OUString::number( j++ ); - bDifferent = true; - - for( long i = 0; i < nCount && bDifferent; i++ ) - if( aName == m_pHatchingList->GetHatch( i )->GetName() ) - bDifferent = false; + aName = aNewName + " " + OUString::number( j++ ); + bValidHatchName = (SearchHatchList(aName) == LISTBOX_ENTRY_NOTFOUND); } SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); - DBG_ASSERT(pFact, "Dialog creation failed!"); + assert(pFact && "Dialog creation failed!"); std::unique_ptr<AbstractSvxNameDialog> pDlg(pFact->CreateSvxNameDialog( GetParentDialog(), aName, aDesc )); - DBG_ASSERT(pDlg, "Dialog creation failed!"); + assert(pDlg && "Dialog creation failed!"); ScopedVclPtr<MessageDialog> pWarnBox; sal_uInt16 nError = 1; @@ -526,13 +536,9 @@ IMPL_LINK_NOARG_TYPED(SvxHatchTabPage, ClickAddHdl_Impl, Button*, void) { pDlg->GetName( aName ); - bDifferent = true; - - for( long i = 0; i < nCount && bDifferent; i++ ) - if( aName == m_pHatchingList->GetHatch( i )->GetName() ) - bDifferent = false; - - if( bDifferent ) { + bValidHatchName = (SearchHatchList(aName) == LISTBOX_ENTRY_NOTFOUND); + if( bValidHatchName ) + { nError = 0; break; } @@ -596,28 +602,20 @@ IMPL_LINK_NOARG_TYPED(SvxHatchTabPage, ClickModifyHdl_Impl, Button*, void) { OUString aDesc( CUI_RES( RID_SVXSTR_DESC_HATCH ) ); OUString aName( m_pHatchingList->GetHatch( nPos )->GetName() ); - OUString aOldName = aName; SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); - DBG_ASSERT(pFact, "Dialog creation failed!"); + assert(pFact && "Dialog creation failed!"); std::unique_ptr<AbstractSvxNameDialog> pDlg(pFact->CreateSvxNameDialog( GetParentDialog(), aName, aDesc )); - DBG_ASSERT(pDlg, "Dialog creation failed!"); + assert(pDlg && "Dialog creation failed!"); - long nCount = m_pHatchingList->Count(); bool bLoop = true; while( bLoop && pDlg->Execute() == RET_OK ) { pDlg->GetName( aName ); - bool bDifferent = true; - - for( long i = 0; i < nCount && bDifferent; i++ ) - { - if( aName == m_pHatchingList->GetHatch( i )->GetName() && - aName != aOldName ) - bDifferent = false; - } + sal_Int32 nHatchPos = SearchHatchList( aName ); + bool bValidHatchName = (nHatchPos == nPos) || (nHatchPos == LISTBOX_ENTRY_NOTFOUND); - if( bDifferent ) + if( bValidHatchName ) { bLoop = false; XHatch aXHatch( m_pLbLineColor->GetSelectEntryColor(), @@ -796,7 +794,7 @@ IMPL_LINK_NOARG_TYPED(SvxHatchTabPage, ClickSaveHdl_Impl, Button*, void) while (nIndex >= 0); INetURLObject aFile(aLastDir); - DBG_ASSERT( aFile.GetProtocol() != INetProtocol::NotValid, "invalid URL" ); + SAL_WARN_IF( aFile.GetProtocol() == INetProtocol::NotValid, "cui.tabpages", "invalid URL" ); if( !m_pHatchingList->GetName().isEmpty() ) { _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
