CSingleDocumentManagerBase.h
Go to the documentation of this file.
1 #ifndef idoc_CSingleDocumentManagerBase_included
2 #define idoc_CSingleDocumentManagerBase_included
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>
14 
15 
16 namespace idoc
17 {
18 
19 
26 {
27 public:
29 
30  // reimplemented (idoc::IDocumentManager)
31  virtual idoc::IUndoManager* GetUndoManagerForDocument(const istd::IChangeable* documentPtr) const;
32  virtual int GetDocumentsCount() const;
33  virtual istd::IChangeable& GetDocumentFromIndex(int index, DocumentInfo* documentInfoPtr = NULL) const;
34  virtual int GetViewsCount(int documentIndex) const;
35  virtual istd::IPolymorphic* GetViewFromIndex(int documentIndex, int viewIndex) const;
36  virtual istd::IPolymorphic* GetActiveView() const;
37  virtual istd::IChangeable* GetDocumentFromView(const istd::IPolymorphic& view, DocumentInfo* documentInfoPtr = NULL) const;
38  virtual istd::IPolymorphic* AddViewToDocument(const istd::IChangeable& document, const QByteArray& viewTypeId = QByteArray());
39  virtual QByteArray GetDocumentTypeId(const istd::IChangeable& document) const;
40  virtual bool InsertNewDocument(
41  const QByteArray& documentTypeId,
42  bool createView = true,
43  const QByteArray& viewTypeId = "",
44  istd::IChangeable** newDocumentPtr = NULL,
45  bool beQuiet = false,
46  bool* ignoredPtr = NULL);
47  virtual bool OpenDocument(
48  const QByteArray* documentTypeIdPtr,
49  const QString* fileNamePtr = NULL,
50  bool createView = true,
51  const QByteArray& viewTypeId = "",
52  istd::IChangeable** documentPtr = NULL,
53  FileToTypeMap* loadedMapPtr = NULL,
54  bool beQuiet = false,
55  bool* ignoredPtr = NULL);
56  virtual bool SaveDocument(
57  int documentIndex = -1,
58  bool requestFileName = false,
59  FileToTypeMap* savedMapPtr = NULL,
60  bool beQuiet = false,
61  bool* ignoredPtr = NULL);
62  virtual bool SaveDirtyDocuments(bool beQuiet = false, bool* ignoredPtr = NULL);
63  virtual bool CloseDocument(int documentIndex = -1, bool beQuiet = false, bool* ignoredPtr = NULL);
64  virtual bool CloseView(istd::IPolymorphic* viewPtr = NULL, bool beQuiet = false, bool* ignoredPtr = NULL);
65 
66 protected:
75  virtual bool OpenSingleDocument(
76  const QString& filePath,
77  bool createView,
78  const QByteArray& viewTypeId,
79  QByteArray& documentTypeId,
80  bool beQuiet,
81  bool* ignoredPtr);
82 
86  bool NewDocument(
87  const QByteArray& documentTypeId,
88  bool createView,
89  const QByteArray& viewTypeId,
90  bool initialize,
91  bool beQuiet,
92  bool* ignoredPtr);
96  bool RegisterDocument();
97 
98  void EnsureViewRemoved();
99 
100  QString GetCurrentDocumentFilePath() const;
101  bool HasDocumentPendingChanges() const;
102 
103  // reimplemented (imod::CSingleModelObserverBase)
104  virtual void OnUpdate(const istd::IChangeable::ChangeSet& changeSet);
105 
106  // abstract methods
107 
111  virtual void OnViewRegistered(istd::IPolymorphic* viewPtr) = 0;
112 
116  virtual void OnViewRemoved(istd::IPolymorphic* viewPtr) = 0;
117 
121  virtual QString GetOpenFilePath(const QByteArray* documentTypeIdPtr = NULL) const = 0;
122 
126  virtual QString GetSaveFilePath(const QByteArray& documentTypeId, const istd::IChangeable* dataObjectPtr, const QString& currentFilePath) const = 0;
127 
132  virtual bool QueryDocumentSave(bool* ignoredPtr) = 0;
133 
137  bool SerializeOpenDocument(iser::IArchive& archive);
138 
139 private:
140  QString m_filePath;
141  QByteArray m_documentTypeId;
142  QByteArray m_viewTypeId;
143  istd::TDelPtr<istd::IChangeable> m_documentPtr;
144  istd::TDelPtr<idoc::IUndoManager> m_undoManagerPtr;
146 
147  bool m_isDirty;
148 };
149 
150 
151 } // namespace idoc
152 
153 
154 #endif // idoc_CSingleDocumentManagerBase_included
155 
156 
Basic implementation for a single model observer.
virtual void OnUpdate(const istd::IChangeable::ChangeSet &changeSet)
Called on update of observed model.
virtual istd::IPolymorphic * GetViewFromIndex(int documentIndex, int viewIndex) const
Get single view using its and document indices.
virtual int GetDocumentsCount() const
Get number of opened documents.
bool RegisterDocument()
Register (attach) created document as new working document.
virtual istd::IChangeable * GetDocumentFromView(const istd::IPolymorphic &view, DocumentInfo *documentInfoPtr=NULL) const
Return the document assigned to view.
Basic implementation of a template-based single document manager.
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.
Base implementation of document manager.
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 void OnViewRemoved(istd::IPolymorphic *viewPtr)=0
Called before view is removed.
virtual idoc::IUndoManager * GetUndoManagerForDocument(const istd::IChangeable *documentPtr) const
Return undo mananger for document documenPtr.
virtual istd::IPolymorphic * GetActiveView() const
Return the active document.
virtual void OnViewRegistered(istd::IPolymorphic *viewPtr)=0
Called after view is registered.
virtual QString GetOpenFilePath(const QByteArray *documentTypeIdPtr=NULL) const =0
Gets open file names.
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
QString GetCurrentDocumentFilePath() const
virtual bool OpenSingleDocument(const QString &filePath, bool createView, const QByteArray &viewTypeId, QByteArray &documentTypeId, bool beQuiet, bool *ignoredPtr)
Open single document using its file path.
virtual QString GetSaveFilePath(const QByteArray &documentTypeId, const istd::IChangeable *dataObjectPtr, const QString &currentFilePath) const =0
Gets save file name.
virtual bool CloseView(istd::IPolymorphic *viewPtr=NULL, bool beQuiet=false, bool *ignoredPtr=NULL)
Close view.
virtual bool SaveDocument(int documentIndex=-1, bool requestFileName=false, FileToTypeMap *savedMapPtr=NULL, bool beQuiet=false, bool *ignoredPtr=NULL)
Save document.
#define NULL
Definition: istd.h:64
virtual QByteArray GetDocumentTypeId(const istd::IChangeable &document) const
Get ID of document type managed by this object.
virtual bool CloseDocument(int documentIndex=-1, bool beQuiet=false, bool *ignoredPtr=NULL)
Close document and all its views.
virtual int GetViewsCount(int documentIndex) const
Get number of view for specified document.
Set of change flags (its IDs).
Definition: IChangeable.h:30
virtual bool SaveDirtyDocuments(bool beQuiet=false, bool *ignoredPtr=NULL)
Ask user (optional) and save all dirty (changed) documents.
virtual istd::IPolymorphic * AddViewToDocument(const istd::IChangeable &document, const QByteArray &viewTypeId=QByteArray())
Add a new view to the document.
virtual bool QueryDocumentSave(bool *ignoredPtr)=0
Query user if this document can be closed.
QMap< QString, QByteArray > FileToTypeMap
Map from file path to ducument type ID's.
Interface providing UNDO/REDO functionality.
Definition: IUndoManager.h:16
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 istd::IChangeable & GetDocumentFromIndex(int index, DocumentInfo *documentInfoPtr=NULL) const
Get document at specified index.
bool SerializeOpenDocument(iser::IArchive &archive)
Serializes open documents information.

© 2007-2017 Witold Gantzke and Kirill Lepskiy