diff options
author | Armin Le Grand (Allotropia) <Armin.Le.Grand@me.com> | 2022-05-10 15:59:29 +0200 |
---|---|---|
committer | Armin Le Grand <Armin.Le.Grand@me.com> | 2022-05-11 14:17:34 +0200 |
commit | 1e016920769ae524575e40b1ec317c700ba0daa3 (patch) | |
tree | 24dc1a6cb9f35ea07879564eb82376fcb0fbd313 /include | |
parent | 5b9b07dcb3e0065ddb616a0a5b0e69c1c3841fa7 (diff) |
Advanced Diagram support: UNDO/REDO support for Diagram DataModel
Added support for UNDO/REDO for changes in Diagram ModelData.
This is currenly applied/used in the DiagramDialog for it's
Add/Remove actions (also supports Cancel of that dialog 1st
time ever). But it is defined more general to add/support
manipulating actions like clone/change_text etc. Also the
UI/dialog at he end will not be/stay modal, so this is a
test implemenation how to use it.
It uses an extract/apply mechanism to get/set the Diagram
ModelData at/for the UNDO action. That may be expanded as
needed for additional data in he future. It may also be
considered to modify the Connection/Point ModelData to
shared_ptr internally completely to avoid copying these
at all. OTOH it is not that much data to handle at all.
Change-Id: I4702ed908b79a476177fe66c0e3284898c6adda5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134118
Tested-by: Jenkins
Reviewed-by: Armin Le Grand <Armin.Le.Grand@me.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/svx/diagram/datamodel.hxx | 20 | ||||
-rw-r--r-- | include/svx/strings.hrc | 1 | ||||
-rw-r--r-- | include/svx/svdogrp.hxx | 13 | ||||
-rw-r--r-- | include/svx/svdundo.hxx | 25 | ||||
-rw-r--r-- | include/vcl/abstdlg.hxx | 4 |
5 files changed, 61 insertions, 2 deletions
diff --git a/include/svx/diagram/datamodel.hxx b/include/svx/diagram/datamodel.hxx index 7a080f8703ee..850cd8f78271 100644 --- a/include/svx/diagram/datamodel.hxx +++ b/include/svx/diagram/datamodel.hxx @@ -154,6 +154,22 @@ struct SVXCORE_DLLPUBLIC Point typedef std::vector< Point > Points; +/** Snippet of Diagram ModelData for Diagram-defining data undo/redo + */ +class SVXCORE_DLLPUBLIC DiagramDataState +{ + Connections maConnections; + Points maPoints; + +public: + DiagramDataState(const Connections& rConnections, const Points& rPoints); + + Connections& getConnections() { return maConnections; } + Points& getPoints() { return maPoints; } +}; + +typedef std::shared_ptr< DiagramDataState > DiagramDataStatePtr; + /** The collected Diagram ModelData */ class SVXCORE_DLLPUBLIC DiagramData @@ -207,6 +223,10 @@ public: OUString addNode(const OUString& rText); bool removeNode(const OUString& rNodeId); + // Undo/Redo helpers to extract/restore Diagram-defining data + DiagramDataStatePtr extractDiagramDataState() const; + void applyDiagramDataState(const DiagramDataStatePtr& rState); + protected: // helpers void getChildrenString(OUStringBuffer& rBuf, const Point* pPoint, sal_Int32 nLevel) const; diff --git a/include/svx/strings.hrc b/include/svx/strings.hrc index e9b354f6f151..17f2b17d6081 100644 --- a/include/svx/strings.hrc +++ b/include/svx/strings.hrc @@ -210,6 +210,7 @@ #define STR_DragInsertGluePoint NC_("STR_DragInsertGluePoint", "Insert gluepoint to %1") #define STR_DragMethMovHdl NC_("STR_DragMethMovHdl", "Move reference-point") #define STR_DragMethObjOwn NC_("STR_DragMethObjOwn", "Geometrically change %1") +#define STR_DiagramModelDataChange NC_("STR_DiagramModelDataChange", "Diagram change %1") #define STR_DragMethMove NC_("STR_DragMethMove", "Move %1") #define STR_DragMethResize NC_("STR_DragMethResize", "Resize %1") #define STR_DragMethRotate NC_("STR_DragMethRotate", "Rotate %1") diff --git a/include/svx/svdogrp.hxx b/include/svx/svdogrp.hxx index 5aab501ec9e4..c411a049c959 100644 --- a/include/svx/svdogrp.hxx +++ b/include/svx/svdogrp.hxx @@ -27,6 +27,13 @@ // Forward declarations class SfxItemSet; class SdrObjGroup; +namespace svx +{ +namespace diagram +{ +class DiagramDataState; +} +} // Helper class to allow administer advanced Diagram related // data and functionality @@ -81,6 +88,12 @@ public: virtual OUString addNode(const OUString& rText) = 0; virtual bool removeNode(const OUString& rNodeId) = 0; + // Undo/Redo helpers for extracting/restoring Diagram-defining data + virtual std::shared_ptr<svx::diagram::DiagramDataState> extractDiagramDataState() const = 0; + virtual void + applyDiagramDataState(const std::shared_ptr<svx::diagram::DiagramDataState>& rState) + = 0; + bool UseDiagramThemeData() const { return mbUseDiagramThemeData; } bool UseDiagramModelData() const { return mbUseDiagramModelData; } bool ForceThemePtrRecreation() const { return mbForceThemePtrRecreation; }; diff --git a/include/svx/svdundo.hxx b/include/svx/svdundo.hxx index c4116616e43a..01b4f6749770 100644 --- a/include/svx/svdundo.hxx +++ b/include/svx/svdundo.hxx @@ -49,6 +49,10 @@ class SdrLayerAdmin; class SdrObjGeoData; class OutlinerParaObject; +namespace svx { namespace diagram { + class DiagramDataState; +}} + /** * Abstract base class (ABC) for all UndoActions of DrawingEngine */ @@ -224,6 +228,24 @@ public: void SetSkipChangeLayout(bool bOn) { mbSkipChangeLayout=bOn; } }; +// Diagram ModelData changes +class SVXCORE_DLLPUBLIC SdrUndoDiagramModelData : public SdrUndoObj +{ + std::shared_ptr< svx::diagram::DiagramDataState > m_aStartState; + std::shared_ptr< svx::diagram::DiagramDataState > m_aEndState; + + void implUndoRedo(bool bUndo); + +public: + SdrUndoDiagramModelData(SdrObject& rNewObj, std::shared_ptr< svx::diagram::DiagramDataState >& rStartState); + virtual ~SdrUndoDiagramModelData() override; + + virtual void Undo() override; + virtual void Redo() override; + + virtual OUString GetComment() const override; +}; + /** * Manipulation of an ObjList: New Object, DeleteObj, SetObjZLevel, Grouping, ... * Abstract base class. @@ -741,6 +763,9 @@ public: const OUString& sOldStr, const OUString& sNewStr ); + // Diagram ModelData changes + virtual std::unique_ptr<SdrUndoAction> CreateUndoDiagramModelData( SdrObject& rObject, std::shared_ptr< svx::diagram::DiagramDataState >& rStartState ); + // Layer virtual std::unique_ptr<SdrUndoAction> CreateUndoNewLayer(sal_uInt16 nLayerNum, SdrLayerAdmin& rNewLayerAdmin, SdrModel& rNewModel); virtual std::unique_ptr<SdrUndoAction> CreateUndoDeleteLayer(sal_uInt16 nLayerNum, SdrLayerAdmin& rNewLayerAdmin, SdrModel& rNewModel); diff --git a/include/vcl/abstdlg.hxx b/include/vcl/abstdlg.hxx index f6097f940655..79b2b32a9836 100644 --- a/include/vcl/abstdlg.hxx +++ b/include/vcl/abstdlg.hxx @@ -34,7 +34,7 @@ namespace com::sun::star::frame { class XModel; } class Dialog; class BitmapEx; -class IDiagramHelper; +class SdrObjGroup; namespace weld { class Dialog; @@ -179,7 +179,7 @@ public: virtual VclPtr<AbstractDiagramDialog> CreateDiagramDialog( weld::Window* pParent, - const std::shared_ptr<IDiagramHelper>& pDiagramHelper) = 0; + SdrObjGroup& rDiagram) = 0; #ifdef _WIN32 virtual VclPtr<VclAbstractDialog> |