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

use unique_ptr in SdrUndoGroup

Change-Id: I569c56b6114e07b2a227ad0f906c1a5188a94af4
Reviewed-on: https://gerrit.libreoffice.org/61528
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 33e596e0
......@@ -85,7 +85,7 @@ public:
class SVX_DLLPUBLIC SdrUndoGroup final : public SdrUndoAction
{
std::vector<SdrUndoAction*> aBuf;
std::vector<std::unique_ptr<SdrUndoAction>> maActions;
// No expanded description of the Action (contains %O)
OUString aComment;
......@@ -98,9 +98,9 @@ public:
virtual ~SdrUndoGroup() override;
void Clear();
sal_Int32 GetActionCount() const { return aBuf.size(); }
SdrUndoAction* GetAction(sal_Int32 nNum) const { return aBuf[nNum]; }
void AddAction(SdrUndoAction* pAct);
sal_Int32 GetActionCount() const { return maActions.size(); }
SdrUndoAction* GetAction(sal_Int32 nNum) const { return maActions[nNum].get(); }
void AddAction(std::unique_ptr<SdrUndoAction> pAct);
void SetComment(const OUString& rStr) { aComment=rStr; }
void SetObjDescription(const OUString& rStr) { aObjDescription=rStr; }
......
......@@ -1193,7 +1193,7 @@ void ScDrawLayer::AddCalcUndo( std::unique_ptr<SdrUndoAction> pUndo )
if (!pUndoGroup)
pUndoGroup.reset(new SdrUndoGroup(*this));
pUndoGroup->AddAction( pUndo.release() );
pUndoGroup->AddAction( std::move(pUndo) );
}
}
......
......@@ -518,7 +518,7 @@ void ScDrawView::SetMarkedOriginalSize()
{
tools::Rectangle aDrawRect = pObj->GetLogicRect();
pUndoGroup->AddAction( new SdrUndoGeoObj( *pObj ) );
pUndoGroup->AddAction( o3tl::make_unique<SdrUndoGeoObj>( *pObj ) );
pObj->Resize( aDrawRect.TopLeft(), Fraction( aOriginalSize.Width(), aDrawRect.GetWidth() ),
Fraction( aOriginalSize.Height(), aDrawRect.GetHeight() ) );
++nDone;
......@@ -581,7 +581,7 @@ void ScDrawView::FitToCellSize()
aCellRect.setHeight(static_cast<double>(aGraphicRect.GetHeight()) * fScaleMin);
}
pUndoGroup->AddAction( new SdrUndoGeoObj( *pObj ) );
pUndoGroup->AddAction( o3tl::make_unique<SdrUndoGeoObj>( *pObj ) );
pObj->SetSnapRect(aCellRect);
......
......@@ -886,7 +886,7 @@ void View::SetMarkedOriginalSize()
{
::tools::Rectangle aDrawRect( pObj->GetLogicRect() );
pUndoGroup->AddAction( mrDoc.GetSdrUndoFactory().CreateUndoGeoObject( *pObj ) );
pUndoGroup->AddAction( std::unique_ptr<SdrUndoAction>(mrDoc.GetSdrUndoFactory().CreateUndoGeoObject( *pObj )) );
pObj->Resize( aDrawRect.TopLeft(), Fraction( aOleSize.Width(), aDrawRect.GetWidth() ),
Fraction( aOleSize.Height(), aDrawRect.GetHeight() ) );
}
......@@ -896,7 +896,7 @@ void View::SetMarkedOriginalSize()
{
const SdrGrafObj* pSdrGrafObj = static_cast< const SdrGrafObj* >(pObj);
const Size aSize = pSdrGrafObj->getOriginalSize( );
pUndoGroup->AddAction( GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pObj ) );
pUndoGroup->AddAction( std::unique_ptr<SdrUndoAction>(GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pObj )) );
::tools::Rectangle aRect( pObj->GetLogicRect() );
aRect.SetSize( aSize );
pObj->SetLogicRect( aRect );
......@@ -1334,8 +1334,7 @@ void View::ChangeMarkedObjectsBulletsNumbering(
pOutliner->SetText(*(pText->GetOutlinerParaObject()));
if (bUndoEnabled)
{
SdrUndoObjSetText* pTxtUndo = dynamic_cast< SdrUndoObjSetText* >(pSdrModel->GetSdrUndoFactory().CreateUndoObjectSetText(*pTextObj, nCellIndex));
pUndoGroup->AddAction(pTxtUndo);
pUndoGroup->AddAction(std::unique_ptr<SdrUndoAction>(pSdrModel->GetSdrUndoFactory().CreateUndoObjectSetText(*pTextObj, nCellIndex)));
}
if ( !bToggleOn )
{
......@@ -1365,8 +1364,8 @@ void View::ChangeMarkedObjectsBulletsNumbering(
pOutliner->SetText(*pParaObj);
if (bUndoEnabled)
{
SdrUndoObjSetText* pTxtUndo = dynamic_cast< SdrUndoObjSetText* >(pSdrModel->GetSdrUndoFactory().CreateUndoObjectSetText(*pTextObj, 0));
pUndoGroup->AddAction(pTxtUndo);
pUndoGroup->AddAction(
std::unique_ptr<SdrUndoAction>(pSdrModel->GetSdrUndoFactory().CreateUndoObjectSetText(*pTextObj, 0)));
}
if ( !bToggleOn )
{
......
......@@ -574,7 +574,7 @@ void SdrModel::AddUndo(SdrUndoAction* pUndo)
{
if (pCurrentUndoGroup)
{
pCurrentUndoGroup->AddAction(pUndo);
pCurrentUndoGroup->AddAction(std::unique_ptr<SdrUndoAction>(pUndo));
}
else
{
......
......@@ -110,44 +110,33 @@ ViewShellId SdrUndoAction::GetViewShellId() const
SdrUndoGroup::SdrUndoGroup(SdrModel& rNewMod)
: SdrUndoAction(rNewMod),
aBuf(),
eFunction(SdrRepeatFunc::NONE)
{}
SdrUndoGroup::~SdrUndoGroup()
{
Clear();
}
void SdrUndoGroup::Clear()
{
for (sal_Int32 nu=0; nu<GetActionCount(); nu++) {
SdrUndoAction* pAct=GetAction(nu);
delete pAct;
}
aBuf.clear();
maActions.clear();
}
void SdrUndoGroup::AddAction(SdrUndoAction* pAct)
void SdrUndoGroup::AddAction(std::unique_ptr<SdrUndoAction> pAct)
{
aBuf.push_back(pAct);
maActions.push_back(std::move(pAct));
}
void SdrUndoGroup::Undo()
{
for (sal_Int32 nu=GetActionCount(); nu>0;) {
nu--;
SdrUndoAction* pAct=GetAction(nu);
pAct->Undo();
}
for (auto it = maActions.rbegin(); it != maActions.rend(); ++it)
(*it)->Undo();
}
void SdrUndoGroup::Redo()
{
for (sal_Int32 nu=0; nu<GetActionCount(); nu++) {
SdrUndoAction* pAct=GetAction(nu);
pAct->Redo();
}
for (std::unique_ptr<SdrUndoAction> & pAction : maActions)
pAction->Redo();
}
OUString SdrUndoGroup::GetComment() const
......@@ -282,7 +271,7 @@ SdrUndoAttrObj::SdrUndoAttrObj(SdrObject& rNewObj, bool bStyleSheet1, bool bSave
for(size_t nObjNum = 0; nObjNum < nObjCount; ++nObjNum)
{
pUndoGroup->AddAction(
new SdrUndoAttrObj(*pOL->GetObj(nObjNum), bStyleSheet1));
o3tl::make_unique<SdrUndoAttrObj>(*pOL->GetObj(nObjNum), bStyleSheet1));
}
}
......@@ -585,7 +574,7 @@ SdrUndoGeoObj::SdrUndoGeoObj(SdrObject& rNewObj)
pUndoGroup.reset(new SdrUndoGroup(pObj->getSdrModelFromSdrObject()));
const size_t nObjCount = pOL->GetObjCount();
for (size_t nObjNum = 0; nObjNum<nObjCount; ++nObjNum) {
pUndoGroup->AddAction(new SdrUndoGeoObj(*pOL->GetObj(nObjNum)));
pUndoGroup->AddAction(o3tl::make_unique<SdrUndoGeoObj>(*pOL->GetObj(nObjNum)));
}
}
else
......@@ -1431,7 +1420,7 @@ SdrUndoDelPage::SdrUndoDelPage(SdrPage& rNewPg)
pUndoGroup.reset( new SdrUndoGroup(rMod) );
}
pUndoGroup->AddAction(rMod.GetSdrUndoFactory().CreateUndoPageRemoveMasterPage(*pDrawPage));
pUndoGroup->AddAction(std::unique_ptr<SdrUndoAction>(rMod.GetSdrUndoFactory().CreateUndoPageRemoveMasterPage(*pDrawPage)));
}
}
}
......
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