itom  4.1.0
pluginModel.h
1 /* ********************************************************************
2  itom software
3  URL: http://www.uni-stuttgart.de/ito
4  Copyright (C) 2020, Institut fuer Technische Optik (ITO),
5  Universitaet Stuttgart, Germany
6 
7  This file is part of itom.
8 
9  itom is free software; you can redistribute it and/or modify it
10  under the terms of the GNU Library General Public Licence as published by
11  the Free Software Foundation; either version 2 of the Licence, or (at
12  your option) any later version.
13 
14  itom is distributed in the hope that it will be useful, but
15  WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
17  General Public Licence for more details.
18 
19  You should have received a copy of the GNU Library General Public License
20  along with itom. If not, see <http://www.gnu.org/licenses/>.
21 *********************************************************************** */
22 
23 #ifndef PLUGINMODEL_H
24 #define PLUGINMODEL_H
25 
26 #if !defined(Q_MOC_RUN) || defined(ADDINMGR_DLL) //only moc this file in itomCommonQtLib but not in other libraries or executables linking against this itomCommonQtLib
27 
28 #include "addInMgrDefines.h"
29 #include "../common/addInInterface.h"
30 
31 #include <qabstractitemmodel.h>
32 #include <qscopedpointer.h>
33 #include <qcolor.h>
34 #include <qicon.h>
35 
36 namespace ito
37 {
38  class AddInBase;
39  class AddInManager;
40 
46  {
47  plsfOk = 0x001,
48  plsfWarning = 0x002,
49  plsfError = 0x004,
50  plsfIgnored = 0x008,
51  plsfRelDbg = 0x100,
52  plsfIncompatible = 0x200,
53  };
54  Q_DECLARE_FLAGS(PluginLoadStatusFlags, tPluginLoadStatusFlag)
55 
56 
57 
62  {
63  PluginLoadStatus() : filename("") {}
64  QString filename;
65  QList< QPair<ito::PluginLoadStatusFlags, QString> > messages;
66  };
67 
68  class PlugInModelPrivate; //forward declaration
69 
78  class ADDINMGR_EXPORT PlugInModel : public QAbstractItemModel
79  {
80  Q_OBJECT
81 
82  public:
83  PlugInModel(ito::AddInManager *addInManager, QObject *parent = NULL);
84  ~PlugInModel();
85 
86  enum tItemType {
87  itemUnknown = 0x0000,
88  itemCatDataIO = 0x0001,
89  itemCatActuator = 0x0002,
90  itemCatAlgo = 0x0004,
91  itemSubCategoryDataIO_Grabber = 0x0008,
92  itemSubCategoryDataIO_ADDA = 0x0010,
93  itemSubCategoryDataIO_RawIO = 0x0020,
94  itemPlugin = 0x0040,
95  itemInstance = 0x0080,
96  itemFilter = 0x0100,
97  itemWidget = 0x0200,
98  itemCatMainAll = itemCatDataIO | itemCatActuator | itemCatAlgo,
99  itemCatSubAll = itemSubCategoryDataIO_Grabber | itemSubCategoryDataIO_ADDA | itemSubCategoryDataIO_RawIO,
100  itemCatAll = itemCatMainAll | itemCatSubAll
101  };
102 
103  QVariant data(const QModelIndex &index, int role) const;
104  Qt::ItemFlags flags(const QModelIndex &index) const;
105  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
106  QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
107  QModelIndex parent(const QModelIndex &index) const;
108  int rowCount(const QModelIndex &parent = QModelIndex()) const;
109  int columnCount(const QModelIndex &parent = QModelIndex()) const;
110  int update(void) { emit(beginResetModel()); emit(endResetModel()); return 0; };
111 
112  bool insertInstance(ito::AddInInterfaceBase* addInInterface, bool beginOperation);
113  bool deleteInstance(ito::AddInBase *addInInstance, const bool beginOperation);
114  bool resetModel(bool beginOperation);
115 
116  QModelIndex getIndexByAddIn(ito::AddInBase *ai) const;
117  QModelIndex getIndexByAddInInterface(ito::AddInInterfaceBase *aib) const;
118  bool getModelIndexInfo(const QModelIndex &index, tItemType &type, size_t &internalData) const;
119 
120  bool getIsAlgoPlugIn(tItemType &itemType, size_t &internalData) const;
121  bool getIsGrabberInstance(tItemType &itemType, size_t &internalData) const;
122 
123  QModelIndex getTypeNode(const int type) const;
124 
126  QColor backgroundColorInstancesWithPythonRef() const;
127  void setBackgroundColorInstancesWithPythonRef(const QColor &bgColor);
128 
129  protected:
130  QVariant getFixedNodeInfo(const QModelIndex &index, const QVariant &name, const tItemType &itemType, const int &role, const QIcon icon) const;
131  QVariant getPluginNodeInfo(const QModelIndex &index, const int &role) const;
132  QVariant getInstanceNodeInfo(const QModelIndex &index, const int &role) const;
133  QVariant getFilterOrWidgetNodeInfo(const QModelIndex &index, const int &role, bool filterNotWidget) const;
134  QMimeData* mimeData(const QModelIndexList &indexes) const;
135 
136  private:
137  QScopedPointer<PlugInModelPrivate> d_ptr;
138  QString getInitCommand(const QModelIndex & item) const;
139  Q_DECLARE_PRIVATE(PlugInModel);
140  };
141 
142 }; // namespace ito
143 
144 #endif // #if !defined(Q_MOC_RUN) || defined(ADDINMGR_DLL)
145 
146 #endif
Definition: pluginModel.h:52
tPluginLoadStatusFlag
Definition: pluginModel.h:45
Definition: pluginModel.h:51
Definition: pluginModel.h:47
Definition: pluginModel.cpp:32
class for visualizing the available (loaded) plugins
Definition: pluginModel.h:78
Definition: pluginModel.h:50
Base class for all plugins.
Definition: addInInterface.h:385
class for AddIn management
Definition: addInManager.h:66
Definition: pluginModel.h:49
Definition: apiFunctionsGraph.cpp:39
This struct provides a structure for saving the load status of any plugins or designerWidgets.
Definition: pluginModel.h:61
Definition: pluginModel.h:48
forward declaration to private container class of AddInAlog
Definition: addInInterface.h:248