Verovio
Source code documentation
editortoolkit.h
1 // Name: editortoolkit.h
3 // Author: Laurent Pugin, Juliette Regimbal
4 // Created: 16/05/2018
5 // Copyright (c) Authors and others. All rights reserved.
7 
8 #ifndef __VRV_EDITOR_TOOLKIT_H__
9 #define __VRV_EDITOR_TOOLKIT_H__
10 
11 #include <cmath>
12 #include <string>
13 #include <utility>
14 
15 //--------------------------------------------------------------------------------
16 
17 #include "doc.h"
18 #include "view.h"
19 
20 #include "jsonxx.h"
21 
22 namespace vrv {
23 
24 class Cursor;
25 
26 //--------------------------------------------------------------------------------
27 // EditorToolkit
28 //--------------------------------------------------------------------------------
29 
31 public:
32  EditorToolkit(Doc *doc, View *view)
33  {
34  m_doc = doc;
35  m_view = view;
36  m_editStatus.reset();
37 
38  m_selectionId = "";
39  m_selectionClassId = UNSPECIFIED;
40  m_selectionSecondaryId = "";
41  m_cursor = NULL;
42 
43  m_options = 0;
44  }
45  virtual ~EditorToolkit() {}
46 
50  virtual bool ParseEditorAction(const std::string &json_editorAction) = 0;
54  virtual std::string EditStatus() { return m_editStatus.json(); }
58  virtual std::string EditResponse() { return m_editResponse.json(); }
59 
63  void OptionsChanged() { m_options++; }
64 
65 #ifndef NO_EDIT_SUPPORT
66 protected:
67  void ResetSelect();
68  bool AppendChild(std::string &elementId, const std::string &elementName, bool unique);
69  bool InsertBefore(std::string &elementId, const std::string &elementName);
70  bool InsertAfter(std::string &elementId, const std::string &elementName);
71  Object *GetElement(const std::string &elementId);
72  Object *PrepareInsertion(Object *parent, const std::string &elementName);
73  Object *ResolveElement(std::string &elementId, bool chain = true);
74  bool InsertMode() const { return (m_cursor); }
75 #endif
76 
77 protected:
78  std::string m_chainedId;
79  std::string m_selectionId;
80  ClassId m_selectionClassId;
81  std::string m_selectionSecondaryId;
82  Cursor *m_cursor;
83 
84  Doc *m_doc;
85  View *m_view;
86  jsonxx::Object m_editStatus;
87  jsonxx::Object m_editResponse;
88 
90  int m_options;
91 };
92 } // namespace vrv
93 
94 #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:30
int m_options
Record option changes
Definition: editortoolkit.h:90
virtual std::string EditResponse()
Get response on the last editor function used.
Definition: editortoolkit.h:58
virtual bool ParseEditorAction(const std::string &json_editorAction)=0
In child classes, this parses the provided editor action and then performs the correct action.
virtual std::string EditStatus()
Get status of the editor (undo, selection, etc.)
Definition: editortoolkit.h:54
void OptionsChanged()
Increase the option change count.
Definition: editortoolkit.h:63
This class represents a basic object.
Definition: object.h:66
This class is a drawing context and corresponds to the view of a MVC design pattern.
Definition: view.h:109