[Libreoffice-commits] core.git: 3 commits - sw/inc sw/source
Michael Stahl
mstahl at redhat.com
Thu Jan 25 18:51:16 UTC 2018
sw/inc/doc.hxx | 7 ++++---
sw/source/core/doc/docnew.cxx | 17 +++++++++--------
sw/source/core/doc/doctxm.cxx | 14 +++++---------
sw/source/uibase/dbui/dbmgr.cxx | 12 ++++++------
4 files changed, 24 insertions(+), 26 deletions(-)
New commits:
commit 26d34f319ba48216785f7fdbf9e6bfdaf2dc6ad2
Author: Michael Stahl <mstahl at redhat.com>
Date: Thu Jan 25 15:49:34 2018 +0100
sw: fix some bug in SwTOXBaseSection::UpdatePageNum()
Looking at UpdatePageNum_ it's fairly obvious that the 2 vectors aNums
and aDescs have to be in sync, but aNums is cleared after each iteration
while aDescs is not.
Change-Id: I41d8a8df5c4c3ae51aa5ea89c21b01651af5651c
diff --git a/sw/source/core/doc/doctxm.cxx b/sw/source/core/doc/doctxm.cxx
index 3202362cbbf2..aa2bee2db1ad 100644
--- a/sw/source/core/doc/doctxm.cxx
+++ b/sw/source/core/doc/doctxm.cxx
@@ -1548,8 +1548,6 @@ void SwTOXBaseSection::UpdatePageNum()
for( SwTOXSortTabBases::size_type nCnt = 0; nCnt < aSortArr.size(); ++nCnt )
{
// Loop over all SourceNodes
- std::vector<sal_uInt16> aNums; // the PageNumber
- std::vector<SwPageDesc*> aDescs; // The PageDescriptors matching the PageNumbers
// process run in lines
SwTOXSortTabBases::size_type nRange = 0;
@@ -1572,6 +1570,8 @@ void SwTOXBaseSection::UpdatePageNum()
for(SwTOXSortTabBases::size_type nRunInEntry = nCnt; nRunInEntry < nCnt + nRange; ++nRunInEntry)
{
+ std::vector<sal_uInt16> aNums; // the PageNumber
+ std::vector<SwPageDesc*> aDescs; // The PageDescriptors matching the PageNumbers
std::vector<sal_uInt16> aMainNums; // contains page numbers of main entries
SwTOXSortTabBase* pSortBase = aSortArr[nRunInEntry];
size_t nSize = pSortBase->aTOXSources.size();
@@ -1630,7 +1630,6 @@ void SwTOXBaseSection::UpdatePageNum()
UpdatePageNum_( const_cast<SwTextNode*>(pTextNd), aNums, aDescs, &aMainNums,
aIntl );
}
- aNums.clear();
}
}
// Delete the mapping array after setting the right PageNumber
commit 38af1bb52d3833da7919e61e650fb9ec1bdaf4f7
Author: Michael Stahl <mstahl at redhat.com>
Date: Thu Jan 25 15:44:34 2018 +0100
sw: de-pointerise local variable in SwTOXBaseSection::UpdatePageNum()
Change-Id: I24fcde19ae94cc5a278da6d88e72ce6a57a64951
diff --git a/sw/source/core/doc/doctxm.cxx b/sw/source/core/doc/doctxm.cxx
index e19316445785..3202362cbbf2 100644
--- a/sw/source/core/doc/doctxm.cxx
+++ b/sw/source/core/doc/doctxm.cxx
@@ -1550,7 +1550,6 @@ void SwTOXBaseSection::UpdatePageNum()
// Loop over all SourceNodes
std::vector<sal_uInt16> aNums; // the PageNumber
std::vector<SwPageDesc*> aDescs; // The PageDescriptors matching the PageNumbers
- std::vector<sal_uInt16> *pMainNums = nullptr; // contains page numbers of main entries
// process run in lines
SwTOXSortTabBases::size_type nRange = 0;
@@ -1573,6 +1572,7 @@ void SwTOXBaseSection::UpdatePageNum()
for(SwTOXSortTabBases::size_type nRunInEntry = nCnt; nRunInEntry < nCnt + nRange; ++nRunInEntry)
{
+ std::vector<sal_uInt16> aMainNums; // contains page numbers of main entries
SwTOXSortTabBase* pSortBase = aSortArr[nRunInEntry];
size_t nSize = pSortBase->aTOXSources.size();
for (size_t j = 0; j < nSize; ++j)
@@ -1616,9 +1616,7 @@ void SwTOXBaseSection::UpdatePageNum()
if(TOX_SORT_INDEX == pSortBase->GetType() &&
rTOXSource.bMainEntry)
{
- if(!pMainNums)
- pMainNums = new std::vector<sal_uInt16>;
- pMainNums->push_back(nPage);
+ aMainNums.push_back(nPage);
}
}
}
@@ -1629,10 +1627,9 @@ void SwTOXBaseSection::UpdatePageNum()
const SwTextNode* pTextNd = pBase->pTOXNd->GetTextNode();
OSL_ENSURE( pTextNd, "no TextNode, wrong TOC" );
- UpdatePageNum_( const_cast<SwTextNode*>(pTextNd), aNums, aDescs, pMainNums,
+ UpdatePageNum_( const_cast<SwTextNode*>(pTextNd), aNums, aDescs, &aMainNums,
aIntl );
}
- DELETEZ(pMainNums);
aNums.clear();
}
}
commit 7dbe76266cb4250701aaee043933ccb21e5f6564
Author: Michael Stahl <mstahl at redhat.com>
Date: Thu Jan 25 15:43:19 2018 +0100
sw: convert SwDoc::mpDBManager to unique_ptr
Very odd things are happening in dbmgr.cxx to override this member,
so add a 2nd member that points to the DBManager that is actually used.
Change-Id: If5d4ea1e4951a0406fddcb71302c53ee7b37a34e
diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx
index 726471e1dea6..aa7ee77406cf 100644
--- a/sw/inc/doc.hxx
+++ b/sw/inc/doc.hxx
@@ -283,7 +283,8 @@ class SW_DLLPUBLIC SwDoc final
SwTOXTypes *mpTOXTypes; //< Tables/indices
SwDefTOXBase_Impl * mpDefTOXBases; //< defaults of SwTOXBase's
- SwDBManager *mpDBManager; //< Pointer to the DBManager for evaluation of DB-fields.
+ std::unique_ptr<SwDBManager> m_pOwnDBManager; //< own DBManager
+ SwDBManager * m_pDBManager; //< DBManager for evaluation of DB-fields.
SwNumRule *mpOutlineRule;
SwFootnoteInfo *mpFootnoteInfo;
@@ -688,8 +689,8 @@ public:
bool IsInVerticalText( const SwPosition& rPos ) const;
// Database and DB-Manager
- void SetDBManager( SwDBManager* pNewMgr ) { mpDBManager = pNewMgr; }
- SwDBManager* GetDBManager() const { return mpDBManager; }
+ void SetDBManager( SwDBManager* pNewMgr ) { m_pDBManager = pNewMgr; }
+ SwDBManager* GetDBManager() const { return m_pDBManager; }
void ChangeDBFields( const std::vector<OUString>& rOldNames,
const OUString& rNewName );
void SetInitDBFields(bool b);
diff --git a/sw/source/core/doc/docnew.cxx b/sw/source/core/doc/docnew.cxx
index 598ba687070b..e71260ac584e 100644
--- a/sw/source/core/doc/docnew.cxx
+++ b/sw/source/core/doc/docnew.cxx
@@ -346,7 +346,8 @@ SwDoc::SwDoc()
#if HAVE_FEATURE_DBCONNECTIVITY
// Create DBManager
- mpDBManager = new SwDBManager(this);
+ m_pOwnDBManager.reset(new SwDBManager(this));
+ m_pDBManager = m_pOwnDBManager.get();
#endif
// create TOXTypes
@@ -534,22 +535,22 @@ SwDoc::~SwDoc()
#if HAVE_FEATURE_DBCONNECTIVITY
// On load, SwDBManager::setEmbeddedName() may register a data source.
// If we have an embedded one, then sDataSource points to the registered name, so revoke it here.
- if (!mpDBManager->getEmbeddedName().isEmpty() && !maDBData.sDataSource.isEmpty())
+ if (!m_pOwnDBManager->getEmbeddedName().isEmpty() && !maDBData.sDataSource.isEmpty())
{
// Remove the revoke listener here first, so that we don't remove the data source from the document.
- mpDBManager->releaseRevokeListener();
+ m_pOwnDBManager->releaseRevokeListener();
SwDBManager::RevokeDataSource(maDBData.sDataSource);
- SwDBManager::RevokeDataSource(mpDBManager->getEmbeddedName());
+ SwDBManager::RevokeDataSource(m_pOwnDBManager->getEmbeddedName());
}
- else if (!mpDBManager->getEmbeddedName().isEmpty())
+ else if (!m_pOwnDBManager->getEmbeddedName().isEmpty())
{
// Remove the revoke listener here first, so that we don't remove the data source from the document.
- mpDBManager->releaseRevokeListener();
+ m_pOwnDBManager->releaseRevokeListener();
// Remove connections which was committed but not used.
- mpDBManager->RevokeNotUsedConnections();
+ m_pOwnDBManager->RevokeNotUsedConnections();
}
- DELETEZ( mpDBManager );
+ m_pOwnDBManager.reset();
#endif
// All Flys need to be destroyed before the Drawing Model,
diff --git a/sw/source/uibase/dbui/dbmgr.cxx b/sw/source/uibase/dbui/dbmgr.cxx
index 6067bd834ac2..5d9ccaf0fa13 100644
--- a/sw/source/uibase/dbui/dbmgr.cxx
+++ b/sw/source/uibase/dbui/dbmgr.cxx
@@ -171,7 +171,7 @@ enum class WorkingDocType { SOURCE, TARGET, COPY };
static SfxObjectShell* lcl_CreateWorkingDocument(
const WorkingDocType aType, const SwWrtShell &rSourceWrtShell,
const vcl::Window *pSourceWindow,
- SwDBManager** const pDBManager,
+ SwDBManager** const ppDBManager,
SwView** const pView, SwWrtShell** const pWrtShell, SwDoc** const pDoc );
static bool lcl_getCountFromResultSet( sal_Int32& rCount, const SwDSParam* pParam )
@@ -962,7 +962,7 @@ static SfxObjectShell* lcl_CreateWorkingDocument(
// optional input
const vcl::Window *pSourceWindow,
// optional in and output to swap the DB manager
- SwDBManager** const pDBManager,
+ SwDBManager** const ppDBManager,
// optional output
SwView** const pView, SwWrtShell** const pWrtShell, SwDoc** const pDoc )
{
@@ -987,17 +987,17 @@ static SfxObjectShell* lcl_CreateWorkingDocument(
if( aType == WorkingDocType::TARGET )
{
- assert( !pDBManager );
+ assert( !ppDBManager );
pWorkDoc->SetInMailMerge( true );
pWorkWrtShell->SetLabelDoc( false );
}
else
{
// We have to swap the DBmanager of the new doc, so we also need input
- assert( pDBManager && *pDBManager );
+ assert(ppDBManager && *ppDBManager);
SwDBManager *pWorkDBManager = pWorkDoc->GetDBManager();
- pWorkDoc->SetDBManager( *pDBManager );
- *pDBManager = pWorkDBManager;
+ pWorkDoc->SetDBManager( *ppDBManager );
+ *ppDBManager = pWorkDBManager;
if( aType == WorkingDocType::SOURCE )
{
More information about the Libreoffice-commits
mailing list