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  std::string EditInfo() override;
42 
43 protected:
44 #ifndef NO_EDIT_SUPPORT
49  bool Chain(jsonxx::Array actions);
50  bool ParseContextAction(jsonxx::Object param, std::string &elementId, bool &scores, bool &sections);
51  bool ParseDeleteAction(jsonxx::Object param, std::string &elementId);
52  bool ParseDragAction(jsonxx::Object param, std::string &elementId, int &x, int &y);
53  bool ParseKeyDownAction(jsonxx::Object param, std::string &elementid, int &key, bool &shiftKey, bool &ctrlKey);
54  bool ParseInsertAction(
55  jsonxx::Object param, std::string &elementName, std::string &elementId, std::string &insertMode);
56  bool ParseSetAction(jsonxx::Object param, std::string &elementId, std::string &attribute, std::string &value);
58 
59  void SetEditInfo();
60  void PrepareUndo();
61  std::string GetCurrentState();
62  bool ReloadState(const std::string &data);
63  void TrimUndoMemory();
64  bool CanUndo() const;
65  bool CanRedo() const;
66  bool Undo();
67  bool Redo();
68 
73  bool Delete(std::string &elementId);
74  bool Drag(std::string &elementId, int x, int y);
75  bool KeyDown(std::string &elementId, int key, bool shiftKey, bool ctrlKey);
76  bool Set(std::string &elementId, std::string const &attribute, std::string const &value);
78 
79  void ClearContext();
80  bool ContextForElement(std::string &elementId);
81  bool ContextForScores(bool editInfo);
82  bool ContextForSections(bool editInfo);
83 
84  Object *GetChainedElement(std::string &elementId);
85 
86  void ContextForObject(const Object *object, jsonxx::Object &element, bool recursive = false);
87  void ContextForObjects(const ArrayOfConstObjects &objects, jsonxx::Array &siblings);
88  void ContextForReferences(const ListOfObjectAttNamePairs &objects, jsonxx::Array &links);
89 
90  ArrayOfConstObjects GetScoreBasedChildrenFor(const Object *object);
91 
92 public:
93  //
94 protected:
95  std::string m_chainedId;
96 
97  bool m_undoPrepared;
98  std::deque<std::string> m_undoStack;
99  std::deque<std::string> m_redoStack;
100  size_t m_undoMemoryUsage = 0;
101 
102  EditorTreeObject *m_scoreContext;
103  EditorTreeObject *m_sectionContext;
104  EditorTreeObject *m_currentContext;
105 };
106 
107 //----------------------------------------------------------------------------
108 // EditorTreeObject
109 //----------------------------------------------------------------------------
110 
115 
116 public:
122  EditorTreeObject(const Object *object, bool ownChildren);
123  virtual ~EditorTreeObject() {};
124  void Reset() override;
125  std::string GetClassName() const override { return m_className; }
127 
132  bool IsSupportedChild(ClassId classId) override { return true; }
134 
139  VisibilityDrawingInterface *GetVisibilityDrawingInterface() override
140  {
141  return vrv_cast<VisibilityDrawingInterface *>(this);
142  }
143  const VisibilityDrawingInterface *GetVisibilityDrawingInterface() const override
144  {
145  return vrv_cast<const VisibilityDrawingInterface *>(this);
146  }
148 
149  ArrayOfConstObjects GetChildObjects() const;
150 
151 private:
152  //
153 public:
154  std::string m_className;
155  const Object *m_object;
156 
157 private:
158  //
159 #endif /* NO_EDIT_SUPPORT */
160 };
161 
162 } // namespace vrv
163 
164 #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.
std::string EditInfo() override
Get information on the last editor function used.
bool Delete(std::string &elementId)
Experimental editor functions.
This class stores an alignment position elements will point to.
Definition: editortoolkit_shared.h:114
bool IsSupportedChild(ClassId classId) override
Base method for checking if a child can be added.
Definition: editortoolkit_shared.h:132
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