summaryrefslogtreecommitdiff
path: root/svx
diff options
context:
space:
mode:
authorArmin Le Grand (Allotropia) <Armin.Le.Grand@me.com>2022-05-10 15:59:29 +0200
committerArmin Le Grand <Armin.Le.Grand@me.com>2022-05-11 14:17:34 +0200
commit1e016920769ae524575e40b1ec317c700ba0daa3 (patch)
tree24dc1a6cb9f35ea07879564eb82376fcb0fbd313 /svx
parent5b9b07dcb3e0065ddb616a0a5b0e69c1c3841fa7 (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 'svx')
-rw-r--r--svx/source/diagram/datamodel.cxx27
-rw-r--r--svx/source/svdraw/svdundo.cxx53
2 files changed, 80 insertions, 0 deletions
diff --git a/svx/source/diagram/datamodel.cxx b/svx/source/diagram/datamodel.cxx
index fd562645eaa0..e45fe7fb4c3a 100644
--- a/svx/source/diagram/datamodel.cxx
+++ b/svx/source/diagram/datamodel.cxx
@@ -141,6 +141,33 @@ bool DiagramData::removeNode(const OUString& rNodeId)
return true;
}
+DiagramDataState::DiagramDataState(const Connections& rConnections, const Points& rPoints)
+: maConnections(rConnections)
+, maPoints(rPoints)
+{
+}
+
+DiagramDataStatePtr DiagramData::extractDiagramDataState() const
+{
+ // Just copy all Connections && Points. The shared_ptr data in
+ // Point-entries is no problem, it just continues exiting shared
+ return std::make_shared< DiagramDataState >(maConnections, maPoints);
+}
+
+void DiagramData::applyDiagramDataState(const DiagramDataStatePtr& rState)
+{
+ if(rState)
+ {
+ maConnections = rState->getConnections();
+ maPoints = rState->getPoints();
+
+ // Reset temporary buffered ModelData association lists & rebuild them
+ // and the Diagram DataModel. Do that here *immediately* to prevent
+ // re-usage of potentially invalid Connection/Point objects
+ buildDiagramDataModel(true);
+ }
+}
+
void DiagramData::getChildrenString(
OUStringBuffer& rBuf,
const svx::diagram::Point* pPoint,
diff --git a/svx/source/svdraw/svdundo.cxx b/svx/source/svdraw/svdundo.cxx
index f1c97c4c16a8..b61ad93fde90 100644
--- a/svx/source/svdraw/svdundo.cxx
+++ b/svx/source/svdraw/svdundo.cxx
@@ -45,6 +45,7 @@
#include <svx/svdoashp.hxx>
#include <sal/log.hxx>
#include <osl/diagnose.h>
+#include <svx/diagram/datamodel.hxx>
// iterates over all views and unmarks this SdrObject if it is marked
@@ -628,6 +629,52 @@ OUString SdrUndoGeoObj::GetComment() const
return ImpGetDescriptionStr(STR_DragMethObjOwn);
}
+SdrUndoDiagramModelData::SdrUndoDiagramModelData(SdrObject& rNewObj, svx::diagram::DiagramDataStatePtr& rStartState)
+: SdrUndoObj(rNewObj)
+, m_aStartState(rStartState)
+, m_aEndState()
+{
+ SdrObjGroup* pDiagram(dynamic_cast<SdrObjGroup*>(&rNewObj));
+
+ if(pDiagram && pDiagram->isDiagram())
+ {
+ m_aEndState = pDiagram->getDiagramHelper()->extractDiagramDataState();
+ }
+}
+
+SdrUndoDiagramModelData::~SdrUndoDiagramModelData()
+{
+}
+
+void SdrUndoDiagramModelData::implUndoRedo(bool bUndo)
+{
+ if(nullptr == pObj)
+ return;
+
+ SdrObjGroup* pDiagram(dynamic_cast<SdrObjGroup*>(pObj));
+
+ if(nullptr == pDiagram || !pDiagram->isDiagram())
+ return;
+
+ pDiagram->getDiagramHelper()->applyDiagramDataState(
+ bUndo ? m_aStartState : m_aEndState);
+ pDiagram->getDiagramHelper()->reLayout(*pDiagram);
+}
+
+void SdrUndoDiagramModelData::Undo()
+{
+ implUndoRedo(true);
+}
+
+void SdrUndoDiagramModelData::Redo()
+{
+ implUndoRedo(false);
+}
+
+OUString SdrUndoDiagramModelData::GetComment() const
+{
+ return ImpGetDescriptionStr(STR_DiagramModelDataChange);
+}
SdrUndoObjList::SdrUndoObjList(SdrObject& rNewObj, bool bOrdNumDirect)
: SdrUndoObj(rNewObj)
@@ -1676,6 +1723,12 @@ std::unique_ptr<SdrUndoAction> SdrUndoFactory::CreateUndoGeoObject( SdrObject& r
return std::make_unique<SdrUndoGeoObj>( rObject );
}
+// Diagram ModelData changes
+std::unique_ptr<SdrUndoAction> SdrUndoFactory::CreateUndoDiagramModelData( SdrObject& rObject, std::shared_ptr< svx::diagram::DiagramDataState >& rStartState )
+{
+ return std::make_unique<SdrUndoDiagramModelData>( rObject, rStartState );
+}
+
std::unique_ptr<SdrUndoAction> SdrUndoFactory::CreateUndoAttrObject( SdrObject& rObject, bool bStyleSheet1, bool bSaveText )
{
return std::make_unique<SdrUndoAttrObj>( rObject, bStyleSheet1, bSaveText );