use rtl::Reference in BibFrameCtrl_Impl

instead of storing both a raw pointer and a uno::Reference

Change-Id: I8caa56eade25561178aa6ffd144b00f452517974
This commit is contained in:
Noel Grandin
2017-01-20 12:11:48 +02:00
parent f7db2b5b3f
commit 81253afdba
2 changed files with 37 additions and 39 deletions

View File

@@ -164,7 +164,6 @@ BibFrameController_Impl::BibFrameController_Impl( const uno::Reference< awt::XWi
BibDataManager* pDataManager) BibDataManager* pDataManager)
:xWindow( xComponent ) :xWindow( xComponent )
,m_xDatMan( pDataManager ) ,m_xDatMan( pDataManager )
,pDatMan( pDataManager )
,pBibMod(nullptr) ,pBibMod(nullptr)
{ {
bDisposing=false; bDisposing=false;
@@ -176,7 +175,7 @@ BibFrameController_Impl::BibFrameController_Impl( const uno::Reference< awt::XWi
BibFrameController_Impl::~BibFrameController_Impl() BibFrameController_Impl::~BibFrameController_Impl()
{ {
mxImpl->pController = nullptr; mxImpl->pController = nullptr;
delete pDatMan; m_xDatMan.clear();
if(pBibMod) if(pBibMod)
CloseBibModul(pBibMod); CloseBibModul(pBibMod);
} }
@@ -244,8 +243,7 @@ void BibFrameController_Impl::dispose() throw (css::uno::RuntimeException, std::
lang::EventObject aObject; lang::EventObject aObject;
aObject.Source = static_cast<XController*>(this); aObject.Source = static_cast<XController*>(this);
mxImpl->aLC.disposeAndClear(aObject); mxImpl->aLC.disposeAndClear(aObject);
m_xDatMan = nullptr; m_xDatMan.clear();
pDatMan = nullptr;
aStatusListeners.clear(); aStatusListeners.clear();
} }
@@ -267,7 +265,7 @@ uno::Reference< frame::XDispatch > BibFrameController_Impl::queryDispatch( cons
CmdToInfoCache::const_iterator pIter = rCmdCache.find( aURL.Complete ); CmdToInfoCache::const_iterator pIter = rCmdCache.find( aURL.Complete );
if ( pIter != rCmdCache.end() ) if ( pIter != rCmdCache.end() )
{ {
if (( pDatMan->HasActiveConnection() ) || if (( m_xDatMan->HasActiveConnection() ) ||
( !pIter->second.bActiveConnection )) ( !pIter->second.bActiveConnection ))
return static_cast<frame::XDispatch*>(this); return static_cast<frame::XDispatch*>(this);
} }
@@ -403,7 +401,7 @@ void BibFrameController_Impl::dispatch(const util::URL& _rURL, const uno::Sequen
OUString aCommand( _rURL.Path); OUString aCommand( _rURL.Path);
if(aCommand == "Bib/Mapping") if(aCommand == "Bib/Mapping")
{ {
pDatMan->CreateMappingDialog(pParent); m_xDatMan->CreateMappingDialog(pParent);
} }
else if(aCommand == "Bib/source") else if(aCommand == "Bib/source")
{ {
@@ -411,7 +409,7 @@ void BibFrameController_Impl::dispatch(const util::URL& _rURL, const uno::Sequen
} }
else if(aCommand == "Bib/sdbsource") else if(aCommand == "Bib/sdbsource")
{ {
OUString aURL = pDatMan->CreateDBChangeDialog(pParent); OUString aURL = m_xDatMan->CreateDBChangeDialog(pParent);
if(!aURL.isEmpty()) if(!aURL.isEmpty())
{ {
try try
@@ -456,7 +454,7 @@ void BibFrameController_Impl::dispatch(const util::URL& _rURL, const uno::Sequen
aValue >>= aQueryField; aValue >>= aQueryField;
BibConfig* pConfig = BibModul::GetConfig(); BibConfig* pConfig = BibModul::GetConfig();
pConfig->setQueryField(aQueryField); pConfig->setQueryField(aQueryField);
pDatMan->startQueryWith(aQuery); m_xDatMan->startQueryWith(aQuery);
} }
else if(aCommand == "Bib/standardFilter") else if(aCommand == "Bib/standardFilter")
{ {
@@ -465,15 +463,15 @@ void BibFrameController_Impl::dispatch(const util::URL& _rURL, const uno::Sequen
uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext(); uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
// create the dialog object // create the dialog object
uno::Reference< ui::dialogs::XExecutableDialog > xDialog = sdb::FilterDialog::createWithQuery(xContext, pDatMan->getParser(), uno::Reference< ui::dialogs::XExecutableDialog > xDialog = sdb::FilterDialog::createWithQuery(xContext, m_xDatMan->getParser(),
Reference<sdbc::XRowSet>(pDatMan->getForm(), uno::UNO_QUERY_THROW), xWindow); Reference<sdbc::XRowSet>(m_xDatMan->getForm(), uno::UNO_QUERY_THROW), xWindow);
// execute it // execute it
if ( xDialog->execute( ) ) if ( xDialog->execute( ) )
{ {
// the dialog has been executed successfully, and the filter on the query composer // the dialog has been executed successfully, and the filter on the query composer
// has been changed // has been changed
OUString sNewFilter = pDatMan->getParser()->getFilter(); OUString sNewFilter = m_xDatMan->getParser()->getFilter();
pDatMan->setFilter( sNewFilter ); m_xDatMan->setFilter( sNewFilter );
} }
} }
catch( const uno::Exception& ) catch( const uno::Exception& )
@@ -485,11 +483,11 @@ void BibFrameController_Impl::dispatch(const util::URL& _rURL, const uno::Sequen
for ( sal_uInt16 n=0; n<nCount; n++ ) for ( sal_uInt16 n=0; n<nCount; n++ )
{ {
BibStatusDispatch *pObj = aStatusListeners[n].get(); BibStatusDispatch *pObj = aStatusListeners[n].get();
if ( pObj->aURL.Path == "Bib/removeFilter" && pDatMan->getParser().is()) if ( pObj->aURL.Path == "Bib/removeFilter" && m_xDatMan->getParser().is())
{ {
FeatureStateEvent aEvent; FeatureStateEvent aEvent;
aEvent.FeatureURL = pObj->aURL; aEvent.FeatureURL = pObj->aURL;
aEvent.IsEnabled = !pDatMan->getParser()->getFilter().isEmpty(); aEvent.IsEnabled = !m_xDatMan->getParser()->getFilter().isEmpty();
aEvent.Requery = false; aEvent.Requery = false;
aEvent.Source = static_cast<XDispatch *>(this); aEvent.Source = static_cast<XDispatch *>(this);
pObj->xListener->statusChanged( aEvent ); pObj->xListener->statusChanged( aEvent );
@@ -508,15 +506,15 @@ void BibFrameController_Impl::dispatch(const util::URL& _rURL, const uno::Sequen
} }
else if(aCommand == "Bib/InsertRecord") else if(aCommand == "Bib/InsertRecord")
{ {
Reference<form::runtime::XFormController > xFormCtrl = pDatMan->GetFormController(); Reference<form::runtime::XFormController > xFormCtrl = m_xDatMan->GetFormController();
if(SaveModified(xFormCtrl)) if(SaveModified(xFormCtrl))
{ {
try try
{ {
Reference< sdbc::XResultSet > xCursor( pDatMan->getForm(), UNO_QUERY ); Reference< sdbc::XResultSet > xCursor( m_xDatMan->getForm(), UNO_QUERY );
xCursor->last(); xCursor->last();
Reference< XResultSetUpdate > xUpdateCursor( pDatMan->getForm(), UNO_QUERY ); Reference< XResultSetUpdate > xUpdateCursor( m_xDatMan->getForm(), UNO_QUERY );
xUpdateCursor->moveToInsertRow(); xUpdateCursor->moveToInsertRow();
} }
catch(const Exception&) catch(const Exception&)
@@ -527,9 +525,9 @@ void BibFrameController_Impl::dispatch(const util::URL& _rURL, const uno::Sequen
} }
else if(aCommand == "Bib/DeleteRecord") else if(aCommand == "Bib/DeleteRecord")
{ {
Reference< css::sdbc::XResultSet > xCursor(pDatMan->getForm(), UNO_QUERY); Reference< css::sdbc::XResultSet > xCursor(m_xDatMan->getForm(), UNO_QUERY);
Reference< XResultSetUpdate > xUpdateCursor(xCursor, UNO_QUERY); Reference< XResultSetUpdate > xUpdateCursor(xCursor, UNO_QUERY);
Reference< beans::XPropertySet > xSet(pDatMan->getForm(), UNO_QUERY); Reference< beans::XPropertySet > xSet(m_xDatMan->getForm(), UNO_QUERY);
bool bIsNew = ::comphelper::getBOOL(xSet->getPropertyValue("IsNew")); bool bIsNew = ::comphelper::getBOOL(xSet->getPropertyValue("IsNew"));
if(!bIsNew) if(!bIsNew)
{ {
@@ -545,7 +543,7 @@ void BibFrameController_Impl::dispatch(const util::URL& _rURL, const uno::Sequen
bRight= !xCursor->isLast(); bRight= !xCursor->isLast();
// ask for confirmation // ask for confirmation
Reference< frame::XController > xCtrl = mxImpl->pController; Reference< frame::XController > xCtrl = mxImpl->pController;
Reference< form::XConfirmDeleteListener > xConfirm(pDatMan->GetFormController(),UNO_QUERY); Reference< form::XConfirmDeleteListener > xConfirm(m_xDatMan->GetFormController(),UNO_QUERY);
if (xConfirm.is()) if (xConfirm.is())
{ {
sdb::RowChangeEvent aEvent; sdb::RowChangeEvent aEvent;
@@ -650,17 +648,17 @@ void BibFrameController_Impl::addStatusListener(
else if(aURL.Path == "Bib/MenuFilter") else if(aURL.Path == "Bib/MenuFilter")
{ {
aEvent.IsEnabled = true; aEvent.IsEnabled = true;
aEvent.FeatureDescriptor=pDatMan->getQueryField(); aEvent.FeatureDescriptor=m_xDatMan->getQueryField();
aEvent.State <<= pDatMan->getQueryFields(); aEvent.State <<= m_xDatMan->getQueryFields();
} }
else if ( aURL.Path == "Bib/source") else if ( aURL.Path == "Bib/source")
{ {
aEvent.IsEnabled = true; aEvent.IsEnabled = true;
aEvent.FeatureDescriptor=pDatMan->getActiveDataTable(); aEvent.FeatureDescriptor=m_xDatMan->getActiveDataTable();
aEvent.State <<= pDatMan->getDataSources(); aEvent.State <<= m_xDatMan->getDataSources();
} }
else if( aURL.Path == "Bib/sdbsource" || else if( aURL.Path == "Bib/sdbsource" ||
aURL.Path == "Bib/Mapping" || aURL.Path == "Bib/Mapping" ||
@@ -676,7 +674,7 @@ void BibFrameController_Impl::addStatusListener(
} }
else if (aURL.Path == "Bib/removeFilter" ) else if (aURL.Path == "Bib/removeFilter" )
{ {
OUString aFilterStr=pDatMan->getFilter(); OUString aFilterStr=m_xDatMan->getFilter();
aEvent.IsEnabled = !aFilterStr.isEmpty(); aEvent.IsEnabled = !aFilterStr.isEmpty();
} }
else if(aURL.Path == "Cut") else if(aURL.Path == "Cut")
@@ -734,9 +732,9 @@ void BibFrameController_Impl::addStatusListener(
} }
else if(aURL.Path == "Bib/DeleteRecord") else if(aURL.Path == "Bib/DeleteRecord")
{ {
Reference< css::sdbc::XResultSet > xCursor(pDatMan->getForm(), UNO_QUERY); Reference< css::sdbc::XResultSet > xCursor(m_xDatMan->getForm(), UNO_QUERY);
Reference< XResultSetUpdate > xUpdateCursor(xCursor, UNO_QUERY); Reference< XResultSetUpdate > xUpdateCursor(xCursor, UNO_QUERY);
Reference< beans::XPropertySet > xSet(pDatMan->getForm(), UNO_QUERY); Reference< beans::XPropertySet > xSet(m_xDatMan->getForm(), UNO_QUERY);
bool bIsNew = ::comphelper::getBOOL(xSet->getPropertyValue("IsNew")); bool bIsNew = ::comphelper::getBOOL(xSet->getPropertyValue("IsNew"));
if(!bIsNew) if(!bIsNew)
{ {
@@ -747,7 +745,7 @@ void BibFrameController_Impl::addStatusListener(
} }
else if (aURL.Path == "Bib/InsertRecord") else if (aURL.Path == "Bib/InsertRecord")
{ {
Reference< beans::XPropertySet > xSet(pDatMan->getForm(), UNO_QUERY); Reference< beans::XPropertySet > xSet(m_xDatMan->getForm(), UNO_QUERY);
aEvent.IsEnabled = canInsertRecords(xSet); aEvent.IsEnabled = canInsertRecords(xSet);
} }
aListener->statusChanged( aEvent ); aListener->statusChanged( aEvent );
@@ -779,7 +777,7 @@ void BibFrameController_Impl::removeStatusListener(
void BibFrameController_Impl::RemoveFilter() void BibFrameController_Impl::RemoveFilter()
{ {
OUString aQuery; OUString aQuery;
pDatMan->startQueryWith(aQuery); m_xDatMan->startQueryWith(aQuery);
sal_uInt16 nCount = aStatusListeners.size(); sal_uInt16 nCount = aStatusListeners.size();
@@ -830,15 +828,16 @@ void BibFrameController_Impl::ChangeDataSource(const uno::Sequence< beans::Prope
uno::Any aDB = pPropertyValue[1].Value; uno::Any aDB = pPropertyValue[1].Value;
OUString aURL; OUString aURL;
aDB >>= aURL; aDB >>= aURL;
pDatMan->setActiveDataSource(aURL); m_xDatMan->setActiveDataSource(aURL);
aDBTableName = pDatMan->getActiveDataTable(); aDBTableName = m_xDatMan->getActiveDataTable();
} }
else else
{ {
m_xDatMan->unload(); Reference<css::form::XLoadable> xLoadable(m_xDatMan.get());
pDatMan->setActiveDataTable(aDBTableName); xLoadable->unload();
pDatMan->updateGridModel(); m_xDatMan->setActiveDataTable(aDBTableName);
m_xDatMan->load(); m_xDatMan->updateGridModel();
xLoadable->load();
} }
@@ -856,9 +855,9 @@ void BibFrameController_Impl::ChangeDataSource(const uno::Sequence< beans::Prope
aEvent.IsEnabled = true; aEvent.IsEnabled = true;
aEvent.Requery = false; aEvent.Requery = false;
aEvent.Source = static_cast<XDispatch *>(this); aEvent.Source = static_cast<XDispatch *>(this);
aEvent.FeatureDescriptor=pDatMan->getQueryField(); aEvent.FeatureDescriptor=m_xDatMan->getQueryField();
uno::Sequence<OUString> aStringSeq=pDatMan->getQueryFields(); uno::Sequence<OUString> aStringSeq=m_xDatMan->getQueryFields();
aEvent.State = makeAny( aStringSeq ); aEvent.State = makeAny( aStringSeq );
pObj->xListener->statusChanged( aEvent ); pObj->xListener->statusChanged( aEvent );

View File

@@ -66,8 +66,7 @@ friend class BibFrameCtrl_Impl;
css::uno::Reference< css::frame::XFrame > xFrame; css::uno::Reference< css::frame::XFrame > xFrame;
bool bDisposing; bool bDisposing;
bool bHierarchical; bool bHierarchical;
css::uno::Reference< css::form::XLoadable > m_xDatMan; rtl::Reference<BibDataManager> m_xDatMan;
BibDataManager* pDatMan;
HdlBibModul pBibMod; HdlBibModul pBibMod;
DECL_LINK( DisposeHdl, void*, void ); DECL_LINK( DisposeHdl, void*, void );