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
25class _AMI_CLASS AppModuleInterface : public QObject
26{
27 public:
32 {
33 explicit Parameters(QSettings* settings, QObject* parent)
34 : _settings(settings)
35 , _parent(parent)
36 {}
37
41 QSettings* _settings;
45 QObject* _parent;
46 };
47
52
57
61 static void instantiate(QSettings* settings, QObject* parent);
62
67 {
69 Uninitialize = 0,
74 };
82
87
92 {
95 Tools
96 };
97
103 static void addAllMenuItems(MenuType menuType, QMenu* menu);
104
108 typedef QMap<QString, AppModuleInterface*> Map;
109
113 [[nodiscard]] static const Map& getMap();
114
119 virtual void initialize(InitializeStage stage) = 0;
120
124 [[nodiscard]] virtual QString getName() const = 0;
125
129 [[nodiscard]] virtual QString getDescription() const = 0;
130
134 [[nodiscard]] virtual QString getLibraryFilename() const = 0;
135
139 [[nodiscard]] virtual QString getSvgIconResource() const;
140
144 virtual void addPropertyPages(PropertySheetDialog* sheet) = 0;
145
149 virtual void addMenuItems(MenuType menuType, QMenu* menu);
150
154 typedef QList<QDockWidget*> DockWidgetList;
155
159 virtual DockWidgetList createDockingWidgets(QWidget* parent);
160
167
171 virtual void addToolBars(QMainWindow* mainWindow);
172
178 static void addAllToolBars(QMainWindow* mainWindow);
179
185 [[nodiscard]] bool hasFileTypes() const;
186
193 void addFileType(const QString& name, const QString& suffix);
194
200 void addFileType(const QString& mime);
201
207 void addFileType(const QMimeType& mime);
208
214 static AppModuleInterface* findByFile(const QString& filename);
215
224 [[nodiscard]] QString getFileTypeFilters() const;
225
234 static QString getFileTypeFilters(bool all_files);
235
241 static AppModuleInterface* selectDialog(const QString& title, QSettings* settings, QWidget* parent = nullptr);
242
250 [[nodiscard]] static QAbstractItemModel* getListModel(bool file_only, QObject* parent);
251
258 [[nodiscard]] MultiDocInterface* createChild(QWidget* parent) const;
259
263 [[nodiscard]] QSettings* getSettings() const;
264
272 MultiDocInterface* openFile(const QString& filename, AppModuleInterface* ami = nullptr) const;
273
280 virtual void documentActivated(MultiDocInterface* iface, bool yn) const;
281
290
291 protected:
298 [[nodiscard]] virtual MultiDocInterface* createWidget(QWidget* parent) const;
299
300 private:
304 QSettings* _settings;
308 QList<AppModuleFileType> _fileTypes;
312 InitializeStage _initializeStage;
316 static Map _map;
317
318 // Declarations of static functions and data members to be able to create implementations.
320};
321
322}// 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.
Definition AppModuleInterface.h:26
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:285
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:108
void addFileType(const QString &name, const QString &suffix)
Adds a file type handled by this instance.
InitializeStage
Definition AppModuleInterface.h:67
@ Initialize
Definition AppModuleInterface.h:71
@ Finalize
Definition AppModuleInterface.h:73
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:289
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
Definition AppModuleInterface.h:92
@ View
Definition AppModuleInterface.h:94
@ Settings
Definition AppModuleInterface.h:93
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:154
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:32
QObject * _parent
Parent object.
Definition AppModuleInterface.h:45
Parameters(QSettings *settings, QObject *parent)
Definition AppModuleInterface.h:33
QSettings * _settings
Settings of application.
Definition AppModuleInterface.h:41