HAL  v4.5.0-83-g30c8f0afc
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
grouping_table_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 <QAbstractTableModel>
29 #include <QString>
30 #include <QColor>
31 #include <QTableView>
32 #include <QList>
33 
34 #include "hal_core/defines.h"
38 
39 namespace hal {
40 
49  {
50  Grouping* mGrouping;
51  public:
58  GroupingTableEntry(const QString& n); // constructor for new grouping
59 
66  GroupingTableEntry(u32 existingId); // entry wraps existing group object
67 
75  : mGrouping(grp) {;}
76 
82  u32 id() const;
83 
89  QString name() const;
90 
96  QColor color() const;
97 
103  void setName(const QString& n);
104 
110  void setColor(const QColor& c);
111 
117  Grouping* grouping() const { return mGrouping; }
118  };
119 
128  {
129  Q_OBJECT
130 
131  bool mDisableEvents;
132 
133  QList<GroupingTableEntry> mGroupings;
134  QString mAboutToRename;
135  bool mIsHistory = false;
136 
137  static QString generateUniqueName(const QString& suggestion, const QSet<QString>& existingNames);
138  public:
145  GroupingTableModel(bool history, QObject* parent=nullptr);
146 
153  int columnCount(const QModelIndex &parent=QModelIndex()) const override;
154 
161  int rowCount(const QModelIndex &parent=QModelIndex()) const override;
162 
170  QVariant data(const QModelIndex &index, int role) const override;
171 
180  QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
181 
190  bool setData(const QModelIndex &index, const QVariant &value, int role) override;
191 
200  bool removeRows(int row, int count=1, const QModelIndex &parent=QModelIndex()) override;
201 
209  bool validate(const QString &input);
210 
218  void setAboutToRename(const QString& oldName) { mAboutToRename = oldName.trimmed(); }
219 
226  GroupingTableEntry groupingAt(int irow) const { return mGroupings.at(irow); }
227 
234 
241  Grouping* groupingByName(const QString& name) const;
242 
251  QColor colorForItem(ItemType itemType, u32 itemId) const;
252 
259  QColor colorForGrouping(Grouping* grouping) const;
260 
268  QString renameGrouping(u32 id, const QString& groupingName);
269 
275  QStringList groupingNames() const;
276 
277  public Q_SLOTS:
283  void deleteGroupingEvent(Grouping* grp);
284 
292  QColor recolorGrouping(u32 id, const QColor& groupingColor);
293 
299  void createGroupingEvent(Grouping *grp);
300 
307 
314 
315  Q_SIGNALS:
323 
329 
336 
337  };
338 
342  class GroupingTableHistory : public QList<u32>
343  {
344  static GroupingTableHistory* inst;
346 
347  static const int sMaxEntries;
348  public:
349  static GroupingTableHistory* instance();
350  void add(u32 id);
351  };
352 
357  {
358  Q_OBJECT
359 
360  public:
361  GroupingTableView(bool history, QWidget* parent=nullptr);
362 
363  Q_SIGNALS:
364  void groupingSelected(u32 id, bool doubleClick);
365 
366  private Q_SLOTS:
367  void handleDoubleClick(const QModelIndex& index);
368  void handleSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
369  };
370 }
An entry within a GroupingTableModel.
Grouping * grouping() const
void setColor(const QColor &c)
GroupingTableEntry(Grouping *grp)
QString name() const
void setName(const QString &n)
GroupingTableEntry(const QString &n)
QColor color() const
u32 id() const
static GroupingTableHistory * instance()
Table that holds information about all groupings.
QColor colorForGrouping(Grouping *grouping) const
int columnCount(const QModelIndex &parent=QModelIndex()) const override
void setAboutToRename(const QString &oldName)
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
GroupingTableModel(bool history, QObject *parent=nullptr)
QString renameGrouping(u32 id, const QString &groupingName)
bool validate(const QString &input)
bool setData(const QModelIndex &index, const QVariant &value, int role) override
void createGroupingEvent(Grouping *grp)
void groupingColorChangedEvent(Grouping *grp)
QVariant data(const QModelIndex &index, int role) const override
void groupingColorChanged(Grouping *grp)
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Grouping * groupingByName(const QString &name) const
void groupingNameChangedEvent(Grouping *grp)
bool removeRows(int row, int count=1, const QModelIndex &parent=QModelIndex()) override
void newEntryAdded(QModelIndex &index)
GroupingTableEntry groupingAt(int irow) const
QStringList groupingNames() const
QColor recolorGrouping(u32 id, const QColor &groupingColor)
void deleteGroupingEvent(Grouping *grp)
QColor colorForItem(ItemType itemType, u32 itemId) const
GroupingTableView(bool history, QWidget *parent=nullptr)
void groupingSelected(u32 id, bool doubleClick)
Base class for any string validator.
Definition: validator.h:41
uint32_t u32
Definition: defines.h:41
ItemType
The ItemType enum provides the enum type to classify graphic items into Modules, Gates or Nets....
Definition: gui_def.h:45
Definition: defines.h:45
std::string name
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const override
const T & at(int i) const const
Q_OBJECTQ_OBJECT
Q_SIGNALSQ_SIGNALS
Q_SLOTSQ_SLOTS
QObject * parent() const const
QString trimmed() const const
Orientation