ACF $AcfVersion:0$
CSingleDocumentManagerBase.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later OR GPL-2.0-or-later OR GPL-3.0-or-later OR LicenseRef-ACF-Commercial
2#pragma once
3
4
5// Qt includes
6#include <QtCore/QByteArray>
7#include <QtCore/QString>
8
9// ACF includes
10#include <istd/TDelPtr.h>
11#include <iser/IArchive.h>
15
16
17namespace idoc
18{
19
20
27{
28public:
30
31 // reimplemented (idoc::IDocumentManager)
32 virtual idoc::IUndoManager* GetUndoManagerForDocument(const istd::IChangeable* documentPtr) const override;
33 virtual int GetDocumentsCount() const override;
34 virtual istd::IChangeable& GetDocumentFromIndex(int index, DocumentInfo* documentInfoPtr = NULL) const override;
35 virtual int GetViewsCount(int documentIndex) const override;
36 virtual istd::IPolymorphic* GetViewFromIndex(int documentIndex, int viewIndex) const override;
37 virtual istd::IPolymorphic* GetActiveView() const override;
38 virtual istd::IChangeable* GetDocumentFromView(const istd::IPolymorphic& view, DocumentInfo* documentInfoPtr = NULL) const override;
39 virtual istd::IPolymorphic* AddViewToDocument(const istd::IChangeable& document, const QByteArray& viewTypeId = QByteArray()) override;
40 virtual QByteArray GetDocumentTypeId(const istd::IChangeable& document) const override;
41 virtual bool InsertNewDocument(
42 const QByteArray& documentTypeId,
43 bool createView = true,
44 const QByteArray& viewTypeId = "",
45 istd::IChangeableSharedPtr* newDocumentPtr = nullptr,
46 bool beQuiet = false,
47 bool* ignoredPtr = NULL) override;
48 virtual bool OpenDocument(
49 const QByteArray* documentTypeIdPtr,
50 const QString* fileNamePtr = NULL,
51 bool createView = true,
52 const QByteArray& viewTypeId = "",
53 istd::IChangeableSharedPtr* documentPtr = nullptr,
54 FileToTypeMap* loadedMapPtr = NULL,
55 bool beQuiet = false,
56 bool* ignoredPtr = NULL,
57 ibase::IProgressManager* progressManagerPtr = NULL) override;
58 virtual bool SaveDocument(
59 int documentIndex = -1,
60 bool requestFileName = false,
61 FileToTypeMap* savedMapPtr = NULL,
62 bool beQuiet = false,
63 bool* ignoredPtr = NULL,
64 ibase::IProgressManager* progressManagerPtr = NULL) override;
65 virtual bool SaveDirtyDocuments(bool beQuiet = false, bool* ignoredPtr = NULL) override;
66 virtual bool CloseDocument(int documentIndex = -1, bool beQuiet = false, bool* ignoredPtr = NULL) override;
67 virtual bool CloseView(istd::IPolymorphic* viewPtr = NULL, bool beQuiet = false, bool* ignoredPtr = NULL) override;
68
69protected:
73 virtual void BeforeSavingDocument(const QString& filePath);
74
78 virtual void AfterSavingDocument(bool saveState);
79
88 virtual bool OpenSingleDocument(
89 const QString& filePath,
90 bool createView,
91 const QByteArray& viewTypeId,
92 QByteArray& documentTypeId,
93 bool beQuiet,
94 bool* ignoredPtr,
95 ibase::IProgressManager* progressManagerPtr);
96
101 const QByteArray& documentTypeId,
102 bool createView,
103 const QByteArray& viewTypeId,
104 bool initialize,
105 bool beQuiet,
106 bool* ignoredPtr);
111
113
115
117
119
120 // reimplemented (imod::CSingleModelObserverBase)
121 virtual void OnUpdate(const istd::IChangeable::ChangeSet& changeSet) override;
122
123 // abstract methods
124
128 virtual void OnViewRegistered(istd::IPolymorphic* viewPtr) = 0;
129
133 virtual void OnViewRemoved(istd::IPolymorphic* viewPtr) = 0;
134
138 virtual void OnDocumentRegistered() = 0;
139
143 virtual void OnDocumentClosed() = 0;
144
148 virtual QString GetOpenFilePath(const QByteArray* documentTypeIdPtr = NULL) const = 0;
149
153 virtual QString GetSaveFilePath(const QByteArray& documentTypeId, const istd::IChangeable* dataObjectPtr, const QString& currentFilePath) const = 0;
154
159 virtual bool QueryDocumentSave(bool* ignoredPtr) = 0;
160
165
166private:
167 class UndoManagerObserver: public imod::CSingleModelObserverBase
168 {
169 public:
170 UndoManagerObserver(CSingleDocumentManagerBase& parent);
171
172 protected:
173 // reimplemented (imod::CSingleModelObserverBase)
174 virtual void OnUpdate(const istd::IChangeable::ChangeSet& changeSet) override;
175
176 private:
178 };
179
180private:
181 QString m_filePath;
182 QByteArray m_documentTypeId;
183 QByteArray m_viewTypeId;
184 istd::IChangeableSharedPtr m_documentPtr;
185 idoc::IUndoManagerSharedPtr m_undoManagerPtr;
187 UndoManagerObserver m_undoManagerObserver;
188
189 bool m_isDirty;
190};
191
192
193} // namespace idoc
194
195
Consume information about progress of some process.
Basic implementation of a template-based single document manager.
virtual istd::IPolymorphic * AddViewToDocument(const istd::IChangeable &document, const QByteArray &viewTypeId=QByteArray()) override
Add a new view to the document.
QString GetCurrentDocumentFilePath() const
virtual bool OpenDocument(const QByteArray *documentTypeIdPtr, const QString *fileNamePtr=NULL, bool createView=true, const QByteArray &viewTypeId="", istd::IChangeableSharedPtr *documentPtr=nullptr, FileToTypeMap *loadedMapPtr=NULL, bool beQuiet=false, bool *ignoredPtr=NULL, ibase::IProgressManager *progressManagerPtr=NULL) override
Opens document(s) from the file list.
virtual bool CloseDocument(int documentIndex=-1, bool beQuiet=false, bool *ignoredPtr=NULL) override
Close document and all its views.
virtual void OnViewRemoved(istd::IPolymorphic *viewPtr)=0
Called before view is removed.
virtual QByteArray GetDocumentTypeId(const istd::IChangeable &document) const override
Get ID of document type managed by this object.
virtual void BeforeSavingDocument(const QString &filePath)
Called just before the document is saved via persistence.
virtual bool InsertNewDocument(const QByteArray &documentTypeId, bool createView=true, const QByteArray &viewTypeId="", istd::IChangeableSharedPtr *newDocumentPtr=nullptr, bool beQuiet=false, bool *ignoredPtr=NULL) override
Creates a new document with the document ID documentTypeId.
virtual bool QueryDocumentSave(bool *ignoredPtr)=0
Query user if this document can be closed.
bool NewDocument(const QByteArray &documentTypeId, bool createView, const QByteArray &viewTypeId, bool initialize, bool beQuiet, bool *ignoredPtr)
Create instance of specified document without attaching to this manager.
virtual idoc::IUndoManager * GetUndoManagerForDocument(const istd::IChangeable *documentPtr) const override
Return undo manager for document documentPtr.
virtual bool OpenSingleDocument(const QString &filePath, bool createView, const QByteArray &viewTypeId, QByteArray &documentTypeId, bool beQuiet, bool *ignoredPtr, ibase::IProgressManager *progressManagerPtr)
Open single document using its file path.
virtual void AfterSavingDocument(bool saveState)
Called immediately after saving the document via persistence.
bool RegisterDocument()
Register (attach) created document as new working document.
bool SerializeOpenDocument(iser::IArchive &archive)
Serializes open documents information.
virtual istd::IPolymorphic * GetActiveView() const override
Return the active document.
virtual void OnViewRegistered(istd::IPolymorphic *viewPtr)=0
Called after view is registered.
virtual istd::IPolymorphic * GetViewFromIndex(int documentIndex, int viewIndex) const override
Get single view using its and document indices.
virtual void OnDocumentRegistered()=0
Called after document is registered.
virtual int GetViewsCount(int documentIndex) const override
Get number of view for specified document.
void OnUndoManagerUpdate(const istd::IChangeable::ChangeSet &changeSet)
virtual QString GetOpenFilePath(const QByteArray *documentTypeIdPtr=NULL) const =0
Gets open file names.
virtual bool CloseView(istd::IPolymorphic *viewPtr=NULL, bool beQuiet=false, bool *ignoredPtr=NULL) override
Close view.
virtual istd::IChangeable & GetDocumentFromIndex(int index, DocumentInfo *documentInfoPtr=NULL) const override
Get document at specified index.
virtual int GetDocumentsCount() const override
Get number of opened documents.
virtual bool SaveDocument(int documentIndex=-1, bool requestFileName=false, FileToTypeMap *savedMapPtr=NULL, bool beQuiet=false, bool *ignoredPtr=NULL, ibase::IProgressManager *progressManagerPtr=NULL) override
Save document.
virtual istd::IChangeable * GetDocumentFromView(const istd::IPolymorphic &view, DocumentInfo *documentInfoPtr=NULL) const override
Return the document assigned to view.
virtual QString GetSaveFilePath(const QByteArray &documentTypeId, const istd::IChangeable *dataObjectPtr, const QString &currentFilePath) const =0
Gets save file name.
virtual bool SaveDirtyDocuments(bool beQuiet=false, bool *ignoredPtr=NULL) override
Ask user (optional) and save all dirty (changed) documents.
virtual void OnDocumentClosed()=0
Called before document is closed.
virtual void OnUpdate(const istd::IChangeable::ChangeSet &changeSet) override
Called on update of observed model.
Base implementation of document manager.
QMap< QString, QByteArray > FileToTypeMap
Map from file path to document type ID's.
Interface providing UNDO/REDO functionality.
Basic implementation for a single model observer.
Represents an input/output persistence archive for object serialization.
Definition IArchive.h:164
Set of change flags (its IDs).
Definition IChangeable.h:36
Common interface for data model objects, which can be changed.
Definition IChangeable.h:28
Base interface for all used interfaces and implementations.
#define NULL
Definition istd.h:74
Contains the system independent basic implementations of Document/View design pattern.
Information about a document managed by the document manager.