ACF $AcfVersion:0$
CMultiDocumentManagerBase.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/QList>
7
8// ACF includes
10#include <istd/TDelPtr.h>
12#include <idoc/IUndoManager.h>
15#include <iser/IArchive.h>
16
17
18namespace idoc
19{
20
21
26{
27public:
33
38
39 // reimplemented (idoc::IDocumentManager)
40 virtual idoc::IUndoManager* GetUndoManagerForDocument(const istd::IChangeable* documentPtr) const override;
41 virtual int GetDocumentsCount() const override;
42 virtual istd::IChangeable& GetDocumentFromIndex(int index, DocumentInfo* documentInfoPtr = NULL) const override;
43 virtual int GetViewsCount(int documentIndex) const override;
44 virtual istd::IPolymorphic* GetViewFromIndex(int documentIndex, int viewIndex) const override;
45 virtual istd::IPolymorphic* GetActiveView() const override;
46 virtual void SetActiveView(istd::IPolymorphic* viewPtr) override;
47 virtual istd::IChangeable* GetDocumentFromView(const istd::IPolymorphic& view, DocumentInfo* documentInfoPtr = NULL) const override;
48 virtual istd::IPolymorphic* AddViewToDocument(const istd::IChangeable& document, const QByteArray& viewTypeId = QByteArray()) override;
49 virtual QByteArray GetDocumentTypeId(const istd::IChangeable& document) const override;
50 virtual bool InsertNewDocument(
51 const QByteArray& documentTypeId,
52 bool createView = true,
53 const QByteArray& viewTypeId = "",
54 istd::IChangeableSharedPtr* newDocumentPtr = nullptr,
55 bool beQuiet = false,
56 bool* ignoredPtr = NULL) override;
57 virtual bool OpenDocument(
58 const QByteArray* documentTypeIdPtr,
59 const QString* fileNamePtr = NULL,
60 bool createView = true,
61 const QByteArray& viewTypeId = "",
62 istd::IChangeableSharedPtr* documentPtr = nullptr,
63 FileToTypeMap* loadedMapPtr = NULL,
64 bool beQuiet = false,
65 bool* ignoredPtr = NULL,
66 ibase::IProgressManager* progressManagerPtr = NULL) override;
67 virtual bool SaveDocument(
68 int documentIndex = -1,
69 bool requestFileName = false,
70 FileToTypeMap* savedMapPtr = NULL,
71 bool beQuiet = false,
72 bool* ignoredPtr = NULL,
73 ibase::IProgressManager* progressManagerPtr = NULL) override;
74 virtual bool SaveDirtyDocuments(bool beQuiet = false, bool* ignoredPtr = NULL) override;
75 virtual bool CloseDocument(int documentIndex = -1, bool beQuiet = false, bool* ignoredPtr = NULL) override;
76 virtual bool CloseView(istd::IPolymorphic* viewPtr = NULL, bool beQuiet = false, bool* ignoredPtr = NULL) override;
77
78protected:
82 struct ViewInfo
83 {
85 QByteArray viewTypeId;
86 };
87 typedef QList<ViewInfo> Views;
88
89
93 struct SingleDocumentData: public DocumentInfo, public imod::CMultiModelDispatcherBase
94 {
97 const QByteArray& documentTypeId,
99
101
106
107 protected:
108 // reimplemented (imod::CMultiModelDispatcherBase)
109 virtual void OnModelChanged(int modelId, const istd::IChangeable::ChangeSet& changeSet) override;
110 };
111
121 const QString& filePath,
122 bool createView,
123 const QByteArray& viewTypeId,
124 QByteArray& documentTypeId,
125 bool beQuiet,
126 bool* ignoredPtr,
127 ibase::IProgressManager* progressManagerPtr);
128
129 virtual void CloseAllDocuments();
130
135
140
145
149 SingleDocumentData* GetDocumentInfoFromPath(const QString& filePath) const;
150
154 int GetDocumentIndex(const SingleDocumentData& document) const;
155
160 const QByteArray& documentTypeId,
161 bool createView,
162 const QByteArray& viewTypeId,
163 bool initialize,
164 bool beQuiet,
165 bool* ignoredPtr) const;
166
171
172 // abstract methods
173
177 virtual void OnViewRegistered(istd::IPolymorphic* viewPtr, const SingleDocumentData& documentData) = 0;
178
182 virtual void OnViewRemoved(istd::IPolymorphic* viewPtr) = 0;
183
187 virtual QStringList GetOpenFilePaths(const QByteArray* documentTypeIdPtr = NULL) const = 0;
188
192 virtual QString GetSaveFilePath(const QByteArray& documentTypeId, const istd::IChangeable* dataObjectPtr, const QString& currentFilePath) const = 0;
193
199 virtual bool QueryDocumentSave(const SingleDocumentData& info, bool* ignoredPtr) = 0;
200
205
209 virtual void OnDocumentSaved();
210
211protected:
213
215
217};
218
219
220} // namespace idoc
221
222
Consume information about progress of some process.
Basic implementation of a template-based multiple document manager.
virtual istd::IChangeableSharedPtr 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.
SingleDocumentData * GetDocumentInfoFromPath(const QString &filePath) const
Get document info assigned to specified file.
virtual bool CloseDocument(int documentIndex=-1, bool beQuiet=false, bool *ignoredPtr=NULL) override
Close document and all its views.
virtual void SetActiveView(istd::IPolymorphic *viewPtr) override
Indicate that some view is active now.
virtual QByteArray GetDocumentTypeId(const istd::IChangeable &document) const override
Get ID of document type managed by this object.
virtual idoc::IUndoManager * GetUndoManagerForDocument(const istd::IChangeable *documentPtr) const override
Return undo manager for document documentPtr.
virtual void OnViewRemoved(istd::IPolymorphic *viewPtr)=0
Called before view is removed.
bool SerializeOpenDocumentList(iser::IArchive &archive)
Serializes open documents information.
idoc::IDocumentTemplate::ViewSharedPtr ViewPtr
bool RegisterDocument(SingleDocumentData *documentPtr)
Register (attach) created document as new working document.
virtual SingleDocumentData * CreateUnregisteredDocument(const QByteArray &documentTypeId, bool createView, const QByteArray &viewTypeId, bool initialize, bool beQuiet, bool *ignoredPtr) const
Create instance of specified document without attaching to this manager.
SingleDocumentData * GetActiveDocumentInfo() const
Get document info assigned to active view.
virtual bool CloseView(istd::IPolymorphic *viewPtr=NULL, bool beQuiet=false, bool *ignoredPtr=NULL) override
Close view.
virtual istd::IPolymorphic * GetViewFromIndex(int documentIndex, int viewIndex) const override
Get single view using its and document indices.
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 istd::IPolymorphic * AddViewToDocument(const istd::IChangeable &document, const QByteArray &viewTypeId=QByteArray()) override
Add a new view to the document.
virtual bool QueryDocumentSave(const SingleDocumentData &info, bool *ignoredPtr)=0
Query user if this document should be saved.
virtual istd::IChangeable & GetDocumentFromIndex(int index, DocumentInfo *documentInfoPtr=NULL) const override
Get document at specified index.
virtual int GetViewsCount(int documentIndex) const override
Get number of view for specified document.
virtual void OnViewRegistered(istd::IPolymorphic *viewPtr, const SingleDocumentData &documentData)=0
Called after view is registered.
virtual bool SaveDirtyDocuments(bool beQuiet=false, bool *ignoredPtr=NULL) override
Ask user (optional) and save all dirty (changed) documents.
istd::TPointerVector< SingleDocumentData > DocumentInfos
virtual istd::IPolymorphic * GetActiveView() const override
Return the active document.
SingleDocumentData * GetDocumentInfoFromView(const istd::IPolymorphic &view) const
Get document info assigned to specified view.
virtual istd::IChangeable * GetDocumentFromView(const istd::IPolymorphic &view, DocumentInfo *documentInfoPtr=NULL) const override
Return the document assigned to view.
virtual QStringList GetOpenFilePaths(const QByteArray *documentTypeIdPtr=NULL) const =0
Gets open file names.
int GetDocumentIndex(const SingleDocumentData &document) const
Get position index of the given document in the document list.
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.
idoc::IUndoManagerSharedPtr UndoManagerPtr
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 void OnDocumentSaved()
Execute after document saved.
virtual QString GetSaveFilePath(const QByteArray &documentTypeId, const istd::IChangeable *dataObjectPtr, const QString &currentFilePath) const =0
Gets save file name.
SingleDocumentData & GetSingleDocumentData(int index) const
Get internal document data object.
CMultiDocumentManagerBase()
Default constructor.
virtual int GetDocumentsCount() const override
Get number of opened documents.
Base implementation of document manager.
QMap< QString, QByteArray > FileToTypeMap
Map from file path to document type ID's.
Interface providing UNDO/REDO functionality.
Generic implementation of a data model changes notifier.
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.
Implementation of a pointer container, which controls the live cycle of the pointer object.
#define NULL
Definition istd.h:74
Contains the system independent basic implementations of Document/View design pattern.
SingleDocumentData(CMultiDocumentManagerBase *parentPtr, const QByteArray &documentTypeId, DocumentPtr &documentPtr)
virtual void OnModelChanged(int modelId, const istd::IChangeable::ChangeSet &changeSet) override
Called when some model observed by dispatcher will be changed.
Information about a document managed by the document manager.