HAL  v4.5.0-83-g30c8f0afc
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
gate_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 "hal_core/defines.h"
29 #include "gui/gui_utils/sort.h"
31 #include <QAbstractTableModel>
32 #include <QSortFilterProxyModel>
33 #include <QTableView>
34 #include <QSet>
35 #include <QList>
36 
37 namespace hal {
38 
39  class Gate;
40  class Module;
41  class Searchbar;
42 
47  {
48  u32 mId;
49  QString mName;
50  QString mType;
51  public:
53 
59  QVariant data(int icol) const;
60  u32 id() const { return mId; }
61  };
62 
63 
68  {
69  Q_OBJECT
70 
71  QList<GateSelectEntry> mEntries;
72  QSet<u32> mSelectableGates;
73 
74  public:
81  GateSelectModel(bool history, const QSet<u32>& selectable = QSet<u32>(), QObject* parent=nullptr);
82 
83  int rowCount(const QModelIndex &parent = QModelIndex()) const override;
84  int columnCount(const QModelIndex &parent = QModelIndex()) const override;
85  QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
86  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
87 
88  u32 gateId(int irow) const;
89  static bool isAccepted(u32 gateId, const QSet<u32>& selectable);
90  };
91 
96  {
97  Q_OBJECT
98 
99  public:
100  GateSelectProxy(QObject* parent = nullptr);
101 
102  public Q_SLOTS:
103  void setSortMechanism(gui_utility::mSortMechanism sortMechanism);
104  void searchTextChanged(const QString& txt);
105  void startSearch(QString text, int options);
106  bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const;
107 
108  protected:
109  bool lessThan(const QModelIndex &sourceLeft, const QModelIndex &sourceRight) const override;
110 
111  private:
112  gui_utility::mSortMechanism mSortMechanism;
113  };
114 
119  {
120  Q_OBJECT
121  public Q_SLOTS:
122  virtual void handleGatesPicked(const QSet<u32>& gats) = 0;
123  public:
125  virtual ~GateSelectReceiver() {;}
126  };
127 
131  class GateSelectPicker : public QObject
132  {
133  Q_OBJECT
134  QSet<u32> mSelectableGates;
135  QSet<u32> mGatesSelected;
136 
137  public:
138  GateSelectPicker(const QSet<u32>& selectable, GateSelectReceiver* receiver);
139 
140  Q_SIGNALS:
141  void triggerCursor(int icurs);
142  void gatesPicked(QSet<u32> gats);
143 
144  public Q_SLOTS:
145  void handleSelectionChanged(void* sender);
146  void terminatePicker();
147  };
148 
152  class GateSelectHistory : public QList<u32>
153  {
154  static GateSelectHistory* inst;
155  GateSelectHistory() {;}
156  public:
157  static GateSelectHistory* instance();
158  void add(u32 id);
159  };
160 
164  class GateSelectView : public QTableView
165  {
166  Q_OBJECT
167 
168  public:
175  GateSelectView(bool history, const QSet<u32>& selectable, QWidget* parent=nullptr);
176 
177  Q_SIGNALS:
178  void gateSelected(u32 gatId, bool doubleClick);
179 
180  private Q_SLOTS:
181  void handleCurrentChanged(const QModelIndex& current, const QModelIndex& previous);
182  void handleDoubleClick(const QModelIndex& index);
183  };
184 }
185 
Definition: gate.h:58
The GateSelectEntry class comprises a single entry of the module selection table.
u32 id() const
QVariant data(int icol) const
data returns data from requested column
GateSelectEntry(Gate *g)
The GateSelectHistory class singleton comprises a list of user selected modules.
static GateSelectHistory * instance()
The GateSelectModel class is the source model for module selection.
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
GateSelectModel(bool history, const QSet< u32 > &selectable=QSet< u32 >(), QObject *parent=nullptr)
GateSelectModel constructor.
u32 gateId(int irow) const
static bool isAccepted(u32 gateId, const QSet< u32 > &selectable)
int columnCount(const QModelIndex &parent=QModelIndex()) const override
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
int rowCount(const QModelIndex &parent=QModelIndex()) const override
The GateSelectPicker class instance gets spawned to pick module from graph.
GateSelectPicker(const QSet< u32 > &selectable, GateSelectReceiver *receiver)
void triggerCursor(int icurs)
void gatesPicked(QSet< u32 > gats)
void handleSelectionChanged(void *sender)
The GateSelectProxy class allows sorting and filtering of module tables.
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
void startSearch(QString text, int options)
GateSelectProxy(QObject *parent=nullptr)
void setSortMechanism(gui_utility::mSortMechanism sortMechanism)
void searchTextChanged(const QString &txt)
bool lessThan(const QModelIndex &sourceLeft, const QModelIndex &sourceRight) const override
virtual void handleGatesPicked(const QSet< u32 > &gats)=0
GateSelectReceiver(QObject *parent=nullptr)
The GateSelectView class is the table widget for module selection.
GateSelectView(bool history, const QSet< u32 > &selectable, QWidget *parent=nullptr)
GateSelectView constructor.
void gateSelected(u32 gatId, bool doubleClick)
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
DisplayRole
Orientation