Verovio
Source code documentation
editortoolkit_shared.h
1 // Name: editortoolkit_shared.h
3 // Author: Laurent Pugin
4 // Created: 03/02/2026
5 // Copyright (c) Authors and others. All rights reserved.
7 
8 #ifndef __VRV_EDITOR_TOOLKIT_SHARED_H__
9 #define __VRV_EDITOR_TOOLKIT_SHARED_H__
10 
11 #include <cmath>
12 #include <deque>
13 #include <string>
14 #include <utility>
15 
16 //--------------------------------------------------------------------------------
17 
18 #include "doc.h"
19 #include "editortoolkit.h"
20 #include "view.h"
21 
22 #include "jsonxx.h"
23 
24 namespace vrv {
25 
26 class EditorTreeObject;
27 
28 //--------------------------------------------------------------------------------
29 // EditorToolkitShared
30 //--------------------------------------------------------------------------------
31 
33 public:
34  EditorToolkitShared(Doc *doc, View *view);
35  virtual ~EditorToolkitShared();
36  bool ParseEditorAction(const std::string &json_editorAction) override
37  {
38  return ParseEditorAction(json_editorAction, false);
39  }
40  bool ParseEditorAction(const std::string &json_editorAction, bool commitOnly = false);
41 
42 protected:
43 #ifndef NO_EDIT_SUPPORT
48  bool Chain(jsonxx::Array actions);
49  bool ParseContextAction(jsonxx::Object param, std::string &elementId, bool &scores, bool &sections);
50  bool ParseDeleteAction(jsonxx::Object param, std::string &elementId);
51  bool ParseDragAction(jsonxx::Object param, std::string &elementId, int &x, int &y);
52  bool ParseKeyDownAction(jsonxx::Object param, std::string &elementid, int &key, bool &shiftKey, bool &ctrlKey);
53  bool ParseInsertAction(
54  jsonxx::Object param, std::string &elementName, std::string &elementId, std::string &insertMode);
55  bool ParseInsertControlAction(
56  jsonxx::Object param, std::string &elementName, std::string &startId, std::string &endId);
57  bool ParseNavigate(jsonxx::Object param, std::string &elementId, int &direction);
58  bool ParsePropertiesAction(jsonxx::Object param, std::string &scoreDef);
59  bool ParseSetAction(jsonxx::Object param, std::string &elementId, std::string &attribute, std::string &value);
61 
62  void SetEditInfo();
63  void PrepareUndo();
64  std::string GetCurrentState();
65  bool ReloadState(const std::string &data);
66  void TrimUndoMemory();
67  bool CanUndo() const;
68  bool CanRedo() const;
69  bool Undo();
70  bool Redo();
71 
76  bool Delete(std::string &elementId);
77  bool Drag(std::string &elementId, int x, int y);
78  bool InsertControl(const std::string &elementName, const std::string startId, const std::string endId);
79  bool KeyDown(std::string &elementId, int key, bool shiftKey, bool ctrlKey);
80  bool Navigate(std::string &elementId, const int &direction);
81  bool Set(std::string &elementId, std::string const &attribute, std::string const &value);
83 
84  void ClearContext();
85  bool ContextForElement(std::string &elementId);
86  bool ContextForScores(bool editInfo);
87  bool ContextForSections(bool editInfo);
88 
89  bool GetScoreDef();
90  bool SetScoreDef(const std::string scoreDef);
91 
92  void ContextForObject(const Object *object, jsonxx::Object &element, bool recursive = false);
93  void ContextForObjects(const ArrayOfConstObjects &objects, jsonxx::Array &siblings);
94  void ContextForReferences(const ListOfObjectAttNamePairs &objects, jsonxx::Array &links);
95 
96  ArrayOfConstObjects GetScoreBasedChildrenFor(const Object *object);
97 
98  void CollectReferringObjects(
99  const Object *element, std::set<std::string> &toDelete, std::set<const Object *> &visited);
100 
101 public:
102  //
103 protected:
104  bool m_undoPrepared;
105  std::deque<std::string> m_undoStack;
106  std::deque<std::string> m_redoStack;
107  size_t m_undoMemoryUsage = 0;
108 
109  EditorTreeObject *m_scoreContext;
110  EditorTreeObject *m_sectionContext;
111  EditorTreeObject *m_currentContext;
112 };
113 
114 //----------------------------------------------------------------------------
115 // EditorTreeObject
116 //----------------------------------------------------------------------------
117 
122 
123 public:
129  EditorTreeObject(const Object *object, bool ownChildren);
130  virtual ~EditorTreeObject() {};
131  void Reset() override;
132  std::string GetClassName() const override { return m_className; }
134 
139  bool IsSupportedChild(ClassId classId) override { return true; }
141 
146  VisibilityDrawingInterface *GetVisibilityDrawingInterface() override
147  {
148  return vrv_cast<VisibilityDrawingInterface *>(this);
149  }
150  const VisibilityDrawingInterface *GetVisibilityDrawingInterface() const override
151  {
152  return vrv_cast<const VisibilityDrawingInterface *>(this);
153  }
155 
156  ArrayOfConstObjects GetChildObjects() const;
157 
158 private:
159  //
160 public:
161  std::string m_className;
162  const Object *m_object;
163 
164 private:
165  //
166 #endif /* NO_EDIT_SUPPORT */
167 };
168 
169 } // namespace vrv
170 
171 #endif
This class is a hold the data and corresponds to the model of a MVC design pattern.
Definition: doc.h:41
Definition: editortoolkit.h:28
Definition: editortoolkit_shared.h:32
bool ParseEditorAction(const std::string &json_editorAction) override
In child classes, this parses the provided editor action and then performs the correct action.
Definition: editortoolkit_shared.h:36
bool Chain(jsonxx::Array actions)
Parse JSON instructions for experimental editor functions.
bool Delete(std::string &elementId)
Experimental editor functions.
This class stores an alignment position elements will point to.
Definition: editortoolkit_shared.h:121
bool IsSupportedChild(ClassId classId) override
Base method for checking if a child can be added.
Definition: editortoolkit_shared.h:139
This class represents a basic object.
Definition: object.h:64
This class is a drawing context and corresponds to the view of a MVC design pattern.
Definition: view.h:107
This class is an interface for MEI element that can be hidden during drawing.
Definition: drawinginterface.h:448