CMainWindowGuiComp.h
Go to the documentation of this file.
1 #ifndef iqtdoc_CMainWindowGuiComp_included
2 #define iqtdoc_CMainWindowGuiComp_included
3 
4 
5 // Qt includes
6 #include <QtCore/QtGlobal>
7 #if QT_VERSION >= 0x050000
8 #include <QtWidgets/QMainWindow>
9 #include <QtWidgets/QDockWidget>
10 #else
11 #include <QtGui/QMainWindow>
12 #include <QtGui/QDockWidget>
13 #endif
14 
15 // ACF includes
16 #include <imod/IModel.h>
18 #include <ibase/IApplication.h>
19 #include <ibase/IApplicationInfo.h>
21 #include <idoc/IUndoManager.h>
22 #include <idoc/IDocumentManager.h>
24 
25 
26 namespace iqtdoc
27 {
28 
29 
30 // Base class as work-around of static variable limit in ACF macros
33 {
34 public:
36 
37  I_BEGIN_BASE_COMPONENT(CMainWindowGuiCompBase);
38  I_ASSIGN(m_applicationInfoCompPtr, "ApplicationInfo", "Application info", true, "ApplicationInfo");
39  I_ASSIGN(m_documentManagerCompPtr, "DocumentManager", "Document manager", true, "DocumentManager");
40  I_ASSIGN_TO(m_documentManagerModelCompPtr, m_documentManagerCompPtr, true);
41  I_ASSIGN_TO(m_documentManagerCommandsCompPtr, m_documentManagerCompPtr, false);
42  I_ASSIGN(m_applicationCompPtr, "Application", "Access to the application's command line", true, "Application");
43  I_ASSIGN(m_isCopyPathVisibleAttrPtr, "IsCopyPathVisible", "If true, operation Tools/CopyDocumentPath will be visible", true, false);
44  I_ASSIGN(m_isOpenContainingFolderVisibleAttrPtr, "IsOpenContainingFolderVisible", "If true, operation Tools/Open Containing Folder will be visible", true, false);
45  I_ASSIGN(m_maxRecentFilesCountAttrPtr, "MaxRecentFiles", "Maximal size of recent file list for one document type", true, 10);
46  I_ASSIGN(m_isOpenCommandVisibleAttrPtr, "OpenCommandVisible", "If enabled the open document command will be shown", false, true);
47  I_ASSIGN(m_isSaveCommandVisibleAttrPtr, "SaveCommandVisible", "If enabled the save document commands will be shown", false, true);
48  I_ASSIGN_MULTI_0(m_mainWindowCompTypeIdsAttrPtr, "MainWindowCompTypeIds", "Set of document type IDs (comma seperated) to enable main window component, empty string enables component independly from document selection", true);
49  I_END_COMPONENT;
50 
51 protected:
52  I_REF(ibase::IApplicationInfo, m_applicationInfoCompPtr);
53  I_REF(idoc::IDocumentManager, m_documentManagerCompPtr);
54  I_REF(imod::IModel, m_documentManagerModelCompPtr);
55  I_REF(ibase::ICommandsProvider, m_documentManagerCommandsCompPtr);
56  I_REF(ibase::IApplication, m_applicationCompPtr);
57  I_ATTR(bool, m_isCopyPathVisibleAttrPtr);
58  I_ATTR(bool, m_isOpenContainingFolderVisibleAttrPtr);
59  I_ATTR(int, m_maxRecentFilesCountAttrPtr);
60  I_ATTR(bool, m_isOpenCommandVisibleAttrPtr);
61  I_ATTR(bool, m_isSaveCommandVisibleAttrPtr);
62  I_MULTIATTR(QByteArray, m_mainWindowCompTypeIdsAttrPtr);
63 };
64 
65 
71  protected imod::TSingleModelObserverBase<idoc::IDocumentManager>
72 {
73  Q_OBJECT
74 
75 public:
78 
79  I_BEGIN_COMPONENT(CMainWindowGuiComp);
80  I_REGISTER_SUBELEMENT(FileCommands);
81  I_REGISTER_SUBELEMENT_INTERFACE(FileCommands, ibase::IHierarchicalCommand, GetFileCommands);
82  I_REGISTER_SUBELEMENT_INTERFACE(FileCommands, ibase::ICommand, GetFileCommands);
83  I_REGISTER_SUBELEMENT_INTERFACE(FileCommands, iprm::INameParam, GetFileCommands);
84  I_REGISTER_SUBELEMENT_INTERFACE(FileCommands, iprm::IEnableableParam, GetFileCommands);
85  I_REGISTER_SUBELEMENT_INTERFACE(FileCommands, istd::IChangeable, GetFileCommands);
86  I_REGISTER_SUBELEMENT(EditCommands);
87  I_REGISTER_SUBELEMENT_INTERFACE(FileCommands, ibase::IHierarchicalCommand, GetEditCommands);
88  I_REGISTER_SUBELEMENT_INTERFACE(FileCommands, ibase::ICommand, GetEditCommands);
89  I_REGISTER_SUBELEMENT_INTERFACE(FileCommands, iprm::INameParam, GetEditCommands);
90  I_REGISTER_SUBELEMENT_INTERFACE(FileCommands, iprm::IEnableableParam, GetEditCommands);
91  I_REGISTER_SUBELEMENT_INTERFACE(FileCommands, istd::IChangeable, GetEditCommands);
92  I_END_COMPONENT;
93 
94  enum GroupId
95  {
96  GI_APPLICATION = 0x200,
100  };
101 
103  {
107  };
108 
110 
111  // reimplemented (imod::IObserver)
112  virtual bool OnModelAttached(imod::IModel* modelPtr, istd::IChangeable::ChangeSet& changeMask);
113  virtual bool OnModelDetached(imod::IModel* modelPtr);
114 
115 protected:
116  virtual bool OpenFile(const QString& fileName);
117 
118  virtual void OnActiveViewChanged();
119  virtual void OnActiveDocumentChanged();
120  virtual void OnDragEnterEvent(QDragEnterEvent* dragEnterEventPtr);
121  virtual void OnDropEvent(QDropEvent* dropEventPtr);
122 
123  void SetupNewCommand();
124  bool HasDocumentTemplate() const;
125  void UpdateUndoMenu();
126 
127  void OnNewDocument(const QByteArray& documentTypeId);
128 
129  virtual bool SerializeRecentFileList(iser::IArchive& archive);
134  virtual void UpdateRecentFileList(const idoc::IDocumentManager::FileToTypeMap& fileToTypeMap);
135  virtual void RemoveFromRecentFileList(const QString& filePath);
136 
137  virtual bool IsMainWindowActive(int index) const;
138 
139  // reimplemented (iqtgui::CSimpleMainWindowGuiComp)
140  virtual void UpdateFixedCommands(iqtgui::CHierarchicalCommand& fixedCommands);
141  virtual void UpdateToolsCommands(iqtgui::CHierarchicalCommand& toolsCommand);
142  virtual void AppendMenuActions(iqtgui::CHierarchicalCommand& menuCommands);
143 
144  // reimplemented (iqtgui::CGuiComponentBase)
145  virtual void OnGuiCreated();
146  virtual void OnRetranslate();
147 
148  // reimplemented (imod::TSingleModelObserverBase)
149  virtual void OnUpdate(const istd::IChangeable::ChangeSet& changeSet);
150 
151  // reimplemented (QObject)
152  virtual bool eventFilter(QObject* sourcePtr, QEvent* eventPtr);
153 
154  // reimplemented (icomp::CComponentBase)
155  virtual void OnComponentCreated();
156  virtual void OnComponentDestroyed();
157 
158 protected Q_SLOTS:
159  void OnNew();
160  void OnOpen();
161  void OnSave();
162  void OnSaveAs();
163  void OnOpenDocument(const QByteArray* documentTypeIdPtr = NULL);
164  void OnQuit();
165  void OnUndo();
166  void OnRedo();
167  void OnCopyPathToClipboard();
168  void OnOpenDocumentFolder();
169 
170 private:
171  class NewDocumentCommand: public iqtgui::CHierarchicalCommand
172  {
173  public:
175 
176  NewDocumentCommand(CMainWindowGuiComp* parentPtr, const QByteArray& documentTypeId): m_parent(*parentPtr), m_documentTypeId(documentTypeId){}
177 
178  // reimplemented (ibase::ICommand)
179  virtual bool Execute(istd::IPolymorphic* /*contextPtr*/)
180  {
181  m_parent.OnNewDocument(m_documentTypeId);
182 
183  return true;
184  }
185 
186  private:
187  CMainWindowGuiComp& m_parent;
188  QByteArray m_documentTypeId;
189  };
190 
191  class RecentFileCommand: public iqtgui::CHierarchicalCommand
192  {
193  public:
195 
196  RecentFileCommand(
197  CMainWindowGuiComp* parentPtr,
198  const QString& name,
199  const QString& actionString,
200  bool isOpenCommand);
201 
202  const QString& GetActionString() const;
203  bool IsOpenCommand() const;
204 
205  // reimplemented (ibase::ICommand)
206  virtual bool Execute(istd::IPolymorphic* /*contextPtr*/);
207 
208  private:
209  CMainWindowGuiComp& m_parent;
210  QString m_actionString;
211  bool m_isOpenCommand;
212  };
213 
214  class ActiveUndoManager: public imod::TSingleModelObserverBase<idoc::IUndoManager>
215  {
216  public:
218 
219  explicit ActiveUndoManager(CMainWindowGuiComp& parent);
220 
221  // reimplemented (imod::IObserver)
222  virtual bool OnModelAttached(imod::IModel* modelPtr, istd::IChangeable::ChangeSet& changeMask);
223 
224  protected:
225  // reimplemented (imod::CSingleModelObserverBase)
226  virtual void OnUpdate(const istd::IChangeable::ChangeSet& changeSet);
227 
228  private:
229  CMainWindowGuiComp& m_parent;
230  };
231 
232  template <class InterfaceType>
233  static InterfaceType* GetFileCommands(CMainWindowGuiComp& parent)
234  {
235  return &parent.m_fileCommand;
236  }
237 
238  template <class InterfaceType>
239  static InterfaceType* GetEditCommands(CMainWindowGuiComp& parent)
240  {
241  return &parent.m_editCommand;
242  }
243 
244  ActiveUndoManager m_activeUndoManager;
245 
246  istd::IPolymorphic* m_activeViewPtr;
247  istd::IChangeable* m_activeDocumentPtr;
248 
249  iqtgui::CHierarchicalCommand m_fileCommand;
250  iqtgui::CHierarchicalCommand m_editCommand;
251 
252  // file menu group
253  iqtgui::CHierarchicalCommand m_newCommand;
254  iqtgui::CHierarchicalCommand m_openCommand;
255  iqtgui::CHierarchicalCommand m_saveCommand;
256  iqtgui::CHierarchicalCommand m_saveAsCommand;
257  iqtgui::CHierarchicalCommand m_quitCommand;
258  // edit menu group
259  iqtgui::CHierarchicalCommand m_undoCommand;
260  iqtgui::CHierarchicalCommand m_redoCommand;
261  // tools menu group
262  iqtgui::CHierarchicalCommand m_copyPathToClipboardCommand;
263  iqtgui::CHierarchicalCommand m_openDocumentFolderCommand;
264 
265  typedef istd::TDelPtr<iqtgui::CHierarchicalCommand> RecentGroupCommandPtr;
266  typedef QMap<QByteArray, RecentGroupCommandPtr> RecentFilesMap;
267  RecentFilesMap m_recentFilesMap;
268 };
269 
270 
271 } // namespace iqtdoc
272 
273 
274 #endif // !iqtdoc_CMainWindowGuiComp_included
275 
276 
Implementation of hierarchical command based on QAction from Qt.
virtual bool SerializeRecentFileList(iser::IArchive &archive)
Interface for a object containing simple text.
Definition: INameParam.h:20
virtual void OnActiveDocumentChanged()
CMainWindowGuiCompBase BaseClass
Provides single command for interaction with user.
Definition: ICommand.h:18
virtual void UpdateFixedCommands(iqtgui::CHierarchicalCommand &fixedCommands)
iqtgui::CSimpleMainWindowGuiComp BaseClass
Basic implementation for a single model observer with binding to concrete data object interface...
virtual bool OpenFile(const QString &fileName)
virtual void UpdateToolsCommands(iqtgui::CHierarchicalCommand &toolsCommand)
virtual void AppendMenuActions(iqtgui::CHierarchicalCommand &menuCommands)
Interface for a provider of the heriarchical commands.
virtual bool OnModelDetached(imod::IModel *modelPtr)
This call back function will be called, if an observable object is about to be detached.
Represent input/output persistence archive.
Definition: IArchive.h:30
Common interface for data model objects, which can be changed.
Definition: IChangeable.h:24
virtual bool OnModelAttached(imod::IModel *modelPtr, istd::IChangeable::ChangeSet &changeMask)
This call back function will be called, if an observable object is about to be attached.
Interface for objects which can be enabled/disabled.
Base interface for all used interfaces and implementations.
Definition: IPolymorphic.h:17
virtual void OnComponentDestroyed()
virtual void RemoveFromRecentFileList(const QString &filePath)
Provide set of user actions needed to manage documents in MVC (Model View Controller) concept...
virtual void OnRetranslate()
Called when non-GUI elements (like commands) should be retranslated.
bool HasDocumentTemplate() const
Common interface to define the hierarchical graph structures.
Standard main window component for any document based application.
This interface provides some information about the application.
virtual void OnActiveViewChanged()
virtual bool eventFilter(QObject *sourcePtr, QEvent *eventPtr)
#define NULL
Definition: istd.h:64
virtual bool IsMainWindowActive(int index) const
virtual void OnComponentCreated()
void OnOpenDocument(const QByteArray *documentTypeIdPtr=NULL)
virtual void OnDropEvent(QDropEvent *dropEventPtr)
virtual void OnGuiCreated()
Called just after GUI is initialized.
virtual void OnDragEnterEvent(QDragEnterEvent *dragEnterEventPtr)
Common interface for model objects, that supports Model/Observer design pattern.
Definition: IModel.h:23
Set of change flags (its IDs).
Definition: IChangeable.h:30
imod::TSingleModelObserverBase< idoc::IDocumentManager > BaseClass2
QMap< QString, QByteArray > FileToTypeMap
Map from file path to ducument type ID's.
virtual void UpdateRecentFileList(const idoc::IDocumentManager::FileToTypeMap &fileToTypeMap)
Updates displayed list of recent used files.
Interface for the main entry point of a component-based application.
Definition: IApplication.h:22
Pointer wrapper providing automatic deleting pointed object during destruction.
Definition: TDelPtr.h:20
virtual void OnUpdate(const istd::IChangeable::ChangeSet &changeSet)
Called on update of observed model.
void OnNewDocument(const QByteArray &documentTypeId)

© 2007-2017 Witold Gantzke and Kirill Lepskiy