ACF $AcfVersion:0$
CMainWindowGuiComp.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/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>
22#include <idoc/IUndoManager.h>
27
28
29namespace iqtdoc
30{
31
32
33// Base class as work-around of static variable limit in ACF macros
36{
37public:
39
40 I_BEGIN_BASE_COMPONENT(CMainWindowGuiCompBase);
41 I_ASSIGN(m_applicationInfoCompPtr, "ApplicationInfo", "Application info", true, "ApplicationInfo");
42 I_ASSIGN(m_documentManagerCompPtr, "DocumentManager", "Document manager", true, "DocumentManager");
43 I_ASSIGN_TO(m_documentManagerModelCompPtr, m_documentManagerCompPtr, true);
44 I_ASSIGN_TO(m_documentManagerCommandsCompPtr, m_documentManagerCompPtr, false);
45 I_ASSIGN(m_applicationCompPtr, "Application", "Access to the application's command line", true, "Application");
46 I_ASSIGN(m_dropConsumerCompPtr, "DropConsumer", "Optionaly defined drop consumer. If no consumer is set, the document manager will process the drop content", false, "DropConsumer");
47 I_ASSIGN(m_persistenceProgressCompPtr, "PersistenceProgress", "Progress management loading and saving of the documents", false, "PersistenceProgress");
48 I_ASSIGN_TO(m_persistenceProgressGuiCompPtr, m_persistenceProgressCompPtr, false);
49 I_ASSIGN(m_isCopyPathVisibleAttrPtr, "IsCopyPathVisible", "If true, operation Tools/CopyDocumentPath will be visible", true, false);
50 I_ASSIGN(m_isOpenContainingFolderVisibleAttrPtr, "IsOpenContainingFolderVisible", "If true, operation Tools/Open Containing Folder will be visible", true, false);
51 I_ASSIGN(m_maxRecentFilesCountAttrPtr, "MaxRecentFiles", "Maximal size of recent file list for one document type", true, 10);
52 I_ASSIGN(m_isOpenCommandVisibleAttrPtr, "OpenCommandVisible", "If enabled the open document command will be shown", false, true);
53 I_ASSIGN(m_isSaveCommandVisibleAttrPtr, "SaveCommandVisible", "If enabled the save document commands will be shown", false, true);
54 I_ASSIGN_MULTI_0(m_mainWindowCompTypeIdsAttrPtr, "MainWindowCompTypeIds", "Set of document type IDs (comma separated) to enable main window component, empty string enables component independently from document selection", true);
55 I_END_COMPONENT;
56
57protected:
58 I_REF(ibase::IApplicationInfo, m_applicationInfoCompPtr);
59 I_REF(idoc::IDocumentManager, m_documentManagerCompPtr);
60 I_REF(imod::IModel, m_documentManagerModelCompPtr);
61 I_REF(ibase::ICommandsProvider, m_documentManagerCommandsCompPtr);
62 I_REF(ibase::IApplication, m_applicationCompPtr);
63 I_REF(iqtgui::IDropConsumer, m_dropConsumerCompPtr);
64 I_REF(ibase::IProgressManager, m_persistenceProgressCompPtr);
65 I_REF(iqtgui::IGuiObject, m_persistenceProgressGuiCompPtr);
66 I_ATTR(bool, m_isCopyPathVisibleAttrPtr);
67 I_ATTR(bool, m_isOpenContainingFolderVisibleAttrPtr);
68 I_ATTR(int, m_maxRecentFilesCountAttrPtr);
69 I_ATTR(bool, m_isOpenCommandVisibleAttrPtr);
70 I_ATTR(bool, m_isSaveCommandVisibleAttrPtr);
71 I_MULTIATTR(QByteArray, m_mainWindowCompTypeIdsAttrPtr);
72};
73
74
186 protected imod::TSingleModelObserverBase<idoc::IDocumentManager>
187{
188 Q_OBJECT
189
190public:
193
194 I_BEGIN_COMPONENT(CMainWindowGuiComp);
195 I_REGISTER_SUBELEMENT(FileCommands);
196 I_REGISTER_SUBELEMENT_INTERFACE(FileCommands, ibase::IHierarchicalCommand, GetFileCommands);
197 I_REGISTER_SUBELEMENT_INTERFACE(FileCommands, ibase::ICommand, GetFileCommands);
198 I_REGISTER_SUBELEMENT_INTERFACE(FileCommands, iprm::INameParam, GetFileCommands);
199 I_REGISTER_SUBELEMENT_INTERFACE(FileCommands, iprm::IEnableableParam, GetFileCommands);
200 I_REGISTER_SUBELEMENT_INTERFACE(FileCommands, istd::IChangeable, GetFileCommands);
201 I_REGISTER_SUBELEMENT(EditCommands);
202 I_REGISTER_SUBELEMENT_INTERFACE(FileCommands, ibase::IHierarchicalCommand, GetEditCommands);
203 I_REGISTER_SUBELEMENT_INTERFACE(FileCommands, ibase::ICommand, GetEditCommands);
204 I_REGISTER_SUBELEMENT_INTERFACE(FileCommands, iprm::INameParam, GetEditCommands);
205 I_REGISTER_SUBELEMENT_INTERFACE(FileCommands, iprm::IEnableableParam, GetEditCommands);
206 I_REGISTER_SUBELEMENT_INTERFACE(FileCommands, istd::IChangeable, GetEditCommands);
207 I_END_COMPONENT;
208
216
223
225
226 // reimplemented (imod::IObserver)
227 virtual bool OnModelAttached(imod::IModel* modelPtr, istd::IChangeable::ChangeSet& changeMask) override;
228 virtual bool OnModelDetached(imod::IModel* modelPtr) override;
229
230protected:
231 virtual bool OpenFile(const QString& fileName, const QByteArray* documentTypeIdPtr = NULL);
232 virtual bool SaveActiveDocument();
233
234 virtual void OnActiveViewChanged();
236 virtual void OnDragEnterEvent(QDragEnterEvent* dragEnterEventPtr);
237 virtual void OnDropEvent(QDropEvent* dropEventPtr);
238
242
243 void OnNewDocument(const QByteArray& documentTypeId);
244
251 virtual void RemoveFromRecentFileList(const QString& filePath);
252
253 virtual bool IsMainWindowActive(int index) const;
254
255 // reimplemented (iqtgui::CSimpleMainWindowGuiComp)
256 virtual void UpdateFixedCommands(iqtgui::CHierarchicalCommand& fixedCommands) override;
257 virtual void UpdateToolsCommands(iqtgui::CHierarchicalCommand& toolsCommand) override;
258 virtual void AppendMenuActions(iqtgui::CHierarchicalCommand& menuCommands) override;
259
260 // reimplemented (iqtgui::CGuiComponentBase)
261 virtual void OnGuiCreated() override;
262 virtual void OnGuiDestroyed() override;
263 virtual void OnRetranslate() override;
264 virtual void OnGuiDesignChanged() override;
265
266 // reimplemented (imod::TSingleModelObserverBase)
267 virtual void OnUpdate(const istd::IChangeable::ChangeSet& changeSet) override;
268
269 // reimplemented (QObject)
270 virtual bool eventFilter(QObject* sourcePtr, QEvent* eventPtr) override;
271
272 // reimplemented (icomp::CComponentBase)
273 virtual void OnComponentCreated() override;
274 virtual void OnComponentDestroyed() override;
275
276protected Q_SLOTS:
277 void OnNew();
278 void OnOpen();
279 void OnSave();
280 void OnSaveAs();
281 void OnQuit();
282 void OnUndo();
283 void OnRedo();
286
287private:
288 class NewDocumentCommand: public iqtgui::CHierarchicalCommand
289 {
290 public:
292
293 NewDocumentCommand(CMainWindowGuiComp* parentPtr, const QByteArray& documentTypeId): m_parent(*parentPtr), m_documentTypeId(documentTypeId){}
294
295 // reimplemented (ibase::ICommand)
296 virtual bool Execute(istd::IPolymorphic* /*contextPtr*/) override
297 {
298 m_parent.OnNewDocument(m_documentTypeId);
299
300 return true;
301 }
302
303 private:
304 CMainWindowGuiComp& m_parent;
305 QByteArray m_documentTypeId;
306 };
307
308 class RecentFileCommand: public iqtgui::CHierarchicalCommand
309 {
310 public:
311 typedef iqtgui::CHierarchicalCommand BaseClass;
312
313 RecentFileCommand(
314 CMainWindowGuiComp* parentPtr,
315 const QString& name,
316 const QString& actionString,
317 bool isOpenCommand);
318
319 const QString& GetActionString() const;
320 bool IsOpenCommand() const;
321
322 // reimplemented (ibase::ICommand)
323 virtual bool Execute(istd::IPolymorphic* /*contextPtr*/) override;
324
325 private:
326 CMainWindowGuiComp& m_parent;
327 QString m_actionString;
328 bool m_isOpenCommand;
329 };
330
331 class ActiveUndoManager: public imod::TSingleModelObserverBase<idoc::IUndoManager>
332 {
333 public:
335
336 explicit ActiveUndoManager(CMainWindowGuiComp& parent);
337
338 // reimplemented (imod::IObserver)
339 virtual bool OnModelAttached(imod::IModel* modelPtr, istd::IChangeable::ChangeSet& changeMask) override;
340
341 protected:
342 // reimplemented (imod::CSingleModelObserverBase)
343 virtual void OnUpdate(const istd::IChangeable::ChangeSet& changeSet) override;
344
345 private:
346 CMainWindowGuiComp& m_parent;
347 };
348
349 class ProgressObserver: public ibase::CCumulatedProgressManagerBase
350 {
351 public:
352 typedef ibase::IProgressManager BaseClass;
353
354 ProgressObserver(CMainWindowGuiComp& parent, ibase::IProgressManager* slaveManagerPtr);
355
356
357 protected:
358 // reimplemented (ibase::CCumulatedProgressManagerBase)
359 virtual void OnProgressChanged(double cumulatedValue) override;
360 virtual void OnTasksChanged() override;
361
362 private:
363 CMainWindowGuiComp& m_parent;
364
365 ibase::IProgressManager* m_slaveManagerPtr;
366 std::unique_ptr<ibase::IProgressLogger> m_currentLoggerPtr;
367 };
368
369 template <class InterfaceType>
370 static InterfaceType* GetFileCommands(CMainWindowGuiComp& parent)
371 {
372 return &parent.m_fileCommand;
373 }
374
375 template <class InterfaceType>
376 static InterfaceType* GetEditCommands(CMainWindowGuiComp& parent)
377 {
378 return &parent.m_editCommand;
379 }
380
381 ActiveUndoManager m_activeUndoManager;
382
383 istd::IPolymorphic* m_activeViewPtr;
384 istd::IChangeable* m_activeDocumentPtr;
385
386 iqtgui::CHierarchicalCommand m_fileCommand;
387 iqtgui::CHierarchicalCommand m_editCommand;
388
389 // file menu group
390 iqtgui::CHierarchicalCommand m_newCommand;
391 iqtgui::CHierarchicalCommand m_openCommand;
392 iqtgui::CHierarchicalCommand m_saveCommand;
393 iqtgui::CHierarchicalCommand m_saveAsCommand;
394 iqtgui::CHierarchicalCommand m_quitCommand;
395 // edit menu group
396 iqtgui::CHierarchicalCommand m_undoCommand;
397 iqtgui::CHierarchicalCommand m_redoCommand;
398 // tools menu group
399 iqtgui::CHierarchicalCommand m_copyPathToClipboardCommand;
400 iqtgui::CHierarchicalCommand m_openDocumentFolderCommand;
401
402 typedef istd::TDelPtr<iqtgui::CHierarchicalCommand> RecentGroupCommandPtr;
403 typedef QMap<QByteArray, RecentGroupCommandPtr> RecentFilesMap;
404 RecentFilesMap m_recentFilesMap;
405
406 istd::TDelPtr<iqtgui::CGuiComponentDialog> m_persistenceProgressDialogPtr;
407 istd::TDelPtr<ProgressObserver> m_persistenceProgressPtr;
408};
409
410
411} // namespace iqtdoc
412
413
Progress manager delegating cumulated progress result to another manager.
Interface for the main entry point of a component-based application.
This interface provides some information about the application.
Provides single command for interaction with user.
Definition ICommand.h:21
Interface for a provider of the heriarchical commands.
Consume information about progress of some process.
Provide set of user actions needed to manage documents in MVC (Model View Controller) concept.
QMap< QString, QByteArray > FileToTypeMap
Map from file path to document type ID's.
Common interface for model objects, that supports Model/Observer design pattern.
Definition IModel.h:25
Basic implementation for a single model observer with binding to concrete data object interface.
Interface for objects which can be enabled/disabled.
Interface for an object containing a name.
Definition INameParam.h:67
iqtgui::CSimpleMainWindowGuiComp BaseClass
Standard main window component for any document-based application.
virtual void OnActiveViewChanged()
void OnNewDocument(const QByteArray &documentTypeId)
virtual void OnRetranslate() override
Called when non-GUI elements (like commands) should be retranslated.
virtual bool OpenFile(const QString &fileName, const QByteArray *documentTypeIdPtr=NULL)
virtual bool IsMainWindowActive(int index) const
bool HasDocumentTemplate() const
virtual void AppendMenuActions(iqtgui::CHierarchicalCommand &menuCommands) override
virtual bool OnModelAttached(imod::IModel *modelPtr, istd::IChangeable::ChangeSet &changeMask) override
Callback invoked when an observable model is about to be attached to this observer.
virtual void RemoveFromRecentFileList(const QString &filePath)
virtual void OnGuiCreated() override
Called just after GUI is initialized.
virtual bool SerializeRecentFileList(iser::IArchive &archive)
virtual void UpdateFixedCommands(iqtgui::CHierarchicalCommand &fixedCommands) override
virtual void OnUpdate(const istd::IChangeable::ChangeSet &changeSet) override
Called on update of observed model.
virtual void UpdateToolsCommands(iqtgui::CHierarchicalCommand &toolsCommand) override
virtual void OnComponentDestroyed() override
imod::TSingleModelObserverBase< idoc::IDocumentManager > BaseClass2
virtual bool eventFilter(QObject *sourcePtr, QEvent *eventPtr) override
virtual bool OnModelDetached(imod::IModel *modelPtr) override
Callback invoked when an observable model is about to be detached from this observer.
virtual void OnDropEvent(QDropEvent *dropEventPtr)
virtual void OnActiveDocumentChanged()
virtual void OnDragEnterEvent(QDragEnterEvent *dragEnterEventPtr)
virtual void OnGuiDestroyed() override
Called just before GUI is released.
virtual void OnComponentCreated() override
virtual void UpdateRecentFileList(const idoc::IDocumentManager::FileToTypeMap &fileToTypeMap)
Updates displayed list of recent used files.
virtual bool SaveActiveDocument()
CMainWindowGuiCompBase BaseClass
virtual void OnGuiDesignChanged() override
Implementation of hierarchical command based on QAction from Qt.
Interface for objects which can receive dragged objects.
Common interface for GUI objects used in ACF component context.
Definition IGuiObject.h:133
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.
Pointer wrapper providing automatic deleting pointed object during destruction.
Definition TDelPtr.h:21
Common interface to define the hierarchical graph structures.
#define NULL
Definition istd.h:74
This package contains Qt implementations related to Document/View concept.