CMultiDocumentManagerBase.h
Go to the documentation of this file.
1 #ifndef idoc_CMultiDocumentManagerBase_included
2 #define idoc_CMultiDocumentManagerBase_included
3 
4 
5 // Qt includes
6 #include <QtCore/QList>
7 
8 // ACF includes
9 #include <istd/TPointerVector.h>
10 #include <istd/TDelPtr.h>
12 #include <idoc/IUndoManager.h>
14 #include <iser/IArchive.h>
15 
16 
17 namespace idoc
18 {
19 
20 
25 {
26 public:
27  enum ModelId
28  {
31  };
32 
37 
38  // reimplemented (idoc::IDocumentManager)
39  virtual idoc::IUndoManager* GetUndoManagerForDocument(const istd::IChangeable* documentPtr) const;
40  virtual int GetDocumentsCount() const;
41  virtual istd::IChangeable& GetDocumentFromIndex(int index, DocumentInfo* documentInfoPtr = NULL) const;
42  virtual int GetViewsCount(int documentIndex) const;
43  virtual istd::IPolymorphic* GetViewFromIndex(int documentIndex, int viewIndex) const;
44  virtual istd::IPolymorphic* GetActiveView() const;
45  virtual istd::IChangeable* GetDocumentFromView(const istd::IPolymorphic& view, DocumentInfo* documentInfoPtr = NULL) const;
46  virtual istd::IPolymorphic* AddViewToDocument(const istd::IChangeable& document, const QByteArray& viewTypeId = QByteArray());
47  virtual QByteArray GetDocumentTypeId(const istd::IChangeable& document) const;
48  virtual bool InsertNewDocument(
49  const QByteArray& documentTypeId,
50  bool createView = true,
51  const QByteArray& viewTypeId = "",
52  istd::IChangeable** newDocumentPtr = NULL,
53  bool beQuiet = false,
54  bool* ignoredPtr = NULL);
55  virtual bool OpenDocument(
56  const QByteArray* documentTypeIdPtr,
57  const QString* fileNamePtr = NULL,
58  bool createView = true,
59  const QByteArray& viewTypeId = "",
60  istd::IChangeable** documentPtr = NULL,
61  FileToTypeMap* loadedMapPtr = NULL,
62  bool beQuiet = false,
63  bool* ignoredPtr = NULL);
64  virtual bool SaveDocument(
65  int documentIndex = -1,
66  bool requestFileName = false,
67  FileToTypeMap* savedMapPtr = NULL,
68  bool beQuiet = false,
69  bool* ignoredPtr = NULL);
70  virtual bool SaveDirtyDocuments(bool beQuiet = false, bool* ignoredPtr = NULL);
71  virtual bool CloseDocument(int documentIndex = -1, bool beQuiet = false, bool* ignoredPtr = NULL);
72  virtual bool CloseView(istd::IPolymorphic* viewPtr = NULL, bool beQuiet = false, bool* ignoredPtr = NULL);
73 
74 protected:
78  struct ViewInfo
79  {
81  QByteArray viewTypeId;
82  };
83  typedef QList<ViewInfo> Views;
84 
85 
89  struct SingleDocumentData: public DocumentInfo, public imod::CMultiModelDispatcherBase
90  {
93  const QByteArray& documentTypeId,
95 
96  virtual ~SingleDocumentData();
97 
102 
103  protected:
104  // reimplemented (imod::CMultiModelDispatcherBase)
105  virtual void OnModelChanged(int modelId, const istd::IChangeable::ChangeSet& changeSet);
106  };
107 
111  virtual void SetActiveView(istd::IPolymorphic* viewPtr);
112 
122  const QString& filePath,
123  bool createView,
124  const QByteArray& viewTypeId,
125  QByteArray& documentTypeId,
126  bool beQuiet,
127  bool* ignoredPtr);
128 
129  virtual void CloseAllDocuments();
130 
134  SingleDocumentData& GetSingleDocumentData(int index) const;
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 
170  bool RegisterDocument(SingleDocumentData* documentPtr);
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 
206 private:
208 
209  DocumentInfos m_documentInfos;
210 
211  istd::IPolymorphic* m_activeViewPtr;
212 };
213 
214 
215 } // namespace idoc
216 
217 
218 #endif // idoc_CMultiDocumentManagerBase_included
219 
220 
virtual void SetActiveView(istd::IPolymorphic *viewPtr)
Indicate that some view is active now.
SingleDocumentData * GetActiveDocumentInfo() const
Get document info assigned to active view.
virtual istd::IPolymorphic * AddViewToDocument(const istd::IChangeable &document, const QByteArray &viewTypeId=QByteArray())
Add a new view to the document.
virtual bool SaveDirtyDocuments(bool beQuiet=false, bool *ignoredPtr=NULL)
Ask user (optional) and save all dirty (changed) documents.
virtual void OnViewRemoved(istd::IPolymorphic *viewPtr)=0
Called before view is removed.
Basic implementation of a template-based multiple document manager.
virtual idoc::IUndoManager * GetUndoManagerForDocument(const istd::IChangeable *documentPtr) const
Return undo mananger for document documenPtr.
Generic implementation of a data model changes notifier.
virtual int GetViewsCount(int documentIndex) const
Get number of view for specified document.
virtual void OnModelChanged(int modelId, const istd::IChangeable::ChangeSet &changeSet)
Base implementation of document manager.
virtual QByteArray GetDocumentTypeId(const istd::IChangeable &document) const
Get ID of document type managed by this object.
virtual istd::IChangeable * OpenSingleDocument(const QString &filePath, bool createView, const QByteArray &viewTypeId, QByteArray &documentTypeId, bool beQuiet, bool *ignoredPtr)
Open single document using its file path.
SingleDocumentData & GetSingleDocumentData(int index) const
Get internal document data object.
SingleDocumentData(CMultiDocumentManagerBase *parentPtr, const QByteArray &documentTypeId, istd::IChangeable *documentPtr)
bool SerializeOpenDocumentList(iser::IArchive &archive)
Serializes open documents information.
virtual QStringList GetOpenFilePaths(const QByteArray *documentTypeIdPtr=NULL) const =0
Gets open file names.
virtual bool CloseView(istd::IPolymorphic *viewPtr=NULL, bool beQuiet=false, bool *ignoredPtr=NULL)
Close view.
Represent input/output persistence archive.
Definition: IArchive.h:30
Common interface for data model objects, which can be changed.
Definition: IChangeable.h:24
Base interface for all used interfaces and implementations.
Definition: IPolymorphic.h:17
virtual bool CloseDocument(int documentIndex=-1, bool beQuiet=false, bool *ignoredPtr=NULL)
Close document and all its views.
SingleDocumentData * GetDocumentInfoFromView(const istd::IPolymorphic &view) const
Get document info assigned to specified view.
virtual QString GetSaveFilePath(const QByteArray &documentTypeId, const istd::IChangeable *dataObjectPtr, const QString &currentFilePath) const =0
Gets save file name.
istd::TDelPtr< istd::IPolymorphic > ViewPtr
virtual bool InsertNewDocument(const QByteArray &documentTypeId, bool createView=true, const QByteArray &viewTypeId="", istd::IChangeable **newDocumentPtr=NULL, bool beQuiet=false, bool *ignoredPtr=NULL)
Creates a new document with the document ID documentTypeId.
virtual istd::IChangeable & GetDocumentFromIndex(int index, DocumentInfo *documentInfoPtr=NULL) const
Get document at specified index.
int GetDocumentIndex(const SingleDocumentData &document) const
Get position index of the given document in the document list.
#define NULL
Definition: istd.h:64
virtual istd::IPolymorphic * GetViewFromIndex(int documentIndex, int viewIndex) const
Get single view using its and document indices.
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 * GetDocumentInfoFromPath(const QString &filePath) const
Get document info assigned to specified file.
bool RegisterDocument(SingleDocumentData *documentPtr)
Register (attach) created document as new working document.
virtual bool SaveDocument(int documentIndex=-1, bool requestFileName=false, FileToTypeMap *savedMapPtr=NULL, bool beQuiet=false, bool *ignoredPtr=NULL)
Save document.
Set of change flags (its IDs).
Definition: IChangeable.h:30
QMap< QString, QByteArray > FileToTypeMap
Map from file path to ducument type ID's.
Interface providing UNDO/REDO functionality.
Definition: IUndoManager.h:16
virtual bool OpenDocument(const QByteArray *documentTypeIdPtr, const QString *fileNamePtr=NULL, bool createView=true, const QByteArray &viewTypeId="", istd::IChangeable **documentPtr=NULL, FileToTypeMap *loadedMapPtr=NULL, bool beQuiet=false, bool *ignoredPtr=NULL)
Opens document(s) from the file list.
virtual istd::IPolymorphic * GetActiveView() const
Return the active document.
virtual bool QueryDocumentSave(const SingleDocumentData &info, bool *ignoredPtr)=0
Query user if this document should be saved.
istd::TDelPtr< idoc::IUndoManager > UndoManagerPtr
istd::TDelPtr< istd::IChangeable > DocumentPtr
virtual int GetDocumentsCount() const
Get number of opened documents.
virtual istd::IChangeable * GetDocumentFromView(const istd::IPolymorphic &view, DocumentInfo *documentInfoPtr=NULL) const
Return the document assigned to view.
CMultiDocumentManagerBase()
Default constructor.
virtual void OnViewRegistered(istd::IPolymorphic *viewPtr, const SingleDocumentData &documentData)=0
Called after view is registered.

© 2007-2017 Witold Gantzke and Kirill Lepskiy