Kaydet (Commit) 0317541c authored tarafından Noel Grandin's avatar Noel Grandin

use more std::unique_ptr in ScDPCollection

Change-Id: I7d76704ba76b0d47544456047bc699b12fa7c288
Reviewed-on: https://gerrit.libreoffice.org/61435
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 8122551c
......@@ -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();
......
......@@ -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());
......
......@@ -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
......
......@@ -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);
......
......@@ -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(
......
......@@ -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();
......
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment