Loading...
Searching...
No Matches
DocumentInterface.hpp
1#pragma once
2#include <score/model/path/ObjectPath.hpp>
3
4#include <type_traits>
5#include <vector>
6
7class QObject;
8namespace score
9{
10class CommandStack;
11class Document;
12class DocumentDelegateModel;
13class DocumentDelegatePresenter;
14struct DocumentContext;
15
16namespace IDocument
17{
18
25SCORE_LIB_BASE_EXPORT Document* documentFromObject(const QObject* obj);
26SCORE_LIB_BASE_EXPORT Document* documentFromObject(const QObject& obj);
27SCORE_LIB_BASE_EXPORT const DocumentContext& documentContext(const QObject& obj);
28
38SCORE_LIB_BASE_EXPORT ObjectPath unsafe_path(QObject const* const& obj);
39SCORE_LIB_BASE_EXPORT ObjectPath unsafe_path(const QObject& obj);
40
42
43// Presenter of a document plugin.
44SCORE_LIB_BASE_EXPORT DocumentDelegatePresenter*
45presenterDelegate_generic(const Document& d);
46
47template <typename T>
48T* 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
56template <typename T>
57 requires(std::is_base_of<DocumentDelegatePresenter, T>::value)
58T* get(const Document& d)
59{
60 return presenterDelegate<T>(d);
61}
62
63template <typename T>
64T* try_presenterDelegate(const Document& d)
65{
66 return dynamic_cast<T*>(presenterDelegate_generic(d));
67}
68
69template <typename T>
70 requires(std::is_base_of<DocumentDelegatePresenter, T>::value)
71T* 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
78SCORE_LIB_BASE_EXPORT DocumentDelegateModel& modelDelegate_generic(const Document& d);
79
80template <typename T>
81T& modelDelegate(const Document& d)
82{
83 return safe_cast<T&>(modelDelegate_generic(d));
84}
85
86template <typename T>
87 requires(std::is_base_of<DocumentDelegateModel, T>::value)
88T& get(const Document& d)
89{
90 return modelDelegate<T>(d);
91}
92
93// And then if we are not
94
95template <typename T>
96T* try_modelDelegate(const Document& d)
97{
98 return dynamic_cast<T*>(&modelDelegate_generic(d));
99}
100
101template <typename T>
102 requires(std::is_base_of<DocumentDelegateModel, T>::value)
103T* 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