summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2019-01-14 14:39:44 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2019-01-16 12:16:49 +0100
commit1bf68dbf53f4b5308e295058226abd6d6fb49c3d (patch)
tree7d291955efb4f58ee047d49fcb5848a2e2bbb7c1 /sc
parent3c93d34caa79c37c41eab1d3212a7ff1cdf53d34 (diff)
pass ScPostIt around by unique_ptr
Change-Id: I99c1f0a5d5c760663f5150b477a936d2f45b874c Reviewed-on: https://gerrit.libreoffice.org/66322 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sc')
-rw-r--r--sc/inc/column.hxx4
-rw-r--r--sc/inc/document.hxx6
-rw-r--r--sc/inc/postit.hxx2
-rw-r--r--sc/inc/table.hxx2
-rw-r--r--sc/qa/unit/ucalc.cxx6
-rw-r--r--sc/source/core/data/column.cxx2
-rw-r--r--sc/source/core/data/column2.cxx6
-rw-r--r--sc/source/core/data/column4.cxx6
-rw-r--r--sc/source/core/data/document.cxx12
-rw-r--r--sc/source/core/data/postit.cxx10
-rw-r--r--sc/source/core/data/table2.cxx10
-rw-r--r--sc/source/ui/docshell/docfunc.cxx7
-rw-r--r--sc/source/ui/undo/undocell.cxx7
-rw-r--r--sc/source/ui/view/drawview.cxx4
14 files changed, 42 insertions, 42 deletions
diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index 7e12cf4eda46..d21918648678 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -602,10 +602,10 @@ public:
const ScPostIt* GetCellNote( sc::ColumnBlockConstPosition& rBlockPos, SCROW nRow ) const;
void DeleteCellNotes( sc::ColumnBlockPosition& rBlockPos, SCROW nRow1, SCROW nRow2, bool bForgetCaptionOwnership );
bool HasCellNotes() const;
- void SetCellNote( SCROW nRow, ScPostIt* pNote);
+ void SetCellNote( SCROW nRow, std::unique_ptr<ScPostIt> pNote);
bool IsNotesEmptyBlock(SCROW nStartRow, SCROW nEndRow) const;
- ScPostIt* ReleaseNote( SCROW nRow );
+ std::unique_ptr<ScPostIt> ReleaseNote( SCROW nRow );
size_t GetNoteCount() const;
void CreateAllNoteCaptions();
void ForgetNoteCaptions( SCROW nRow1, SCROW nRow2, bool bPreserveData );
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index bb7a4f01fa2b..7ff9ed357616 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -1186,14 +1186,14 @@ public:
/** Notes **/
SC_DLLPUBLIC ScPostIt* GetNote(const ScAddress& rPos);
SC_DLLPUBLIC ScPostIt* GetNote(SCCOL nCol, SCROW nRow, SCTAB nTab);
- void SetNote(const ScAddress& rPos, ScPostIt* pNote);
- void SetNote(SCCOL nCol, SCROW nRow, SCTAB nTab, ScPostIt* pNote);
+ void SetNote(const ScAddress& rPos, std::unique_ptr<ScPostIt> pNote);
+ void SetNote(SCCOL nCol, SCROW nRow, SCTAB nTab, std::unique_ptr<ScPostIt> pNote);
SC_DLLPUBLIC bool HasNote(const ScAddress& rPos) const;
bool HasNote(SCCOL nCol, SCROW nRow, SCTAB nTab) const;
SC_DLLPUBLIC bool HasColNotes(SCCOL nCol, SCTAB nTab) const;
SC_DLLPUBLIC bool HasTabNotes(SCTAB nTab) const;
bool HasNotes() const;
- SC_DLLPUBLIC ScPostIt* ReleaseNote(const ScAddress& rPos);
+ SC_DLLPUBLIC std::unique_ptr<ScPostIt> ReleaseNote(const ScAddress& rPos);
SC_DLLPUBLIC ScPostIt* GetOrCreateNote(const ScAddress& rPos);
SC_DLLPUBLIC ScPostIt* CreateNote(const ScAddress& rPos);
size_t GetNoteCount( SCTAB nTab, SCCOL nCol ) const;
diff --git a/sc/inc/postit.hxx b/sc/inc/postit.hxx
index ca72c47befca..4700979cd04a 100644
--- a/sc/inc/postit.hxx
+++ b/sc/inc/postit.hxx
@@ -90,7 +90,7 @@ public:
object (used e.g. in Undo documents to restore the pointer to the
existing caption object).
*/
- ScPostIt* Clone(
+ std::unique_ptr<ScPostIt> Clone(
const ScAddress& rOwnPos,
ScDocument& rDestDoc, const ScAddress& rDestPos,
bool bCloneCaption ) const;
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index e26ae0ae7a40..d853c4072de1 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -460,7 +460,7 @@ public:
void GetFirstDataPos(SCCOL& rCol, SCROW& rRow) const;
void GetLastDataPos(SCCOL& rCol, SCROW& rRow) const;
- ScPostIt* ReleaseNote( SCCOL nCol, SCROW nRow );
+ std::unique_ptr<ScPostIt> ReleaseNote( SCCOL nCol, SCROW nRow );
size_t GetNoteCount( SCCOL nCol ) const;
SCROW GetNotePosition( SCCOL nCol, size_t nIndex ) const;
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index be249c6f647e..63ea088741ee 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -5343,8 +5343,8 @@ void Test::testNoteLifeCycle()
CPPUNIT_ASSERT_MESSAGE("Failed to insert a new cell comment.", pNote);
pNote->SetText(aPos, "New note");
- ScPostIt* pNote2 = m_pDoc->ReleaseNote(aPos);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("This note instance is expected to be identical to the original.", pNote, pNote2);
+ std::unique_ptr<ScPostIt> pNote2 = m_pDoc->ReleaseNote(aPos);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("This note instance is expected to be identical to the original.", pNote, pNote2.get());
CPPUNIT_ASSERT_MESSAGE("The note shouldn't be here after it's been released.", !m_pDoc->HasNote(aPos));
// Modify the internal state of the note instance to make sure it's really
@@ -5352,7 +5352,7 @@ void Test::testNoteLifeCycle()
pNote->SetText(aPos, "New content");
// Re-insert the note back to the same place.
- m_pDoc->SetNote(aPos, pNote);
+ m_pDoc->SetNote(aPos, std::move(pNote2));
SdrCaptionObj* pCaption = pNote->GetOrCreateCaption(aPos).get();
CPPUNIT_ASSERT_MESSAGE("Failed to create a caption object.", pCaption);
CPPUNIT_ASSERT_EQUAL_MESSAGE("This caption should belong to the drawing layer of the document.",
diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx
index 0c151a70ac65..e2ec2efa1849 100644
--- a/sc/source/core/data/column.cxx
+++ b/sc/source/core/data/column.cxx
@@ -1206,7 +1206,7 @@ void ScColumn::CopyCellToDocument( SCROW nSrcRow, SCROW nDestRow, ScColumn& rDes
pNote = pNote->Clone(ScAddress(nCol, nSrcRow, nTab),
*rDestCol.GetDoc(),
ScAddress(rDestCol.nCol, nDestRow, rDestCol.nTab),
- false);
+ false).release();
rDestCol.maCellNotes.set(nDestRow, pNote);
pNote->UpdateCaptionPos(ScAddress(rDestCol.nCol, nDestRow, rDestCol.nTab));
}
diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx
index f9b4569d5c4e..ac6b06d7f4e0 100644
--- a/sc/source/core/data/column2.cxx
+++ b/sc/source/core/data/column2.cxx
@@ -1825,7 +1825,7 @@ public:
SCROW nDestRow = nRow + mnDestOffset;
ScAddress aSrcPos(mnSrcCol, nRow, mnSrcTab);
ScAddress aDestPos(mnDestCol, nDestRow, mnDestTab);
- miPos = mrDestNotes.set(miPos, nDestRow, p->Clone(aSrcPos, *mrDestCol.GetDoc(), aDestPos, mbCloneCaption));
+ miPos = mrDestNotes.set(miPos, nDestRow, p->Clone(aSrcPos, *mrDestCol.GetDoc(), aDestPos, mbCloneCaption).release());
// Notify our LOK clients also
ScDocShell::LOKCommentNotify(LOKCommentNotificationType::Add, mrDestCol.GetDoc(), aDestPos, p);
}
@@ -1914,10 +1914,10 @@ const ScPostIt* ScColumn::GetCellNote( sc::ColumnBlockConstPosition& rBlockPos,
return sc::cellnote_block::at(*aPos.first->data, aPos.second);
}
-void ScColumn::SetCellNote(SCROW nRow, ScPostIt* pNote)
+void ScColumn::SetCellNote(SCROW nRow, std::unique_ptr<ScPostIt> pNote)
{
//pNote->UpdateCaptionPos(ScAddress(nCol, nRow, nTab)); // TODO notes useful ? slow import with many notes
- maCellNotes.set(nRow, pNote);
+ maCellNotes.set(nRow, pNote.release());
}
namespace {
diff --git a/sc/source/core/data/column4.cxx b/sc/source/core/data/column4.cxx
index d21d52f4029c..379d6e24a389 100644
--- a/sc/source/core/data/column4.cxx
+++ b/sc/source/core/data/column4.cxx
@@ -295,7 +295,7 @@ void ScColumn::CopyOneCellFromClip( sc::CopyFromClipContext& rCxt, SCROW nRow1,
for (size_t i = 0; i < nDestSize; ++i)
{
bool bCloneCaption = (nFlags & InsertDeleteFlags::NOCAPTIONS) == InsertDeleteFlags::NONE;
- aNotes.push_back(pNote->Clone(rSrcPos, *pDocument, aDestPos, bCloneCaption));
+ aNotes.push_back(pNote->Clone(rSrcPos, *pDocument, aDestPos, bCloneCaption).release());
aDestPos.IncRow();
}
@@ -611,14 +611,14 @@ void ScColumn::CloneFormulaCell(
CellStorageModified();
}
-ScPostIt* ScColumn::ReleaseNote( SCROW nRow )
+std::unique_ptr<ScPostIt> ScColumn::ReleaseNote( SCROW nRow )
{
if (!ValidRow(nRow))
return nullptr;
ScPostIt* p = nullptr;
maCellNotes.release(nRow, p);
- return p;
+ return std::unique_ptr<ScPostIt>(p);
}
size_t ScColumn::GetNoteCount() const
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index 749a15f37fae..8a1bd262fa0e 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -6471,14 +6471,14 @@ ScPostIt* ScDocument::GetNote(SCCOL nCol, SCROW nRow, SCTAB nTab)
}
-void ScDocument::SetNote(const ScAddress& rPos, ScPostIt* pNote)
+void ScDocument::SetNote(const ScAddress& rPos, std::unique_ptr<ScPostIt> pNote)
{
- return SetNote(rPos.Col(), rPos.Row(), rPos.Tab(), pNote);
+ return SetNote(rPos.Col(), rPos.Row(), rPos.Tab(), std::move(pNote));
}
-void ScDocument::SetNote(SCCOL nCol, SCROW nRow, SCTAB nTab, ScPostIt* pNote)
+void ScDocument::SetNote(SCCOL nCol, SCROW nRow, SCTAB nTab, std::unique_ptr<ScPostIt> pNote)
{
- return maTabs[nTab]->aCol[nCol].SetCellNote(nRow, pNote);
+ return maTabs[nTab]->aCol[nCol].SetCellNote(nRow, std::move(pNote));
}
bool ScDocument::HasNote(const ScAddress& rPos) const
@@ -6535,7 +6535,7 @@ bool ScDocument::HasNotes() const
return false;
}
-ScPostIt* ScDocument::ReleaseNote(const ScAddress& rPos)
+std::unique_ptr<ScPostIt> ScDocument::ReleaseNote(const ScAddress& rPos)
{
ScTable* pTab = FetchTable(rPos.Tab());
if (!pTab)
@@ -6554,7 +6554,7 @@ ScPostIt* ScDocument::GetOrCreateNote(const ScAddress& rPos)
ScPostIt* ScDocument::CreateNote(const ScAddress& rPos)
{
ScPostIt* pPostIt = new ScPostIt(*this, rPos);
- SetNote(rPos, pPostIt);
+ SetNote(rPos, std::unique_ptr<ScPostIt>(pPostIt));
return pPostIt;
}
diff --git a/sc/source/core/data/postit.cxx b/sc/source/core/data/postit.cxx
index 581dfb5207a6..5a97f266a82e 100644
--- a/sc/source/core/data/postit.cxx
+++ b/sc/source/core/data/postit.cxx
@@ -530,10 +530,10 @@ ScPostIt::~ScPostIt()
RemoveCaption();
}
-ScPostIt* ScPostIt::Clone( const ScAddress& rOwnPos, ScDocument& rDestDoc, const ScAddress& rDestPos, bool bCloneCaption ) const
+std::unique_ptr<ScPostIt> ScPostIt::Clone( const ScAddress& rOwnPos, ScDocument& rDestDoc, const ScAddress& rDestPos, bool bCloneCaption ) const
{
CreateCaptionFromInitData( rOwnPos );
- return bCloneCaption ? new ScPostIt( rDestDoc, rDestPos, *this, mnPostItId ) : new ScPostIt( rDestDoc, rDestPos, maNoteData, false, mnPostItId );
+ return bCloneCaption ? std::make_unique<ScPostIt>( rDestDoc, rDestPos, *this, mnPostItId ) : std::make_unique<ScPostIt>( rDestDoc, rDestPos, maNoteData, false, mnPostItId );
}
void ScPostIt::SetDate( const OUString& rDate )
@@ -886,7 +886,7 @@ ScPostIt* ScNoteUtil::CreateNoteFromCaption(
ScPostIt* pNote = new ScPostIt( rDoc, rPos, aNoteData, false );
pNote->AutoStamp();
- rDoc.SetNote(rPos, pNote);
+ rDoc.SetNote(rPos, std::unique_ptr<ScPostIt>(pNote));
// ScNoteCaptionCreator c'tor updates the caption object to be part of a note
ScNoteCaptionCreator aCreator( rDoc, rPos, aNoteData.m_pCaption, true/*bShown*/ );
@@ -922,7 +922,7 @@ ScPostIt* ScNoteUtil::CreateNoteFromObjectData(
ScPostIt* pNote = new ScPostIt( rDoc, rPos, aNoteData, /*bAlwaysCreateCaption*/false, 0/*nPostItId*/ );
pNote->AutoStamp();
- rDoc.SetNote(rPos, pNote);
+ rDoc.SetNote(rPos, std::unique_ptr<ScPostIt>(pNote));
return pNote;
}
@@ -945,7 +945,7 @@ ScPostIt* ScNoteUtil::CreateNoteFromString(
pNote = new ScPostIt( rDoc, rPos, aNoteData, bAlwaysCreateCaption, nPostItId );
pNote->AutoStamp();
//insert takes ownership
- rDoc.SetNote(rPos, pNote);
+ rDoc.SetNote(rPos, std::unique_ptr<ScPostIt>(pNote));
}
return pNote;
}
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index 6608876a6ff4..2ed72a208ae1 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -1003,8 +1003,8 @@ void ScTable::TransposeColNotes(ScTable* pTransClip, SCCOL nCol1, SCCOL nCol, SC
ScPostIt* pNote = *itData;
if (pNote)
{
- ScPostIt* pClonedNote = pNote->Clone( ScAddress(nCol, curRow, nTab), *pTransClip->pDocument, aDestPos, true );
- pTransClip->pDocument->SetNote(aDestPos, pClonedNote);
+ std::unique_ptr<ScPostIt> pClonedNote = pNote->Clone( ScAddress(nCol, curRow, nTab), *pTransClip->pDocument, aDestPos, true );
+ pTransClip->pDocument->SetNote(aDestPos, std::move(pClonedNote));
}
}
break; // we reached the last valid block
@@ -1020,8 +1020,8 @@ void ScTable::TransposeColNotes(ScTable* pTransClip, SCCOL nCol1, SCCOL nCol, SC
ScPostIt* pNote = *itData;
if (pNote)
{
- ScPostIt* pClonedNote = pNote->Clone( ScAddress(nCol, curRow, nTab), *pTransClip->pDocument, aDestPos, true );
- pTransClip->pDocument->SetNote(aDestPos, pClonedNote);
+ std::unique_ptr<ScPostIt> pClonedNote = pNote->Clone( ScAddress(nCol, curRow, nTab), *pTransClip->pDocument, aDestPos, true );
+ pTransClip->pDocument->SetNote(aDestPos, std::move(pClonedNote));
}
}
}
@@ -1588,7 +1588,7 @@ ScFormulaCell* ScTable::GetFormulaCell( SCCOL nCol, SCROW nRow )
return aCol[nCol].GetFormulaCell(nRow);
}
-ScPostIt* ScTable::ReleaseNote( SCCOL nCol, SCROW nRow )
+std::unique_ptr<ScPostIt> ScTable::ReleaseNote( SCCOL nCol, SCROW nRow )
{
if (!ValidCol(nCol))
return nullptr;
diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx
index a3255535443f..09d0f0ece5a7 100644
--- a/sc/source/ui/docshell/docfunc.cxx
+++ b/sc/source/ui/docshell/docfunc.cxx
@@ -1254,7 +1254,7 @@ void ScDocFunc::ReplaceNote( const ScAddress& rPos, const OUString& rNoteText, c
SfxUndoManager* pUndoMgr = (pDrawLayer && rDoc.IsUndoEnabled()) ? rDocShell.GetUndoManager() : nullptr;
ScNoteData aOldData;
- ScPostIt* pOldNote = rDoc.ReleaseNote( rPos );
+ std::unique_ptr<ScPostIt> pOldNote = rDoc.ReleaseNote( rPos );
sal_uInt32 nNoteId = 0;
if( pOldNote )
{
@@ -1270,7 +1270,8 @@ void ScDocFunc::ReplaceNote( const ScAddress& rPos, const OUString& rNoteText, c
pDrawLayer->BeginCalcUndo(false);
// delete the note (creates drawing undo action for the caption object)
- delete pOldNote;
+ bool hadOldNote(pOldNote);
+ pOldNote.reset();
// create new note (creates drawing undo action for the new caption object)
ScNoteData aNewData;
@@ -1298,7 +1299,7 @@ void ScDocFunc::ReplaceNote( const ScAddress& rPos, const OUString& rNoteText, c
// Let our LOK clients know about the new/modified note
if (pNewNote)
{
- ScDocShell::LOKCommentNotify(pOldNote ? LOKCommentNotificationType::Modify : LOKCommentNotificationType::Add,
+ ScDocShell::LOKCommentNotify(hadOldNote ? LOKCommentNotificationType::Modify : LOKCommentNotificationType::Add,
&rDoc, rPos, pNewNote);
}
}
diff --git a/sc/source/ui/undo/undocell.cxx b/sc/source/ui/undo/undocell.cxx
index 169196304f51..5e67ccf16861 100644
--- a/sc/source/ui/undo/undocell.cxx
+++ b/sc/source/ui/undo/undocell.cxx
@@ -966,7 +966,7 @@ void ScUndoReplaceNote::DoInsertNote( const ScNoteData& rNoteData )
ScDocument& rDoc = pDocShell->GetDocument();
OSL_ENSURE( !rDoc.GetNote(maPos), "ScUndoReplaceNote::DoInsertNote - unexpected cell note" );
ScPostIt* pNote = new ScPostIt( rDoc, maPos, rNoteData, false );
- rDoc.SetNote( maPos, pNote );
+ rDoc.SetNote( maPos, std::unique_ptr<ScPostIt>(pNote) );
ScDocShell::LOKCommentNotify(LOKCommentNotificationType::Add, &rDoc, maPos, pNote);
}
}
@@ -977,14 +977,13 @@ void ScUndoReplaceNote::DoRemoveNote( const ScNoteData& rNoteData )
{
ScDocument& rDoc = pDocShell->GetDocument();
OSL_ENSURE( rDoc.GetNote(maPos), "ScUndoReplaceNote::DoRemoveNote - missing cell note" );
- if( ScPostIt* pNote = rDoc.ReleaseNote( maPos ) )
+ if( std::unique_ptr<ScPostIt> pNote = rDoc.ReleaseNote( maPos ) )
{
/* Forget pointer to caption object to suppress removing the
caption object from the drawing layer while deleting pNote
(removing the caption is done by a drawing undo action). */
pNote->ForgetCaption();
- ScDocShell::LOKCommentNotify(LOKCommentNotificationType::Remove, &rDoc, maPos, pNote);
- delete pNote;
+ ScDocShell::LOKCommentNotify(LOKCommentNotificationType::Remove, &rDoc, maPos, pNote.get());
}
}
}
diff --git a/sc/source/ui/view/drawview.cxx b/sc/source/ui/view/drawview.cxx
index 8ec01408b049..4196a882e024 100644
--- a/sc/source/ui/view/drawview.cxx
+++ b/sc/source/ui/view/drawview.cxx
@@ -866,7 +866,7 @@ void ScDrawView::DeleteMarked()
bool bUndo = pDrawLayer && pDocShell && pUndoMgr && pDoc->IsUndoEnabled();
// remove the cell note from document, we are its owner now
- ScPostIt* pNote = pDoc->ReleaseNote( pCaptData->maStart );
+ std::unique_ptr<ScPostIt> pNote = pDoc->ReleaseNote( pCaptData->maStart );
OSL_ENSURE( pNote, "ScDrawView::DeleteMarked - cell note missing in document" );
if( pNote )
{
@@ -877,7 +877,7 @@ void ScDrawView::DeleteMarked()
if( bUndo )
pDrawLayer->BeginCalcUndo(false);
// delete the note (already removed from document above)
- delete pNote;
+ pNote.reset();
// add the undo action for the note
if( bUndo )
pUndoMgr->AddUndoAction( o3tl::make_unique<ScUndoReplaceNote>( *pDocShell, pCaptData->maStart, aNoteData, false, pDrawLayer->GetCalcUndo() ) );