HAL
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 
76  : mGrouping(grp) {;}
77 
83  u32 id() const;
84 
90  QString name() const;
91 
97  QColor color() const;
98 
104  void setName(const QString& n);
105 
111  void setColor(const QColor& c);
112 
118  Grouping* grouping() const { return mGrouping; }
119  };
120 
129  {
130  Q_OBJECT
131 
132  bool mDisableEvents;
133 
134  QList<GroupingTableEntry> mGroupings;
135  QString mAboutToRename;
136  bool mIsHistory = false;
137 
138  static QString generateUniqueName(const QString& suggestion, const QSet<QString>& existingNames);
139  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 
339  class GroupingTableHistory : public QList<u32>
340  {
341  static GroupingTableHistory* inst;
343 
344  static const int sMaxEntries;
345  public:
346  static GroupingTableHistory* instance();
347  void add(u32 id);
348  };
349 
351  {
352  Q_OBJECT
353 
354  public:
355  GroupingTableView(bool history, QWidget* parent=nullptr);
356 
357  Q_SIGNALS:
358  void groupingSelected(u32 id, bool doubleClick);
359 
360  private Q_SLOTS:
361  void handleDoubleClick(const QModelIndex& index);
362  void handleSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
363  };
364 }
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
ItemType
The ItemType enum provides the enum type to classify graphic items into Modules, Gates or Nets....
Definition: gui_def.h:45
n
Definition: test.py:6
quint32 u32
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