itom  4.1.0
dialogPluginPicker.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 DIALOGPLUGINPICKER_H
24 #define DIALOGPLUGINPICKER_H
25 
26 #include "../../common/addInInterface.h"
27 #include "../../common/sharedStructures.h"
28 
29 #include <QtGui>
30 #include <qdialog.h>
31 #include <qvector.h>
32 
33 #include "../../AddInManager/addInManager.h"
34 #include "../../AddInManager/pluginModel.h"
35 #include <qsortfilterproxymodel.h>
36 
37 #include "ui_dialogPluginPicker.h"
38 
39 namespace ito {
40 
41 class PickerSortFilterProxyModel : public QSortFilterProxyModel
42 {
43 public:
44  PickerSortFilterProxyModel(QObject *parent = 0) : QSortFilterProxyModel(parent), m_minimumMask(0x0), m_pluginName(QString::Null()), m_showPluginsWithoutInstance(false) {};
46 
47  inline void setPluginMinimumMask( const int minimumMask )
48  {
49  m_minimumMask = minimumMask;
50  invalidateFilter();
51  };
52 
53  inline void setPluginName( QString &name )
54  {
55  m_pluginName = name;
56  invalidateFilter();
57  }
58 
59  inline void showPluginsWithoutInstance(bool show)
60  {
61  m_showPluginsWithoutInstance = show;
62  invalidateFilter();
63  };
64 
65 protected:
66  bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
67  {
68  QModelIndex idx = sourceModel()->index(sourceRow, 0, sourceParent);
69  int type = sourceModel()->data(idx, Qt::UserRole + 1).toInt();
70  int itemType = sourceModel()->data(idx, Qt::UserRole + 3).toInt();
71 
72 
73  if(!m_showPluginsWithoutInstance)
74  {
75  int itemType = sourceModel()->data(idx, Qt::UserRole + 3).toInt();
76  if(itemType == ito::PlugInModel::itemPlugin && sourceModel()->hasChildren(idx) == false)
77  {
78  return false;
79  }
80  }
81 
82  if(!m_pluginName.isNull() && itemType == ito::PlugInModel::itemPlugin )
83  {
84  if( QString::compare( sourceModel()->data(idx, Qt::DisplayRole).toString(), m_pluginName, Qt::CaseInsensitive ) != 0)
85  {
86  return false;
87  }
88  }
89 
90  if(type == ito::typeAlgo)
91  {
92  return false; //never allow algorithms or widgets
93  }
94 
95  return (type & m_minimumMask) == m_minimumMask;
96  }
97 
98 private:
99  int m_minimumMask;
100  QString m_pluginName; //default QString::Null()
101  bool m_showPluginsWithoutInstance;
102 };
103 
104 } //end namespace ito
105 
106 namespace ito {
107 
108 
109 class DialogPluginPicker : public QDialog
110 {
111  Q_OBJECT
112 
113 public:
114  DialogPluginPicker(bool allowNewInstances, ito::AddInBase *currentItem, int minimumPluginTypeMask = 0x0, QString pluginName = QString::Null(), QWidget *parent = NULL );
115  ~DialogPluginPicker() {};
116 
117  ito::AddInBase* getSelectedInstance();
118 
119 protected:
120 
121 private:
122  void itemClicked(const QModelIndex &index);
123  Ui::DialogPluginPicker ui;
124  PickerSortFilterProxyModel *m_pFilterModel;
125 
126 private slots:
127  void itemDblClicked(const QModelIndex &index);
128  void showPluginsWithoutInstance(bool checked);
129  void createNewInstance(bool checked);
130  void selectionChanged(const QItemSelection& newSelection, const QItemSelection& oldSelection);
131 
132 };
133 
134 } //end namespace ito
135 
136 #endif
Definition: addInInterface.h:132
Base class for all plugins.
Definition: addInInterface.h:385
Definition: apiFunctionsGraph.cpp:39
Definition: dialogPluginPicker.h:109
Definition: dialogPluginPicker.h:41