HAL  v4.5.0-133-g64838ea8d
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
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;
88  QSet<u32> gates() const;
89  };
90 
95  {
96  Q_OBJECT
97 
98  QList<ModuleSelectEntry> mEntries;
99  ModuleSelectExclude mExcl;
100 
101  public:
106  ModuleSelectModel(QObject* parent=nullptr);
107 
108  void appendEntries(bool history);
109 
110  int rowCount(const QModelIndex &parent = QModelIndex()) const override;
111  int columnCount(const QModelIndex &parent = QModelIndex()) const override;
112  QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
113  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
114 
115  void excludeModulesById(QSet<u32> id_set) { mExcl.append(id_set); }
116 
117  u32 moduleId(int irow) const;
118  QColor moduleColor(int irow) const;
119  };
120 
125  {
126  Q_OBJECT
127 
128  public:
129  ModuleSelectProxy(QObject* parent = nullptr);
130 
131  public Q_SLOTS:
132  void setSortMechanism(gui_utility::mSortMechanism sortMechanism);
133  void startSearch(QString text, int options) override;
134  bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override;
135 
136  protected:
137  static bool lessThan(const QColor& a, const QColor& b);
138  bool lessThan(const QModelIndex &sourceLeft, const QModelIndex &sourceRight) const override;
139 
140 
141  private:
142  gui_utility::mSortMechanism mSortMechanism;
143  };
144 
149  {
150  Q_OBJECT
151  public:
153  virtual ~ModuleSelectReceiver() {;}
154  public Q_SLOTS:
155  virtual void handleModulesPicked(const QSet<u32>& mods) = 0;
156  };
157 
162  {
163  Q_OBJECT
164  ModuleSelectExclude mSelectExclude;
165  QSet<u32> mModulesSelected;
166 
167  public:
168  ModuleSelectPicker(ModuleSelectReceiver* receiver, QObject* parent = nullptr);
169 
170  public Q_SLOTS:
171  void terminatePicker();
172 
173  Q_SIGNALS:
174  void triggerCursor(int icurs);
176 
177  public Q_SLOTS:
178  void handleSelectionChanged(void* sender);
179  };
180 
184  class ModuleSelectHistory : public QList<u32>
185  {
186  static ModuleSelectHistory* inst;
187  ModuleSelectHistory() {;}
188 
189  static const int sMaxEntries;
190  public:
191  static ModuleSelectHistory* instance();
192  void add(u32 id);
193  };
194 
199  {
200  Q_OBJECT
201 
202  public:
210  ModuleSelectView(bool history, Searchbar* sbar, QSet<u32>* exclude_ids,
211  QWidget* parent=nullptr);
212 
213  Q_SIGNALS:
214  void moduleSelected(u32 modId, bool doubleClick);
215 
216  private Q_SLOTS:
217  void handleSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
218  void handleDoubleClick(const QModelIndex& index);
219  };
220 }
221 
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.
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)
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
uint32_t u32
Definition: defines.h:41
Definition: defines.h:45
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
DisplayRole
Orientation