HAL
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:
80  GateSelectModel(bool history, const QSet<u32>& selectable = QSet<u32>(), QObject* parent=nullptr);
81 
82  int rowCount(const QModelIndex &parent = QModelIndex()) const override;
83  int columnCount(const QModelIndex &parent = QModelIndex()) const override;
84  QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
85  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
86 
87  u32 gateId(int irow) const;
88  static bool isAccepted(u32 gateId, const QSet<u32>& selectable);
89  };
90 
95  {
96  Q_OBJECT
97 
98  public:
99  GateSelectProxy(QObject* parent = nullptr);
100 
101  public Q_SLOTS:
102  void setSortMechanism(gui_utility::mSortMechanism sortMechanism);
103  void searchTextChanged(const QString& txt);
104  void startSearch(QString text, int options);
105  bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const;
106 
107  protected:
108  bool lessThan(const QModelIndex &sourceLeft, const QModelIndex &sourceRight) const override;
109 
110  private:
111  gui_utility::mSortMechanism mSortMechanism;
112  };
113 
115  {
116  Q_OBJECT
117  public Q_SLOTS:
118  virtual void handleGatesPicked(const QSet<u32>& gats) = 0;
119  public:
121  virtual ~GateSelectReceiver() {;}
122  };
123 
127  class GateSelectPicker : public QObject
128  {
129  Q_OBJECT
130  QSet<u32> mSelectableGates;
131  QSet<u32> mGatesSelected;
132 
133  public:
134  GateSelectPicker(const QSet<u32>& selectable, GateSelectReceiver* receiver);
135 
136  Q_SIGNALS:
137  void triggerCursor(int icurs);
138  void gatesPicked(QSet<u32> gats);
139 
140  public Q_SLOTS:
141  void handleSelectionChanged(void* sender);
142  void terminatePicker();
143  };
144 
148  class GateSelectHistory : public QList<u32>
149  {
150  static GateSelectHistory* inst;
151  GateSelectHistory() {;}
152  public:
153  static GateSelectHistory* instance();
154  void add(u32 id);
155  };
156 
160  class GateSelectView : public QTableView
161  {
162  Q_OBJECT
163 
164  public:
170  GateSelectView(bool history, const QSet<u32>& selectable, QWidget* parent=nullptr);
171 
172  Q_SIGNALS:
173  void gateSelected(u32 gatId, bool doubleClick);
174 
175  private Q_SLOTS:
176  void handleCurrentChanged(const QModelIndex& current, const QModelIndex& previous);
177  void handleDoubleClick(const QModelIndex& index);
178  };
179 }
180 
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)
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
DisplayRole
Orientation