HAL
module_select_model.h
Go to the documentation of this file.
1 // MIT License
2 //
3 // Copyright (c) 2019 Ruhr University Bochum, Chair for Embedded Security. All Rights reserved.
4 // Copyright (c) 2019 Marc Fyrbiak, Sebastian Wallat, Max Hoffmann ("ORIGINAL AUTHORS"). All rights reserved.
5 // Copyright (c) 2021 Max Planck Institute for Security and Privacy. All Rights reserved.
6 // Copyright (c) 2021 Jörn Langheinrich, Julian Speith, Nils Albartus, René Walendy, Simon Klix ("ORIGINAL AUTHORS"). All Rights reserved.
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in all
16 // copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 // SOFTWARE.
25 
26 #pragma once
27 
28 #include "gui/gui_utils/sort.h"
29 #include "hal_core/defines.h"
30 
31 #include <QAbstractTableModel>
32 #include <QColor>
33 #include <QDebug>
34 #include <QList>
35 #include <QSortFilterProxyModel>
36 #include <QTableView>
38 
39 namespace hal {
40 
41  class Module;
42  class Searchbar;
43 
48  {
49  u32 mId;
50  QString mName;
51  QString mType;
52  QColor mColor;
53  public:
55 
61  QVariant data(int icol) const;
62  QColor color() const { return mColor; }
63  u32 id() const { return mId; }
64  };
65 
74  QList<u32> mGates;
75  QList<u32> mModules;
76  QSet<u32> mExclude;
77  public:
79  bool isAccepted(u32 modId) const { return !mExclude.contains(modId); }
80 
81  void append(QSet<u32> mod_ids) { mExclude += mod_ids; }
86  QString selectionToString() const;
87  QSet<u32> modules() const { return QSet<u32>::fromList(mModules); }
88  QSet<u32> gates() const { return QSet<u32>::fromList(mGates); }
89  };
90 
95  {
96  Q_OBJECT
97 
98  QList<ModuleSelectEntry> mEntries;
99  ModuleSelectExclude mExcl;
100 
101  public:
107  ModuleSelectModel(QObject* parent=nullptr);
108 
109  void appendEntries(bool history);
110 
111  int rowCount(const QModelIndex &parent = QModelIndex()) const override;
112  int columnCount(const QModelIndex &parent = QModelIndex()) const override;
113  QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
114  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
115 
116  void excludeModulesById(QSet<u32> id_set) { mExcl.append(id_set); }
117 
118  u32 moduleId(int irow) const;
119  QColor moduleColor(int irow) const;
120  };
121 
126  {
127  Q_OBJECT
128 
129  public:
130  ModuleSelectProxy(QObject* parent = nullptr);
131 
132  public Q_SLOTS:
133  void setSortMechanism(gui_utility::mSortMechanism sortMechanism);
134  void startSearch(QString text, int options) override;
135  bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override;
136 
137  protected:
138  static bool lessThan(const QColor& a, const QColor& b);
139  bool lessThan(const QModelIndex &sourceLeft, const QModelIndex &sourceRight) const override;
140 
141 
142  private:
143  gui_utility::mSortMechanism mSortMechanism;
144  };
145 
147  {
148  Q_OBJECT
149  public:
151  virtual ~ModuleSelectReceiver() {;}
152  public Q_SLOTS:
153  virtual void handleModulesPicked(const QSet<u32>& mods) = 0;
154  };
155 
160  {
161  Q_OBJECT
162  ModuleSelectExclude mSelectExclude;
163  QSet<u32> mModulesSelected;
164 
165  public:
166  ModuleSelectPicker(ModuleSelectReceiver* receiver, QObject* parent = nullptr);
167 
168  public Q_SLOTS:
169  void terminatePicker();
170 
171  Q_SIGNALS:
172  void triggerCursor(int icurs);
174 
175  public Q_SLOTS:
176  void handleSelectionChanged(void* sender);
177  };
178 
182  class ModuleSelectHistory : public QList<u32>
183  {
184  static ModuleSelectHistory* inst;
185  ModuleSelectHistory() {;}
186 
187  static const int sMaxEntries;
188  public:
189  static ModuleSelectHistory* instance();
190  void add(u32 id);
191  };
192 
197  {
198  Q_OBJECT
199 
200  public:
207  ModuleSelectView(bool history, Searchbar* sbar, QSet<u32>* exclude_ids,
208  QWidget* parent=nullptr);
209 
210  Q_SIGNALS:
211  void moduleSelected(u32 modId, bool doubleClick);
212 
213  private Q_SLOTS:
214  void handleSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
215  void handleDoubleClick(const QModelIndex& index);
216  };
217 }
218 
The ModuleSelectEntry class comprises a single entry of the module selection table.
u32 id() const
QVariant data(int icol) const
data returns data from requested column
ModuleSelectEntry(Module *m)
QColor color() const
The ModuleSelectExclude class is used to determine which modules can't be selected.
QSet< u32 > modules() const
QString selectionToString() const
selectionToString function is used to generate selection as text for message box
bool isAccepted(u32 modId) const
void append(QSet< u32 > mod_ids)
QSet< u32 > gates() const
The ModuleSelectHistory class singleton comprises a list of user selected modules.
static ModuleSelectHistory * instance()
The ModuleSelectModel class is the source model for module selection.
QColor moduleColor(int irow) const
void excludeModulesById(QSet< u32 > id_set)
void appendEntries(bool history)
int rowCount(const QModelIndex &parent=QModelIndex()) const override
ModuleSelectModel(QObject *parent=nullptr)
ModuleSelectModel constructor.
u32 moduleId(int irow) const
int columnCount(const QModelIndex &parent=QModelIndex()) const override
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
The ModuleSelectPicker class instance gets spawned to pick module from graph.
void handleSelectionChanged(void *sender)
ModuleSelectPicker(ModuleSelectReceiver *receiver, QObject *parent=nullptr)
void modulesPicked(QSet< u32 > mods)
void triggerCursor(int icurs)
The ModuleSelectProxy class allows sorting and filtering of module tables.
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override
void startSearch(QString text, int options) override
static bool lessThan(const QColor &a, const QColor &b)
ModuleSelectProxy(QObject *parent=nullptr)
void setSortMechanism(gui_utility::mSortMechanism sortMechanism)
ModuleSelectReceiver(QObject *parent=nullptr)
virtual void handleModulesPicked(const QSet< u32 > &mods)=0
The ModuleSelectView class is the table widget for module selection.
void moduleSelected(u32 modId, bool doubleClick)
ModuleSelectView(bool history, Searchbar *sbar, QSet< u32 > *exclude_ids, QWidget *parent=nullptr)
ModuleSelectView constructor.
A QFrame with a QLineEdit that can be used to input a substring to search for.
Definition: searchbar.h:48
quint32 u32
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const override
Q_OBJECTQ_OBJECT
Q_SIGNALSQ_SIGNALS
Q_SLOTSQ_SLOTS
QObject * parent() const const
QObject * sender() const const
bool contains(const T &value) const const
QSet< T > fromList(const QList< T > &list)
DisplayRole
Orientation