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);
28SCORE_LIB_BASE_EXPORT Document* try_documentFromObject(const QObject& obj) noexcept;
29SCORE_LIB_BASE_EXPORT const DocumentContext& documentContext(const QObject& obj);
30
40SCORE_LIB_BASE_EXPORT ObjectPath unsafe_path(QObject const* const& obj);
41SCORE_LIB_BASE_EXPORT ObjectPath unsafe_path(const QObject& obj);
42
45SCORE_LIB_BASE_EXPORT QString copyOrigin(const Document& doc);
46
48
49// Presenter of a document plugin.
50SCORE_LIB_BASE_EXPORT DocumentDelegatePresenter*
51presenterDelegate_generic(const Document& d);
52
53template <typename T>
54T* presenterDelegate(const Document& d)
55{
56 auto pd = presenterDelegate_generic(d);
57 if(pd)
58 return safe_cast<T*>(pd);
59 return nullptr;
60}
61
62template <typename T>
63 requires(std::is_base_of<DocumentDelegatePresenter, T>::value)
64T* get(const Document& d)
65{
66 return presenterDelegate<T>(d);
67}
68
69template <typename T>
70T* try_presenterDelegate(const Document& d)
71{
72 return dynamic_cast<T*>(presenterDelegate_generic(d));
73}
74
75template <typename T>
76 requires(std::is_base_of<DocumentDelegatePresenter, T>::value)
77T* try_get(const Document& d)
78{
79 return try_presenterDelegate<T>(d);
80}
81
82// Model of a document plugin
83// First if we are sure
84SCORE_LIB_BASE_EXPORT DocumentDelegateModel& modelDelegate_generic(const Document& d);
85
86template <typename T>
87T& modelDelegate(const Document& d)
88{
89 return safe_cast<T&>(modelDelegate_generic(d));
90}
91
92template <typename T>
93 requires(std::is_base_of<DocumentDelegateModel, T>::value)
94T& get(const Document& d)
95{
96 return modelDelegate<T>(d);
97}
98
99// And then if we are not
100
101template <typename T>
102T* try_modelDelegate(const Document& d)
103{
104 return dynamic_cast<T*>(&modelDelegate_generic(d));
105}
106
107template <typename T>
108 requires(std::is_base_of<DocumentDelegateModel, T>::value)
109T* try_get(const Document& d)
110{
111 return try_modelDelegate<T>(d);
112}
113}
114}
The ObjectPath class.
Definition ObjectPath.hpp:37
Base toolkit upon which the software is built.
Definition Application.cpp:108