Scanframe Modular Application 0.1.0
Loading...
Searching...
No Matches
AppModuleInterface.h
Go to the documentation of this file.
1#pragma once
2
3#include <QAbstractItemModel>
4#include <QDockWidget>
5#include <QMimeType>
6#include <QObject>
7#include <QSettings>
10#include <ami/iface/global.h>
11#include <bitset>
14
15class QMainWindow;
16
17namespace sf
18{
19
24class _AMI_CLASS AppModuleInterface : public QObject
25{
26 public:
31 {
32 explicit Parameters(QSettings* settings, QObject* parent)
33 : _settings(settings)
34 , _parent(parent)
35 {}
36
40 QSettings* _settings;
44 QObject* _parent;
45 };
46
51
56
60 static void instantiate(QSettings* settings, QObject* parent);
61
66 {
68 Uninitialize = 0,
73 };
74
81
86
92 {
96 Tools
97 };
98
104 static void addAllMenuItems(MenuType menuType, QMenu* menu);
105
109 typedef QMap<QString, AppModuleInterface*> Map;
110
114 [[nodiscard]] static const Map& getMap();
115
120 virtual void initialize(InitializeStage stage) = 0;
121
125 [[nodiscard]] virtual QString getName() const = 0;
126
130 [[nodiscard]] virtual QString getDescription() const = 0;
131
135 [[nodiscard]] virtual QString getLibraryFilename() const = 0;
136
140 [[nodiscard]] virtual QString getSvgIconResource() const;
141
145 virtual void addPropertyPages(PropertySheetDialog* sheet) = 0;
146
150 virtual void addMenuItems(MenuType menuType, QMenu* menu);
151
155 typedef QList<QDockWidget*> DockWidgetList;
156
160 virtual DockWidgetList createDockingWidgets(QWidget* parent);
161
168
172 virtual void addToolBars(QMainWindow* mainWindow);
173
179 static void addAllToolBars(QMainWindow* mainWindow);
180
186 [[nodiscard]] bool hasFileTypes() const;
187
194 void addFileType(const QString& name, const QString& suffix);
195
201 void addFileType(const QString& mime);
202
208 void addFileType(const QMimeType& mime);
209
215 static AppModuleInterface* findByFile(const QString& filename);
216
225 [[nodiscard]] QString getFileTypeFilters() const;
226
235 static QString getFileTypeFilters(bool all_files);
236
242 static AppModuleInterface* selectDialog(const QString& title, QSettings* settings, QWidget* parent = nullptr);
243
251 [[nodiscard]] static QAbstractItemModel* getListModel(bool file_only, QObject* parent);
252
259 [[nodiscard]] MultiDocInterface* createChild(QWidget* parent) const;
260
264 [[nodiscard]] QSettings* getSettings() const;
265
273 MultiDocInterface* openFile(const QString& filename, AppModuleInterface* ami = nullptr) const;
274
281 virtual void documentActivated(MultiDocInterface* iface, bool yn) const;
282
291
292 protected:
299 [[nodiscard]] virtual MultiDocInterface* createWidget(QWidget* parent) const;
300
301 private:
305 QSettings* _settings;
309 QList<AppModuleFileType> _fileTypes;
313 InitializeStage _initializeStage;
317 static Map _map;
318
319 // Declarations of static functions and data members to be able to create implementations.
321};
322
323}// namespace sf
#define SF_DECL_IFACE(InterfaceType, ParamType, FuncName)
Declares a public static function in the class where it is used. Where: InterfaceType: Global typenam...
Definition TClassRegistration.h:71
#define _AMI_CLASS
Definition ami/iface/global.h:35
Base/Interface class for application modules. This class should provide functionality for loading lib...
Definition AppModuleInterface.h:25
virtual QString getName() const =0
Gets the description of this instance.
bool hasFileTypes() const
virtual QString getLibraryFilename() const =0
Gets the library filename.
virtual QString getSvgIconResource() const
Gets svg icon resource name and can be overridden to change the default.
AppModuleInterface(const Parameters &)
Constructor for passing general structure for derived classes.
MultiDocInterface * createChild(QWidget *parent) const
Calls createChild() and assigns this creating instance for reference.
static void addAllPropertyPages(PropertySheetDialog *sheet)
Adds property pages from all modules to the passed sheet.
static void addAllMenuItems(MenuType menuType, QMenu *menu)
Adds items from all modules to this menu.
virtual QString getDescription() const =0
Gets the description of this instance.
virtual MultiDocInterface * createWidget(QWidget *parent) const
Creates child of the passed parent (i.e. QMdiArea).
MultiDocInterface * openFile(const QString &filename, AppModuleInterface *ami=nullptr) const
Makes the application open a file.
virtual DockWidgetList createDockingWidgets(QWidget *parent)
Creates docking widgets having the passed parent.
TClosure< MultiDocInterface *, const QString &, AppModuleInterface * > OpenFileClosure
Type definition for the callback closure.
Definition AppModuleInterface.h:286
QString getFileTypeFilters() const
Gets the filter string for a file dialog.
static QString getFileTypeFilters(bool all_files)
Gets the filter string for the open file dialog.
QMap< QString, AppModuleInterface * > Map
Definition AppModuleInterface.h:109
void addFileType(const QString &name, const QString &suffix)
Adds a file type handled by this instance.
InitializeStage
Stages for a module.
Definition AppModuleInterface.h:66
@ Initialize
Definition AppModuleInterface.h:70
@ Finalize
Definition AppModuleInterface.h:72
static size_t initializeInstances(InitializeStage stage)
Initializes all uninitialized instances or visa versa.
~AppModuleInterface() override
Virtual destructor for derived classes.
static AppModuleInterface * findByFile(const QString &filename)
Find the instance handling the file using the file suffix.
QSettings * getSettings() const
Gets the settings class passed on creation.
void addFileType(const QString &mime)
Adds a file type handled by this instance.
static OpenFileClosure callbackOpenFile
Holds a callback to open a file in the application.
Definition AppModuleInterface.h:290
static DockWidgetList createAllDockingWidgets(QWidget *parent)
Creates all docking widgets of the loaded modules by calling createDockingWidgets().
virtual void documentActivated(MultiDocInterface *iface, bool yn) const
Called from main window when a document is activated or deactivated.
virtual void addPropertyPages(PropertySheetDialog *sheet)=0
Adds module property pages to the passed sheet.
static const Map & getMap()
Gets the named module map.
virtual void initialize(InitializeStage stage)=0
Called when al modules are loaded or when a module added.
MenuType
Type of menu items to collect.
Definition AppModuleInterface.h:92
@ View
Definition AppModuleInterface.h:95
@ Project
Definition AppModuleInterface.h:93
@ Settings
Definition AppModuleInterface.h:94
virtual void addToolBars(QMainWindow *mainWindow)
Adds toolbars to the passed main window.
virtual void addMenuItems(MenuType menuType, QMenu *menu)
Adds menu items for the passed type of menu.
void addFileType(const QMimeType &mime)
Adds a file type using the passed QMimeType instance.
QList< QDockWidget * > DockWidgetList
Type definition for containing dock widgets.
Definition AppModuleInterface.h:155
static QAbstractItemModel * getListModel(bool file_only, QObject *parent)
Gets a list model from the available instances.
static AppModuleInterface * selectDialog(const QString &title, QSettings *settings, QWidget *parent=nullptr)
Determined if this module handles this mime type.
static void instantiate(QSettings *settings, QObject *parent)
Creates instances of all available/loaded interface implementations.
static void addAllToolBars(QMainWindow *mainWindow)
Creates all toolbars of the loaded modules by calling addToolBars().
Interface for MDI document widgets handling files.
Definition MultiDocInterface.h:41
Dialog containing multiple property pages.
Definition qt/PropertySheetDialog.h:14
Encapsulates the std::function() template.
Definition TClosure.h:14
Definition Application.h:10
Structure for passing parameters to derived classes loaded and created at run-time.
Definition AppModuleInterface.h:31
QObject * _parent
Parent object.
Definition AppModuleInterface.h:44
Parameters(QSettings *settings, QObject *parent)
Definition AppModuleInterface.h:32
QSettings * _settings
Settings of application.
Definition AppModuleInterface.h:40