Verovio
Source code documentation
editortoolkit_cmn.h
1 // Name: editortoolkit_cmn.h
3 // Author: Juliette Regimbal
4 // Created: 04/06/2019
5 // Copyright (c) Authors and others. All rights reserved.
7 
8 #ifndef __VRV_EDITOR_TOOLKIT_CMN_H__
9 #define __VRV_EDITOR_TOOLKIT_CMN_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 // EditorToolkitCMN
30 //--------------------------------------------------------------------------------
31 
33 public:
34  EditorToolkitCMN(Doc *doc, View *view);
35  virtual ~EditorToolkitCMN();
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(jsonxx::Object param, std::string &elementType, std::string &startid, std::string &endid);
55  bool ParseSetAction(jsonxx::Object param, std::string &elementId, std::string &attribute, std::string &value);
57 
58  void PrepareUndo();
59  std::string GetCurrentState();
60  bool ReloadState(const std::string &data);
61  void TrimUndoMemory();
62  bool CanUndo() const;
63  bool CanRedo() const;
64  bool Undo();
65  bool Redo();
66 
71  bool Delete(std::string &elementId);
72  bool Drag(std::string &elementId, int x, int y);
73  bool KeyDown(std::string &elementId, int key, bool shiftKey, bool ctrlKey);
74  bool Insert(std::string &elementType, std::string const &startid, std::string const &endid);
75  bool Insert(std::string &elementType, std::string const &startid);
76  bool Set(std::string &elementId, std::string const &attribute, std::string const &value);
78 
79  bool InsertNote(Object *object);
80 
81  bool DeleteNote(Note *note);
82 
83  void ClearContext();
84  bool ContextForElement(std::string &elementId);
85  bool ContextForScores(bool editInfo);
86  bool ContextForSections(bool editInfo);
87 
88  Object *GetElement(std::string &elementId);
89 
90  void ContextForObject(const Object *object, jsonxx::Object &element, bool recursive = false);
91  void ContextForObjects(const ArrayOfConstObjects &objects, jsonxx::Array &siblings);
92  void ContextForReferences(const ListOfObjectAttNamePairs &objects, jsonxx::Array &links);
93 
94  ArrayOfConstObjects GetScoreBasedChildrenFor(const Object *object);
95 
96 public:
97  //
98 protected:
99  std::string m_chainedId;
100 
101  bool m_undoPrepared;
102  std::deque<std::string> m_undoStack;
103  std::deque<std::string> m_redoStack;
104  size_t m_undoMemoryUsage = 0;
105 
106  EditorTreeObject *m_scoreContext;
107  EditorTreeObject *m_sectionContext;
108  EditorTreeObject *m_currentContext;
109 };
110 
111 //----------------------------------------------------------------------------
112 // EditorTreeObject
113 //----------------------------------------------------------------------------
114 
119 
120 public:
126  EditorTreeObject(const Object *object, bool ownChildren);
127  virtual ~EditorTreeObject() {};
128  void Reset() override;
129  std::string GetClassName() const override { return m_className; }
131 
136  bool IsSupportedChild(ClassId classId) override { return true; }
138 
143  VisibilityDrawingInterface *GetVisibilityDrawingInterface() override
144  {
145  return vrv_cast<VisibilityDrawingInterface *>(this);
146  }
147  const VisibilityDrawingInterface *GetVisibilityDrawingInterface() const override
148  {
149  return vrv_cast<const VisibilityDrawingInterface *>(this);
150  }
152 
153  ArrayOfConstObjects GetChildObjects() const;
154 
155 private:
156  //
157 public:
158  std::string m_className;
159  const Object *m_object;
160 
161 private:
162  //
163 #endif /* NO_EDIT_SUPPORT */
164 };
165 
166 } // namespace vrv
167 
168 #endif
This class is a hold the data and corresponds to the model of a MVC design pattern.
Definition: doc.h:41
Definition: editortoolkit_cmn.h:32
bool Delete(std::string &elementId)
Experimental editor functions.
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 ParseEditorAction(const std::string &json_editorAction) override
In child classes, this parses the provided editor action and then performs the correct action.
Definition: editortoolkit_cmn.h:36
Definition: editortoolkit.h:28
This class stores an alignment position elements will point to.
Definition: editortoolkit_cmn.h:118
bool IsSupportedChild(ClassId classId) override
Base method for checking if a child can be added.
Definition: editortoolkit_cmn.h:136
This class models the MEI <note> element.
Definition: note.h:67
This class represents a basic object.
Definition: object.h:62
This class is a drawing context and corresponds to the view of a MVC design pattern.
Definition: view.h:106
This class is an interface for MEI element that can be hidden during drawing.
Definition: drawinginterface.h:422