Loading...
Searching...
No Matches
DocumentManager.hpp
1#pragma once
2#include <score/tools/Version.hpp>
3
4#include <core/document/DocumentBuilder.hpp>
5
6#include <ossia/detail/json_fwd.hpp>
7
8#include <QObject>
9#include <QString>
10
11#include <score_lib_base_export.h>
12
13#include <functional>
14#include <vector>
15#include <verdigris>
16class QRecentFilesMenu;
17namespace score
18{
19class Document;
20struct ApplicationContext;
21class View;
22struct RestorableDocument;
23} // namespace score
24
25namespace score
26{
27
29{
30public:
31 const std::vector<Document*>& documents() const { return m_documents; }
32
33 std::vector<Document*>& documents() { return m_documents; }
34
35 Document* currentDocument() const { return m_currentDocument; }
36
37 void setCurrentDocument(Document* d) { m_currentDocument = d; }
38
39protected:
40 std::vector<Document*> m_documents;
41 Document* m_currentDocument{};
42};
43
47class SCORE_LIB_BASE_EXPORT DocumentManager
48 : public QObject
49 , public DocumentList
50{
51 W_OBJECT(DocumentManager)
52public:
53 DocumentManager(score::View* view, QObject* parentPresenter);
54
55 void init(const score::GUIApplicationContext& ctx);
56
58
59 auto recentFiles() const { return m_recentFiles; }
60
61 // Document management
62 Document* setupDocument(const score::GUIApplicationContext& ctx, score::Document* doc);
63
64 template <typename... Args>
65 Document* newDocument(const score::GUIApplicationContext& ctx, Args&&... args)
66 {
67 prepareNewDocument(ctx);
68 return setupDocument(ctx, m_builder.newDocument(ctx, std::forward<Args>(args)...));
69 }
70
72 Document* newDocumentFromTemplate(
73 const score::GUIApplicationContext& ctx, const QString& templatePath);
74
75 template <typename... Args>
76 Document* loadDocument(const score::GUIApplicationContext& ctx, Args&&... args)
77 {
78 closeVirginDocument(ctx);
79 prepareNewDocument(ctx);
80 return setupDocument(ctx, m_builder.loadDocument(ctx, std::forward<Args>(args)...));
81 }
82
83 template <typename... Args>
84 void restoreDocument(const score::GUIApplicationContext& ctx, Args&&... args)
85 {
86 prepareNewDocument(ctx);
87 setupDocument(ctx, m_builder.restoreDocument(ctx, std::forward<Args>(args)...));
88 }
89
90 // Restore documents after a crash
91 void restoreDocuments(const score::GUIApplicationContext& ctx);
92
93 void setCurrentDocument(const score::GUIApplicationContext& ctx, Document* doc);
94
95 // Returns true if the document was closed.
96 bool closeDocument(const score::GUIApplicationContext& ctx, Document&);
97 void forceCloseDocument(const score::GUIApplicationContext& ctx, Document&);
98
99 // Methods to save and load
100 bool saveDocument(Document&);
101 bool saveDocumentAs(Document&);
102 bool saveDocumentAs(Document&, const QString& path);
103
104 bool saveStack();
105 Document* loadStack(const score::GUIApplicationContext& ctx);
106 Document* loadStack(const score::GUIApplicationContext& ctx, const QString&);
107
113 Document* loadFile(
115 std::function<void(Document*)> onDone = {});
116 Document* loadFile(const score::GUIApplicationContext& ctx, const QString& filename);
117
124 Document* openArchive(const score::GUIApplicationContext& ctx, const QString& archive);
125
126 bool closeAllDocuments(const score::GUIApplicationContext& ctx);
127
128 bool preparingNewDocument() const;
129
134 static bool
135 checkAndUpdateJson(rapidjson::Value&, const score::GUIApplicationContext& ctx);
136
137public:
138 void documentChanged(score::Document* arg_1)
139 E_SIGNAL(SCORE_LIB_BASE_EXPORT, documentChanged, arg_1)
140
141private:
142 void closeVirginDocument(const score::GUIApplicationContext& ctx);
143 void prepareNewDocument(const score::GUIApplicationContext& ctx);
144
145 static bool updateJson(
146 rapidjson::Value& object, score::Version json_ver, score::Version score_ver);
147
148 void saveRecentFilesState();
149
150 score::View* m_view{};
151
152 DocumentBuilder m_builder;
153
154 QPointer<QRecentFilesMenu> m_recentFiles{};
155
156 bool m_preparingNewDocument{};
157};
158
159SCORE_LIB_BASE_EXPORT
160Id<score::DocumentModel> getStrongId(const std::vector<score::Document*>& v);
161
162}
The id_base_t class.
Definition Identifier.hpp:59
Methods to set-up documents.
Definition DocumentBuilder.hpp:27
The Document class is the central part of the software.
Definition Document.hpp:51
Owns the documents.
Definition DocumentManager.hpp:50
Represents the version of a plug-in.
Definition Version.hpp:13
The main display of the application.
Definition lib/core/view/Window.hpp:41
Base toolkit upon which the software is built.
Definition Application.cpp:108
Definition DocumentManager.hpp:29
Specializes ApplicationContext with the QMainWindow.
Definition GUIApplicationContext.hpp:15