HAL  v4.5.0-83-g30c8f0afc
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
endpoint_table_model.cpp
Go to the documentation of this file.
2 
3 #include "gui/gui_globals.h"
4 #include "hal_core/netlist/net.h"
5 
6 namespace hal
7 {
8 
10  {
11  }
12 
14  {
16  mEntries.clear();
17  endResetModel();
18  }
19 
20  int EndpointTableModel::rowCount(const QModelIndex& parent) const
21  {
22  Q_UNUSED(parent)
23 
24  return mEntries.size();
25  }
26 
28  {
29  Q_UNUSED(parent)
30 
31  return 4;
32  }
33 
35  {
36  if (index.row() < mEntries.size() && index.column() < 4)
37  {
38  if (role == Qt::DisplayRole)
39  {
40  switch (index.column())
41  {
42  case 0:
43  return mEntries[index.row()].name;
44  case 1:
45  return mEntries[index.row()].id;
46  case 2:
47  return mEntries[index.row()].type;
48  case 3:
49  return mEntries[index.row()].pin;
50  }
51  }
52  }
53 
54  return QVariant();
55  }
56 
57  QVariant EndpointTableModel::headerData(int section, Qt::Orientation orientation, int role) const
58  {
59  if (role != Qt::DisplayRole)
60  return QVariant();
61 
62  if (orientation == Qt::Horizontal)
63  {
64  switch (section)
65  {
66  case 0:
67  return "Name";
68  case 1:
69  return "ID";
70  case 2:
71  return "Type";
72  case 3:
73  return "Pin";
74  default:
75  return QVariant();
76  }
77  }
78 
79  return section + 1;
80  }
81 
83  {
84  if (net == nullptr)
85  return;
86 
87  mNetId = net->get_id();
88 
89  QList<Entry> newEntryList;
90 
91  std::vector<Endpoint*> v;
92 
93  if (mType == Type::source)
94  v = net->get_sources();
95  else
96  v = net->get_destinations();
97 
98  for (Endpoint* e : v)
99  {
100  Entry newEntry;
101 
102  newEntry.name = QString::fromStdString(e->get_gate()->get_name());
103  newEntry.id = e->get_gate()->get_id();
104  newEntry.type = QString::fromStdString(e->get_gate()->get_type()->get_name());
105  newEntry.pin = QString::fromStdString(e->get_pin()->get_name());
106 
107  newEntryList.append(newEntry);
108  }
109 
110  beginResetModel();
111  mEntries = newEntryList;
112  endResetModel();
113  }
114 
116  {
117  return mNetId;
118  }
119 
121  {
122  return mEntries[index.row()].id;
123  }
124 
126  {
127  return mEntries.at(index.row()).pin;
128  }
129 
131  {
132  if (mType == source)
133  return "Source";
134  else
135  return "Destination";
136  }
137 
139  {
140  return mType;
141  }
142 } // namespace hal
QVariant data(const QModelIndex &index, int role) const override
u32 getGateIDFromIndex(const QModelIndex &index)
QString getPinNameFromIndex(const QModelIndex &index)
int rowCount(const QModelIndex &parent=QModelIndex()) const override
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
EndpointTableModel(Type type, QObject *parent=nullptr)
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Definition: net.h:58
uint32_t u32
Definition: defines.h:41
Definition: defines.h:45
PinType type
Net * net
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const override
void append(const T &value)
const T & at(int i) const const
void clear()
int size() const const
int column() const const
int row() const const
QObject * parent() const const
QString fromStdString(const std::string &str)
DisplayRole
Orientation