sc/inc/dpobject.hxx | 2 - sc/qa/unit/ucalc_pivottable.cxx | 44 ++++++++++++++++++------------------- sc/source/core/data/dpobject.cxx | 8 ++---- sc/source/filter/excel/xipivot.cxx | 6 ++--- sc/source/filter/xml/xmldpimp.cxx | 18 +++++++-------- sc/source/ui/docshell/dbdocfun.cxx | 2 - sc/source/ui/undo/undodat.cxx | 4 --- 7 files changed, 40 insertions(+), 44 deletions(-)
New commits: commit 0317541c6b5486647bacaa5255e4babfc5ce9c23 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Fri Oct 5 12:03:05 2018 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Mon Oct 8 11:54:53 2018 +0200 use more std::unique_ptr in ScDPCollection Change-Id: I7d76704ba76b0d47544456047bc699b12fa7c288 Reviewed-on: https://gerrit.libreoffice.org/61435 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/sc/inc/dpobject.hxx b/sc/inc/dpobject.hxx index df422a461c97..5b69aaca9f2a 100644 --- a/sc/inc/dpobject.hxx +++ b/sc/inc/dpobject.hxx @@ -392,7 +392,7 @@ public: OUString CreateNewName() const; void FreeTable(const ScDPObject* pDPObj); - SC_DLLPUBLIC void InsertNewTable(ScDPObject* pDPObj); + SC_DLLPUBLIC void InsertNewTable(std::unique_ptr<ScDPObject> pDPObj); SC_DLLPUBLIC bool HasTable(const ScDPObject* pDPObj) const; SC_DLLPUBLIC SheetCaches& GetSheetCaches(); diff --git a/sc/qa/unit/ucalc_pivottable.cxx b/sc/qa/unit/ucalc_pivottable.cxx index 01d922201fdf..e05dca044af0 100644 --- a/sc/qa/unit/ucalc_pivottable.cxx +++ b/sc/qa/unit/ucalc_pivottable.cxx @@ -222,7 +222,7 @@ void Test::testPivotTable() m_pDoc, ScRange(nCol1, nRow1, 0, nCol2, nRow2, 0), aFields, nFieldCount, false); ScDPCollection* pDPs = m_pDoc->GetDPCollection(); - pDPs->InsertNewTable(pDPObj); + pDPs->InsertNewTable(std::unique_ptr<ScDPObject>(pDPObj)); CPPUNIT_ASSERT_EQUAL_MESSAGE("there should be only one data pilot table.", size_t(1), pDPs->GetCount()); pDPObj->SetName(pDPs->CreateNewName()); @@ -266,7 +266,7 @@ void Test::testPivotTable() // don't reload the cache which should force the copy to use the old data // from the cache. ScDPObject* pDPObj2 = new ScDPObject(*pDPObj); - pDPs->InsertNewTable(pDPObj2); + pDPs->InsertNewTable(std::unique_ptr<ScDPObject>(pDPObj2)); aOutRange = pDPObj2->GetOutRange(); pDPObj2->ClearTableData(); @@ -351,7 +351,7 @@ void Test::testPivotTable() pDPObj = createDPFromRange( m_pDoc, ScRange(nCol1, nRow1, 0, nCol2, nRow2, 0), aFields, nFieldCount, false); - pDPs->InsertNewTable(pDPObj); + pDPs->InsertNewTable(std::unique_ptr<ScDPObject>(pDPObj)); CPPUNIT_ASSERT_EQUAL_MESSAGE("there should be only one data pilot table.", size_t(1), pDPs->GetCount()); pDPObj->SetName(pDPs->CreateNewName()); @@ -401,7 +401,7 @@ void Test::testPivotTableLabels() m_pDoc, ScRange(nCol1, nRow1, 0, nCol2, nRow2, 0), aFields, nFieldCount, false); ScDPCollection* pDPs = m_pDoc->GetDPCollection(); - pDPs->InsertNewTable(pDPObj); + pDPs->InsertNewTable(std::unique_ptr<ScDPObject>(pDPObj)); CPPUNIT_ASSERT_EQUAL_MESSAGE("there should be only one data pilot table.", size_t(1), pDPs->GetCount()); pDPObj->SetName(pDPs->CreateNewName()); @@ -456,7 +456,7 @@ void Test::testPivotTableDateLabels() m_pDoc, ScRange(nCol1, nRow1, 0, nCol2, nRow2, 0), aFields, nFieldCount, false); ScDPCollection* pDPs = m_pDoc->GetDPCollection(); - pDPs->InsertNewTable(pDPObj); + pDPs->InsertNewTable(std::unique_ptr<ScDPObject>(pDPObj)); CPPUNIT_ASSERT_EQUAL_MESSAGE("there should be only one data pilot table.", size_t(1), pDPs->GetCount()); pDPObj->SetName(pDPs->CreateNewName()); @@ -538,7 +538,7 @@ void Test::testPivotTableFilters() m_pDoc, ScRange(nCol1, nRow1, 0, nCol2, nRow2, 0), aFields, nFieldCount, true); ScDPCollection* pDPs = m_pDoc->GetDPCollection(); - pDPs->InsertNewTable(pDPObj); + pDPs->InsertNewTable(std::unique_ptr<ScDPObject>(pDPObj)); CPPUNIT_ASSERT_EQUAL_MESSAGE("there should be only one data pilot table.", size_t(1), pDPs->GetCount()); pDPObj->SetName(pDPs->CreateNewName()); @@ -697,7 +697,7 @@ void Test::testPivotTableNamedSource() CPPUNIT_ASSERT_MESSAGE("Failed to create a new pivot table object.", pDPObj); ScDPCollection* pDPs = m_pDoc->GetDPCollection(); - pDPs->InsertNewTable(pDPObj); + pDPs->InsertNewTable(std::unique_ptr<ScDPObject>(pDPObj)); CPPUNIT_ASSERT_EQUAL_MESSAGE("there should be only one data pilot table.", size_t(1), pDPs->GetCount()); pDPObj->SetName(pDPs->CreateNewName()); @@ -972,7 +972,7 @@ void Test::testPivotTableDuplicateDataFields() m_pDoc, aDataRange, aFields, SAL_N_ELEMENTS(aFields), false); ScDPCollection* pDPs = m_pDoc->GetDPCollection(); - pDPs->InsertNewTable(pDPObj); + pDPs->InsertNewTable(std::unique_ptr<ScDPObject>(pDPObj)); CPPUNIT_ASSERT_EQUAL_MESSAGE("there should be only one data pilot table.", size_t(1), pDPs->GetCount()); pDPObj->SetName(pDPs->CreateNewName()); @@ -1063,7 +1063,7 @@ void Test::testPivotTableNormalGrouping() m_pDoc, aDataRange, aFields, SAL_N_ELEMENTS(aFields), false); ScDPCollection* pDPs = m_pDoc->GetDPCollection(); - pDPs->InsertNewTable(pDPObj); + pDPs->InsertNewTable(std::unique_ptr<ScDPObject>(pDPObj)); CPPUNIT_ASSERT_EQUAL_MESSAGE("there should be only one data pilot table.", size_t(1), pDPs->GetCount()); pDPObj->SetName(pDPs->CreateNewName()); @@ -1223,7 +1223,7 @@ void Test::testPivotTableNumberGrouping() m_pDoc, aDataRange, aFields, SAL_N_ELEMENTS(aFields), false); ScDPCollection* pDPs = m_pDoc->GetDPCollection(); - pDPs->InsertNewTable(pDPObj); + pDPs->InsertNewTable(std::unique_ptr<ScDPObject>(pDPObj)); CPPUNIT_ASSERT_EQUAL_MESSAGE("there should be only one data pilot table.", size_t(1), pDPs->GetCount()); pDPObj->SetName(pDPs->CreateNewName()); @@ -1306,7 +1306,7 @@ void Test::testPivotTableDateGrouping() m_pDoc, aDataRange, aFields, SAL_N_ELEMENTS(aFields), false); ScDPCollection* pDPs = m_pDoc->GetDPCollection(); - pDPs->InsertNewTable(pDPObj); + pDPs->InsertNewTable(std::unique_ptr<ScDPObject>(pDPObj)); CPPUNIT_ASSERT_EQUAL_MESSAGE("there should be only one data pilot table.", size_t(1), pDPs->GetCount()); pDPObj->SetName(pDPs->CreateNewName()); @@ -1477,7 +1477,7 @@ void Test::testPivotTableEmptyRows() m_pDoc, aDataRange, aFields, SAL_N_ELEMENTS(aFields), false); ScDPCollection* pDPs = m_pDoc->GetDPCollection(); - pDPs->InsertNewTable(pDPObj); + pDPs->InsertNewTable(std::unique_ptr<ScDPObject>(pDPObj)); CPPUNIT_ASSERT_EQUAL_MESSAGE("there should be only one data pilot table.", size_t(1), pDPs->GetCount()); pDPObj->SetName(pDPs->CreateNewName()); @@ -1602,7 +1602,7 @@ void Test::testPivotTableTextNumber() m_pDoc, aDataRange, aFields, SAL_N_ELEMENTS(aFields), false); ScDPCollection* pDPs = m_pDoc->GetDPCollection(); - pDPs->InsertNewTable(pDPObj); + pDPs->InsertNewTable(std::unique_ptr<ScDPObject>(pDPObj)); CPPUNIT_ASSERT_EQUAL_MESSAGE("there should be only one data pilot table.", size_t(1), pDPs->GetCount()); pDPObj->SetName(pDPs->CreateNewName()); @@ -1684,7 +1684,7 @@ void Test::testPivotTableCaseInsensitiveStrings() m_pDoc, aDataRange, aFields, SAL_N_ELEMENTS(aFields), false); ScDPCollection* pDPs = m_pDoc->GetDPCollection(); - pDPs->InsertNewTable(pDPObj); + pDPs->InsertNewTable(std::unique_ptr<ScDPObject>(pDPObj)); CPPUNIT_ASSERT_EQUAL_MESSAGE("there should be only one data pilot table.", size_t(1), pDPs->GetCount()); pDPObj->SetName(pDPs->CreateNewName()); @@ -1773,7 +1773,7 @@ void Test::testPivotTableNumStability() m_pDoc, aDataRange, aFields, SAL_N_ELEMENTS(aFields), false); ScDPCollection* pDPs = m_pDoc->GetDPCollection(); - pDPs->InsertNewTable(pDPObj); + pDPs->InsertNewTable(std::unique_ptr<ScDPObject>(pDPObj)); CPPUNIT_ASSERT_EQUAL_MESSAGE("there should be only one data pilot table.", size_t(1), pDPs->GetCount()); pDPObj->SetName(pDPs->CreateNewName()); @@ -1843,7 +1843,7 @@ void Test::testPivotTableFieldReference() m_pDoc, aDataRange, aFields, SAL_N_ELEMENTS(aFields), false); ScDPCollection* pDPs = m_pDoc->GetDPCollection(); - pDPs->InsertNewTable(pDPObj); + pDPs->InsertNewTable(std::unique_ptr<ScDPObject>(pDPObj)); CPPUNIT_ASSERT_EQUAL_MESSAGE("there should be only one data pilot table.", size_t(1), pDPs->GetCount()); pDPObj->SetName(pDPs->CreateNewName()); @@ -2082,7 +2082,7 @@ void Test::testFuncGETPIVOTDATA() } ScDPCollection* pDPs = m_pDoc->GetDPCollection(); - pDPs->InsertNewTable(pDPObj); + pDPs->InsertNewTable(std::unique_ptr<ScDPObject>(pDPObj)); CPPUNIT_ASSERT_EQUAL_MESSAGE("there should be only one data pilot table.", size_t(1), pDPs->GetCount()); pDPObj->SetName(pDPs->CreateNewName()); @@ -2143,7 +2143,7 @@ void Test::testFuncGETPIVOTDATA() pDPObj = createDPFromRange(m_pDoc, aDataRange, aFields, SAL_N_ELEMENTS(aFields), false); } - pDPs->InsertNewTable(pDPObj); + pDPs->InsertNewTable(std::unique_ptr<ScDPObject>(pDPObj)); aOutRange = refresh(pDPObj); { @@ -2238,7 +2238,7 @@ void Test::testFuncGETPIVOTDATALeafAccess() pDPObj = createDPFromRange(m_pDoc, aDataRange, aFields, SAL_N_ELEMENTS(aFields), false); ScDPCollection* pDPs = m_pDoc->GetDPCollection(); - pDPs->InsertNewTable(pDPObj); + pDPs->InsertNewTable(std::unique_ptr<ScDPObject>(pDPObj)); CPPUNIT_ASSERT_EQUAL_MESSAGE("there should be only one data pilot table.", size_t(1), pDPs->GetCount()); pDPObj->SetName(pDPs->CreateNewName()); @@ -2333,7 +2333,7 @@ void Test::testPivotTableRepeatItemLabels() m_pDoc, ScRange(nCol1, nRow1, 0, nCol2, nRow2, 0), aFields, nFieldCount, false); ScDPCollection* pDPs = m_pDoc->GetDPCollection(); - pDPs->InsertNewTable(pDPObj); + pDPs->InsertNewTable(std::unique_ptr<ScDPObject>(pDPObj)); CPPUNIT_ASSERT_EQUAL_MESSAGE("there should be only one data pilot table.", size_t(1), pDPs->GetCount()); pDPObj->SetName(pDPs->CreateNewName()); @@ -2413,13 +2413,13 @@ void Test::testPivotTableDPCollection() // Add 2 DP objects ScDPObject* pDPObj = createDPFromRange(m_pDoc, aDataRange , aFields, nFieldCount, false); - pDPs->InsertNewTable(pDPObj); + pDPs->InsertNewTable(std::unique_ptr<ScDPObject>(pDPObj)); pDPObj->SetName("DP1"); // set custom name CPPUNIT_ASSERT_EQUAL_MESSAGE("there should be only one data pilot table.", size_t(1), pDPs->GetCount()); ScDPObject* pDPObj2 = createDPFromRange(m_pDoc, aDataRange, aFields, nFieldCount, false); - pDPs->InsertNewTable(pDPObj2); + pDPs->InsertNewTable(std::unique_ptr<ScDPObject>(pDPObj2)); pDPObj2->SetName("DP2"); // set custom name CPPUNIT_ASSERT_EQUAL_MESSAGE("there should be two DP tables", size_t(2), pDPs->GetCount()); diff --git a/sc/source/core/data/dpobject.cxx b/sc/source/core/data/dpobject.cxx index f2b322a4c2d8..d68495127de7 100644 --- a/sc/source/core/data/dpobject.cxx +++ b/sc/source/core/data/dpobject.cxx @@ -3706,9 +3706,7 @@ void ScDPCollection::WriteRefsTo( ScDPCollection& r ) const if (!bFound) { // none found, re-insert deleted object (see ScUndoDataPilot::Undo) - - ScDPObject* pDestObj = new ScDPObject(rSrcObj); - r.InsertNewTable(pDestObj); + r.InsertNewTable(o3tl::make_unique<ScDPObject>(rSrcObj)); } } OSL_ENSURE( maTables.size() == r.maTables.size(), "WriteRefsTo: couldn't restore all entries" ); @@ -3778,14 +3776,14 @@ void ScDPCollection::FreeTable(const ScDPObject* pDPObject) maTables.erase(std::remove_if(maTables.begin(), maTables.end(), funcRemoveCondition), maTables.end()); } -void ScDPCollection::InsertNewTable(ScDPObject* pDPObj) +void ScDPCollection::InsertNewTable(std::unique_ptr<ScDPObject> pDPObj) { const ScRange& rOutRange = pDPObj->GetOutRange(); const ScAddress& s = rOutRange.aStart; const ScAddress& e = rOutRange.aEnd; mpDoc->ApplyFlagsTab(s.Col(), s.Row(), e.Col(), e.Row(), s.Tab(), ScMF::DpTable); - maTables.push_back(std::unique_ptr<ScDPObject>(pDPObj)); + maTables.push_back(std::move(pDPObj)); } bool ScDPCollection::HasTable(const ScDPObject* pDPObj) const diff --git a/sc/source/filter/excel/xipivot.cxx b/sc/source/filter/excel/xipivot.cxx index 084924bdfb3f..b46439abbb28 100644 --- a/sc/source/filter/excel/xipivot.cxx +++ b/sc/source/filter/excel/xipivot.cxx @@ -1475,7 +1475,7 @@ void XclImpPivotTable::Convert() } // create the DataPilot - ScDPObject* pDPObj = new ScDPObject( &GetDocRef() ); + std::unique_ptr<ScDPObject> pDPObj(new ScDPObject( &GetDocRef() )); pDPObj->SetName( maPTInfo.maTableName ); if (!maPTInfo.maDataName.isEmpty()) aSaveData.GetDataLayoutDimension()->SetLayoutName(maPTInfo.maDataName); @@ -1488,8 +1488,8 @@ void XclImpPivotTable::Convert() pDPObj->SetOutRange( aOutRange ); pDPObj->SetHeaderLayout( maPTViewEx9Info.mnGridLayout == 0 ); - GetDoc().GetDPCollection()->InsertNewTable(pDPObj); - mpDPObj = pDPObj; + mpDPObj = pDPObj.get(); + GetDoc().GetDPCollection()->InsertNewTable(std::move(pDPObj)); ApplyFieldInfo(); ApplyMergeFlags(aOutRange, aSaveData); diff --git a/sc/source/filter/xml/xmldpimp.cxx b/sc/source/filter/xml/xmldpimp.cxx index 49e0a638e51f..25affb883ab7 100644 --- a/sc/source/filter/xml/xmldpimp.cxx +++ b/sc/source/filter/xml/xmldpimp.cxx @@ -450,7 +450,7 @@ void SAL_CALL ScXMLDataPilotTableContext::endFastElement( sal_Int32 /*nElement*/ if (!bTargetRangeAddress) return; - ScDPObject* pDPObject(new ScDPObject(pDoc)); + std::unique_ptr<ScDPObject> pDPObject(new ScDPObject(pDoc)); pDPObject->SetName(sDataPilotTableName); pDPObject->SetTag(sApplicationData); pDPObject->SetOutRange(aTargetRangeAddress); @@ -467,7 +467,7 @@ void SAL_CALL ScXMLDataPilotTableContext::endFastElement( sal_Int32 /*nElement*/ aImportDesc.aObject = sSourceObject; aImportDesc.nType = sheet::DataImportMode_SQL; aImportDesc.bNative = bIsNative; - rPivotSources.appendDBSource(pDPObject, aImportDesc); + rPivotSources.appendDBSource(pDPObject.get(), aImportDesc); } break; case TABLE : @@ -476,7 +476,7 @@ void SAL_CALL ScXMLDataPilotTableContext::endFastElement( sal_Int32 /*nElement*/ aImportDesc.aDBName = sDatabaseName; aImportDesc.aObject = sSourceObject; aImportDesc.nType = sheet::DataImportMode_TABLE; - rPivotSources.appendDBSource(pDPObject, aImportDesc); + rPivotSources.appendDBSource(pDPObject.get(), aImportDesc); } break; case QUERY : @@ -485,14 +485,14 @@ void SAL_CALL ScXMLDataPilotTableContext::endFastElement( sal_Int32 /*nElement*/ aImportDesc.aDBName = sDatabaseName; aImportDesc.aObject = sSourceObject; aImportDesc.nType = sheet::DataImportMode_QUERY; - rPivotSources.appendDBSource(pDPObject, aImportDesc); + rPivotSources.appendDBSource(pDPObject.get(), aImportDesc); } break; case SERVICE : { ScDPServiceDesc aServiceDesc(sServiceName, sServiceSourceName, sServiceSourceObject, sServiceUsername, sServicePassword); - rPivotSources.appendServiceSource(pDPObject, aServiceDesc); + rPivotSources.appendServiceSource(pDPObject.get(), aServiceDesc); } break; case CELLRANGE : @@ -506,13 +506,13 @@ void SAL_CALL ScXMLDataPilotTableContext::endFastElement( sal_Int32 /*nElement*/ else aSheetDesc.SetSourceRange(aSourceCellRangeAddress); aSheetDesc.SetQueryParam(aSourceQueryParam); - rPivotSources.appendSheetSource(pDPObject, aSheetDesc); + rPivotSources.appendSheetSource(pDPObject.get(), aSheetDesc); } } break; } - rPivotSources.appendSelectedPages(pDPObject, maSelectedPages); + rPivotSources.appendSelectedPages(pDPObject.get(), maSelectedPages); pDPSave->SetRowGrand(maRowGrandTotal.mbVisible); pDPSave->SetColumnGrand(maColGrandTotal.mbVisible); @@ -536,9 +536,9 @@ void SAL_CALL ScXMLDataPilotTableContext::endFastElement( sal_Int32 /*nElement*/ if ( pDPCollection->GetByName(pDPObject->GetName()) ) pDPObject->SetName( OUString() ); // ignore the invalid name, create a new name in AfterXMLLoading - pDPCollection->InsertNewTable(pDPObject); + SetButtons(pDPObject.get()); - SetButtons(pDPObject); + pDPCollection->InsertNewTable(std::move(pDPObject)); } void ScXMLDataPilotTableContext::SetGrandTotal( diff --git a/sc/source/ui/docshell/dbdocfun.cxx b/sc/source/ui/docshell/dbdocfun.cxx index a0f85a2712bd..f1441235e229 100644 --- a/sc/source/ui/docshell/dbdocfun.cxx +++ b/sc/source/ui/docshell/dbdocfun.cxx @@ -1458,7 +1458,7 @@ bool ScDBDocFunc::CreatePivotTable(const ScDPObject& rDPObj, bool bRecord, bool } } - rDoc.GetDPCollection()->InsertNewTable(pDestObj.release()); + rDoc.GetDPCollection()->InsertNewTable(std::move(pDestObj)); rDestObj.ReloadGroupTableData(); rDestObj.SyncAllDimensionMembers(); diff --git a/sc/source/ui/undo/undodat.cxx b/sc/source/ui/undo/undodat.cxx index 1d0f6a3ee354..f6e5d3ca626a 100644 --- a/sc/source/ui/undo/undodat.cxx +++ b/sc/source/ui/undo/undodat.cxx @@ -1457,9 +1457,7 @@ void ScUndoDataPilot::Undo() else if (xOldDPObject) { // re-insert deleted object - - ScDPObject* pDestObj = new ScDPObject(*xOldDPObject); - rDoc.GetDPCollection()->InsertNewTable(pDestObj); + rDoc.GetDPCollection()->InsertNewTable(o3tl::make_unique<ScDPObject>(*xOldDPObject)); } if (xNewUndoDoc) _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits