DocumentInterface.hpp
1 #pragma once
2 #include <score/model/path/ObjectPath.hpp>
3 
4 #include <type_traits>
5 #include <vector>
6 
7 class QObject;
8 namespace score
9 {
10 class CommandStack;
11 class Document;
12 class DocumentDelegateModel;
13 class DocumentDelegatePresenter;
14 struct DocumentContext;
15 
16 namespace IDocument
17 {
18 
25 SCORE_LIB_BASE_EXPORT Document* documentFromObject(const QObject* obj);
26 SCORE_LIB_BASE_EXPORT Document* documentFromObject(const QObject& obj);
27 SCORE_LIB_BASE_EXPORT const DocumentContext& documentContext(const QObject& obj);
28 
38 SCORE_LIB_BASE_EXPORT ObjectPath unsafe_path(QObject const* const& obj);
39 SCORE_LIB_BASE_EXPORT ObjectPath unsafe_path(const QObject& obj);
40 
42 
43 // Presenter of a document plugin.
44 SCORE_LIB_BASE_EXPORT DocumentDelegatePresenter*
45 presenterDelegate_generic(const Document& d);
46 
47 template <typename T>
48 T* presenterDelegate(const Document& d)
49 {
50  auto pd = presenterDelegate_generic(d);
51  if(pd)
52  return safe_cast<T*>(pd);
53  return nullptr;
54 }
55 
56 template <typename T>
57  requires(std::is_base_of<DocumentDelegatePresenter, T>::value)
58 T* get(const Document& d)
59 {
60  return presenterDelegate<T>(d);
61 }
62 
63 template <typename T>
64 T* try_presenterDelegate(const Document& d)
65 {
66  return dynamic_cast<T*>(presenterDelegate_generic(d));
67 }
68 
69 template <typename T>
70  requires(std::is_base_of<DocumentDelegatePresenter, T>::value)
71 T* try_get(const Document& d)
72 {
73  return try_presenterDelegate<T>(d);
74 }
75 
76 // Model of a document plugin
77 // First if we are sure
78 SCORE_LIB_BASE_EXPORT DocumentDelegateModel& modelDelegate_generic(const Document& d);
79 
80 template <typename T>
81 T& modelDelegate(const Document& d)
82 {
83  return safe_cast<T&>(modelDelegate_generic(d));
84 }
85 
86 template <typename T>
87  requires(std::is_base_of<DocumentDelegateModel, T>::value)
88 T& get(const Document& d)
89 {
90  return modelDelegate<T>(d);
91 }
92 
93 // And then if we are not
94 
95 template <typename T>
96 T* try_modelDelegate(const Document& d)
97 {
98  return dynamic_cast<T*>(&modelDelegate_generic(d));
99 }
100 
101 template <typename T>
102  requires(std::is_base_of<DocumentDelegateModel, T>::value)
103 T* try_get(const Document& d)
104 {
105  return try_modelDelegate<T>(d);
106 }
107 }
108 }
The ObjectPath class.
Definition: ObjectPath.hpp:37
Base toolkit upon which the software is built.
Definition: Application.cpp:90