diff options
author | Michael Stahl <michael.stahl@allotropia.de> | 2021-11-30 20:27:24 +0100 |
---|---|---|
committer | Michael Stahl <michael.stahl@allotropia.de> | 2021-12-01 13:52:24 +0100 |
commit | 25a368c30acb54e0819d2b2b890a3fd1530d8a76 (patch) | |
tree | 4d48772b82e4a9d99d23702012abb25685e3c296 /include/svx | |
parent | 9425ea3f8f5622e857dc1e860b151fd94323de0c (diff) |
tdf#145928 svx: fix undo of sorting shapes
The problem is that in sw there are these obnoxious virtual SdrObjects
that are created and destroyed by the layout.
0 SdrObject::~SdrObject()
3 SwVirtFlyDrawObj::~SwVirtFlyDrawObj()
5 SwFlyFrame::FinitDrawObj()
12 SwFrame::DestroyFrame(SwFrame*)
13 SwFrameFormat::DelFrames()
14 SwUndoFlyBase::DelFly(SwDoc*)
15 SwUndoDelLayFormat::SwUndoDelLayFormat(SwFrameFormat*)
16 SwHistoryTextFlyCnt::SwHistoryTextFlyCnt(SwFrameFormat*)
This misdesign means that SdrUndoObj::pObj may point to a deleted
object.
Commit 9bc6160e0acbc78be998129ea55ed7e4529959fa may create SdrUnoObj
when saving the document, so that is now an additional way to introduce
the problem.
Try to work around it by not using a SdrUndoObj subclass in this case,
but create a new SdrUndoAction subclass that uses SdrPage::sort() and
stores no pointers.
There is still the problem that changes in the layout or view settings
like "Hide tracked changes" could cause different virtual SdrObjects to
exist between when the Undo was recorded and when it is activated, in
which case nothing is done.
But that really requires a larger refactoring such as having a SdrPage
for the model that never contains virtual SdrObjects, and another
SdrPage for the view that does contain virtual SdrObjects to fix.
Change-Id: I4cf5d4eb8bb24a51730c55ff34a043b8a88fdb52
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126153
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
Diffstat (limited to 'include/svx')
-rw-r--r-- | include/svx/svdundo.hxx | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/include/svx/svdundo.hxx b/include/svx/svdundo.hxx index 67ca464b5b4c..5bb4e26c1a43 100644 --- a/include/svx/svdundo.hxx +++ b/include/svx/svdundo.hxx @@ -377,6 +377,24 @@ public: virtual OUString GetComment() const override; }; +class SdrUndoSort final : public SdrUndoAction +{ +private: + ::std::vector<sal_Int32> m_OldSortOrder; + ::std::vector<sal_Int32> m_NewSortOrder; + sal_uInt16 const m_nPage; + + void Do(::std::vector<sal_Int32> & rSortOrder); + +public: + SdrUndoSort(SdrPage & rPage, + ::std::vector<sal_Int32> const& rSortOrder); + + virtual void Undo() override; + virtual void Redo() override; + + virtual OUString GetComment() const override; +}; // #i11702# @@ -732,6 +750,7 @@ public: virtual std::unique_ptr<SdrUndoAction> CreateUndoNewPage(SdrPage& rPage); virtual std::unique_ptr<SdrUndoAction> CreateUndoCopyPage(SdrPage& rPage); virtual std::unique_ptr<SdrUndoAction> CreateUndoSetPageNum(SdrPage& rNewPg, sal_uInt16 nOldPageNum1, sal_uInt16 nNewPageNum1); + virtual std::unique_ptr<SdrUndoAction> CreateUndoSort(SdrPage& rPage, ::std::vector<sal_Int32> const& rSortOrder); // Master page virtual std::unique_ptr<SdrUndoAction> CreateUndoPageRemoveMasterPage(SdrPage& rChangedPage); |