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

flatten SfxUndoArray

there is really no need to point to an impl which points to a
std::vector

Change-Id: I73c47cf3056a24d909e77b9b4cf9d9ae57c19c04
Reviewed-on: https://gerrit.libreoffice.org/60588
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst d8ac55e3
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <limits> #include <limits>
#include <memory> #include <memory>
#include <vector>
struct MarkedUndoAction; struct MarkedUndoAction;
...@@ -80,42 +81,31 @@ private: ...@@ -80,42 +81,31 @@ private:
typedef sal_Int32 UndoStackMark; typedef sal_Int32 UndoStackMark;
#define MARK_INVALID ::std::numeric_limits< UndoStackMark >::max() #define MARK_INVALID ::std::numeric_limits< UndoStackMark >::max()
class SVL_DLLPUBLIC SfxUndoActions struct MarkedUndoAction
{ {
struct Impl; SfxUndoAction* pAction;
std::unique_ptr<Impl> mpImpl; ::std::vector< UndoStackMark > aMarks;
public:
SfxUndoActions();
SfxUndoActions( const SfxUndoActions& r );
~SfxUndoActions();
bool empty() const;
size_t size() const;
const MarkedUndoAction& operator[]( size_t i ) const;
MarkedUndoAction& operator[]( size_t i );
const SfxUndoAction* GetUndoAction( size_t i ) const;
SfxUndoAction* GetUndoAction( size_t i );
void Remove( size_t i_pos ); MarkedUndoAction(SfxUndoAction* p) : pAction(p) {}
void Remove( size_t i_pos, size_t i_count );
void Insert( SfxUndoAction* i_action, size_t i_pos );
}; };
/** do not make use of these implementation details, unless you /** do not make use of these implementation details, unless you
really really have to! */ really really have to! */
struct SVL_DLLPUBLIC SfxUndoArray struct SVL_DLLPUBLIC SfxUndoArray
{ {
SfxUndoActions aUndoActions; std::vector<MarkedUndoAction> maUndoActions;
size_t nMaxUndoActions; size_t nMaxUndoActions;
size_t nCurUndoAction; size_t nCurUndoAction;
SfxUndoArray *pFatherUndoArray; SfxUndoArray *pFatherUndoArray;
SfxUndoArray(size_t nMax=0):
nMaxUndoActions(nMax), nCurUndoAction(0), SfxUndoArray(size_t nMax=0) :
pFatherUndoArray(nullptr) {} nMaxUndoActions(nMax), nCurUndoAction(0), pFatherUndoArray(nullptr) {}
virtual ~SfxUndoArray(); virtual ~SfxUndoArray();
SfxUndoAction* GetUndoAction(size_t idx) { return maUndoActions[idx].pAction; }
void Remove(int idx);
void Remove( size_t i_pos, size_t i_count );
void Insert( SfxUndoAction* i_action, size_t i_pos );
}; };
......
...@@ -503,9 +503,9 @@ void SdTiledRenderingTest::testSetGraphicSelection() ...@@ -503,9 +503,9 @@ void SdTiledRenderingTest::testSetGraphicSelection()
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pUndoManager->GetUndoActionCount()); CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pUndoManager->GetUndoActionCount());
auto pListAction = dynamic_cast<SfxListUndoAction*>(pUndoManager->GetUndoAction()); auto pListAction = dynamic_cast<SfxListUndoAction*>(pUndoManager->GetUndoAction());
CPPUNIT_ASSERT(pListAction); CPPUNIT_ASSERT(pListAction);
for (size_t i = 0; i < pListAction->aUndoActions.size(); ++i) for (size_t i = 0; i < pListAction->maUndoActions.size(); ++i)
// The second item was -1 here, view shell ID wasn't known. // The second item was -1 here, view shell ID wasn't known.
CPPUNIT_ASSERT_EQUAL(ViewShellId(nView1), pListAction->aUndoActions.GetUndoAction(i)->GetViewShellId()); CPPUNIT_ASSERT_EQUAL(ViewShellId(nView1), pListAction->GetUndoAction(i)->GetViewShellId());
::tools::Rectangle aShapeAfter = pObject->GetSnapRect(); ::tools::Rectangle aShapeAfter = pObject->GetSnapRect();
// Check that a resize happened, but aspect ratio is not kept. // Check that a resize happened, but aspect ratio is not kept.
......
...@@ -1488,11 +1488,11 @@ void OutlineView::TryToMergeUndoActions() ...@@ -1488,11 +1488,11 @@ void OutlineView::TryToMergeUndoActions()
if( pListAction && pPrevListAction ) if( pListAction && pPrevListAction )
{ {
// find the top EditUndo action in the top undo action list // find the top EditUndo action in the top undo action list
size_t nAction = pListAction->aUndoActions.size(); size_t nAction = pListAction->maUndoActions.size();
EditUndo* pEditUndo = nullptr; EditUndo* pEditUndo = nullptr;
while( !pEditUndo && nAction ) while( !pEditUndo && nAction )
{ {
pEditUndo = dynamic_cast< EditUndo* >(pListAction->aUndoActions.GetUndoAction(--nAction)); pEditUndo = dynamic_cast< EditUndo* >(pListAction->GetUndoAction(--nAction));
} }
sal_uInt16 nEditPos = nAction; // we need this later to remove the merged undo actions sal_uInt16 nEditPos = nAction; // we need this later to remove the merged undo actions
...@@ -1500,7 +1500,7 @@ void OutlineView::TryToMergeUndoActions() ...@@ -1500,7 +1500,7 @@ void OutlineView::TryToMergeUndoActions()
// make sure it is the only EditUndo action in the top undo list // make sure it is the only EditUndo action in the top undo list
while( pEditUndo && nAction ) while( pEditUndo && nAction )
{ {
if( dynamic_cast< EditUndo* >(pListAction->aUndoActions.GetUndoAction(--nAction)) ) if( dynamic_cast< EditUndo* >(pListAction->GetUndoAction(--nAction)) )
pEditUndo = nullptr; pEditUndo = nullptr;
} }
...@@ -1509,10 +1509,10 @@ void OutlineView::TryToMergeUndoActions() ...@@ -1509,10 +1509,10 @@ void OutlineView::TryToMergeUndoActions()
{ {
// yes, see if we can merge it with the prev undo list // yes, see if we can merge it with the prev undo list
nAction = pPrevListAction->aUndoActions.size(); nAction = pPrevListAction->maUndoActions.size();
EditUndo* pPrevEditUndo = nullptr; EditUndo* pPrevEditUndo = nullptr;
while( !pPrevEditUndo && nAction ) while( !pPrevEditUndo && nAction )
pPrevEditUndo = dynamic_cast< EditUndo* >(pPrevListAction->aUndoActions.GetUndoAction(--nAction)); pPrevEditUndo = dynamic_cast< EditUndo* >(pPrevListAction->GetUndoAction(--nAction));
if( pPrevEditUndo && pPrevEditUndo->Merge( pEditUndo ) ) if( pPrevEditUndo && pPrevEditUndo->Merge( pEditUndo ) )
{ {
...@@ -1520,26 +1520,26 @@ void OutlineView::TryToMergeUndoActions() ...@@ -1520,26 +1520,26 @@ void OutlineView::TryToMergeUndoActions()
// the top EditUndo of the previous undo list // the top EditUndo of the previous undo list
// first remove the merged undo action // first remove the merged undo action
DBG_ASSERT( pListAction->aUndoActions.GetUndoAction(nEditPos) == pEditUndo, DBG_ASSERT( pListAction->GetUndoAction(nEditPos) == pEditUndo,
"sd::OutlineView::TryToMergeUndoActions(), wrong edit pos!" ); "sd::OutlineView::TryToMergeUndoActions(), wrong edit pos!" );
pListAction->aUndoActions.Remove(nEditPos); pListAction->Remove(nEditPos);
delete pEditUndo; delete pEditUndo;
if ( !pListAction->aUndoActions.empty() ) if ( !pListAction->maUndoActions.empty() )
{ {
// now we have to move all remaining doc undo actions from the top undo // now we have to move all remaining doc undo actions from the top undo
// list to the previous undo list and remove the top undo list // list to the previous undo list and remove the top undo list
size_t nCount = pListAction->aUndoActions.size(); size_t nCount = pListAction->maUndoActions.size();
size_t nDestAction = pPrevListAction->aUndoActions.size(); size_t nDestAction = pPrevListAction->maUndoActions.size();
while( nCount-- ) while( nCount-- )
{ {
SfxUndoAction* pTemp = pListAction->aUndoActions.GetUndoAction(0); SfxUndoAction* pTemp = pListAction->GetUndoAction(0);
pListAction->aUndoActions.Remove(0); pListAction->Remove(0);
if( pTemp ) if( pTemp )
pPrevListAction->aUndoActions.Insert( pTemp, nDestAction++ ); pPrevListAction->Insert( pTemp, nDestAction++ );
} }
pPrevListAction->nCurUndoAction = pPrevListAction->aUndoActions.size(); pPrevListAction->nCurUndoAction = pPrevListAction->maUndoActions.size();
} }
rOutlineUndo.RemoveLastUndoAction(); rOutlineUndo.RemoveLastUndoAction();
......
This diff is collapsed.
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