HAL
module_item.cpp
Go to the documentation of this file.
3 
5 
6 #include "gui/gui_globals.h"
8 
9 namespace hal
10 {
11 
13  BaseTreeItem(),
14  mId(id),
15  mItemType(type),
16  mHighlighted(false),
17  mModuleModel(model)
18  {
19  switch(type)
20  {
22  {
23  const Module* m = gNetlist->get_module_by_id(id);
24  Q_ASSERT(m);
25  mName = QString::fromStdString(m->get_name());
26  mModuleType = QString::fromStdString(m->get_type());
27  break;
28  }
29  case TreeItemType::Gate:
30  {
31  const Gate* g = gNetlist->get_gate_by_id(id);
32  Q_ASSERT(g);
33  mName = QString::fromStdString(g->get_name());
34  mModuleType = QString::fromStdString(g->get_type()->get_name());
35  break;
36  }
37  case TreeItemType::Net:
38  {
39  const Net* n = gNetlist->get_net_by_id(id);
40  Q_ASSERT(n);
41  mName = QString::fromStdString(n->get_name());
42  break;
43  }
44  }
45  mModuleModel->mModuleItemMaps[(int)mItemType]->insertMulti(id,this);
46  }
47 
49  {
50  auto it = mModuleModel->mModuleItemMaps[(int)mItemType]->lowerBound(mId);
51  while (it != mModuleModel->mModuleItemMaps[(int)mItemType]->upperBound(mId))
52  {
53  if (it.value() == this)
54  it = mModuleModel->mModuleItemMaps[(int)mItemType]->erase(it);
55  else
56  ++it;
57  }
58  }
59 
61  {
62  if(mItemType != TreeItemType::Module) // only module can have children
63  return;
64 
65  Module* m = gNetlist->get_module_by_id(mId);
66  Q_ASSERT(m);
67  for (Module* subm : m->get_submodules())
68  {
69  auto it = moduleMap.find(subm->get_id());
70  if (it != moduleMap.constEnd())
71  {
72  ModuleItem* childItem = it.value();
73  appendChild(childItem);
74  childItem->setParent(this);
75  }
76  }
77  }
78 
79  void ModuleItem::setModuleType(const QString &moduleType)
80  {
81  if (mItemType != TreeItemType::Module) return;
83  if (!module) return;
84  module->set_type(moduleType.toStdString());
85  mModuleType = moduleType;
86  }
87 
88  QVariant ModuleItem::getData(int column) const
89  {
90  // DEBUG CODE, USE STYLED DELEGATES OR SOMETHING
91  switch (column) {
92  case 0:
93  return mName;
94  case 1:
95  return mId;
96  case 2:
97  return mModuleType;
98  }
99  return QVariant();
100  }
101 
103  {
104  setName(data[0].toString());
105  if (mItemType == TreeItemType::Module)
106  setModuleType(data.at(2).toString());
107  }
108 
109  void ModuleItem::setDataAtIndex(int index, QVariant &data)
110  {
111  switch (index) {
112  case 0:
113  setName(data.toString());
114  return;
115  case 1:
116  return;
117  case 2:
118  setModuleType(data.toString());
119  return;
120  }
121  }
122 
124  {
125  return mName;
126  }
127 
129  {
130  return mId;
131  }
132 
134  {
135  return mHighlighted;
136  }
137 
139  {
140  if (dynamic_cast<RootTreeItem*>(mParent)) return true;
141  return false;
142  }
143 
145  return mItemType;
146  }
147 
149  {
150  mName = name;
151  }
152 
153  void ModuleItem::setHighlighted(const bool highlighted)
154  {
155  mHighlighted = highlighted;
156  }
157 
159  {
160  return 3;
161  }
162 
164  {
165  Q_UNUSED(data);
166  }
167 }
(Future) Base class for all tree models related to the details widget.
BaseTreeItem * mParent
virtual void appendChild(BaseTreeItem *child)
virtual void setParent(BaseTreeItem *parent)
Definition: gate.h:58
std::string get_name() const
Definition: module.cpp:87
void set_type(const std::string &type)
Definition: module.cpp:111
std::vector< Module * > get_submodules(const std::function< bool(Module *)> &filter=nullptr, bool recursive=false) const
Definition: module.cpp:259
std::string get_type() const
Definition: module.cpp:106
An item in the ModuleModel.
Definition: module_item.h:48
void setDataAtIndex(int index, QVariant &data) override
QVariant getData(int column) const override
Definition: module_item.cpp:88
void appendExistingChildIfAny(const QMap< u32, ModuleItem * > &moduleMap)
Definition: module_item.cpp:60
void setHighlighted(const bool highlighted)
void setData(QList< QVariant > data) override
bool isToplevelItem() const
int getColumnCount() const override
void appendData(QVariant data) override
void setName(const QString &name)
u32 id() const
QString name() const
bool highlighted() const
virtual ~ModuleItem()
Definition: module_item.cpp:48
TreeItemType getType() const
void setModuleType(const QString &moduleType)
Definition: module_item.cpp:79
ModuleItem(const u32 id, const TreeItemType type, ModuleModel *model)
Definition: module_item.cpp:12
A model for displaying multiple netlist elements.
Definition: module_model.h:54
Definition: net.h:58
Gate * get_gate_by_id(const u32 gate_id) const
Definition: netlist.cpp:193
Module * get_module_by_id(u32 module_id) const
Definition: netlist.cpp:613
Net * get_net_by_id(u32 net_id) const
Definition: netlist.cpp:353
const Module * module(const Gate *g, const NodeBoxes &boxes)
Netlist * gNetlist
Definition: plugin_gui.cpp:80
n
Definition: test.py:6
quint32 u32
PinType type
std::string name
i32 id
QMap::const_iterator constEnd() const const
QMap::iterator find(const Key &key)
QString fromStdString(const std::string &str)
std::string toStdString() const const