HAL  v4.5.0-133-g64838ea8d
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
selection_tree_view.cpp
Go to the documentation of this file.
2 
6 #include "gui/gui_globals.h"
14 
15 #include <QApplication>
16 #include <QClipboard>
17 #include <QHeaderView>
18 #include <QMenu>
19 #include <QMouseEvent>
20 
21 namespace hal
22 {
23  SelectionTreeView::SelectionTreeView(QWidget* parent, bool isGrouping) : QTreeView(parent)
24  {
26  // all rows are plain single line text, so the view must not measure each of them separately
30 
31  mIsGrouping = isGrouping;
32 
34  setDragEnabled(true);
36  connect(this, &QTreeView::customContextMenuRequested, this, &SelectionTreeView::handleCustomContextMenuRequested);
37 
38  connect(this, &SelectionTreeView::itemDoubleClicked, this, &SelectionTreeView::handleTreeViewItemFocusClicked);
40  }
41 
43  {
44  setColumnWidth(0, 160);
45  setColumnWidth(1, 40);
46  setColumnWidth(2, 80);
48  }
49 
50  void SelectionTreeView::currentChanged(const QModelIndex& current, const QModelIndex& previous)
51  {
52  Q_UNUSED(previous);
53 
54  const ModuleItem* sti = current.isValid() ? itemFromIndex(current) : nullptr;
55 
57  }
58 
60  {
61  QPoint point = viewport()->mapFromGlobal(event->globalPos());
62  ;
63 
64  QModelIndex index = indexAt(point);
65 
66  if (index.isValid())
67  {
70  }
71  }
72 
74  {
75  SelectionTreeProxyModel* treeProxy = dynamic_cast<SelectionTreeProxyModel*>(model());
76  if (!treeProxy) return nullptr;
77 
78  // topmost element if no valid index given
79  QModelIndex proxyIndex = index.isValid() ? index : treeProxy->index(0, 0, rootIndex());
80 
81  if (!proxyIndex.isValid())
82  return nullptr;
83 
84  QModelIndex modelIndex = treeProxy->mapToSource(proxyIndex);
85  return static_cast<ModuleItem*>(modelIndex.internalPointer());
86  }
87 
89  {
90  Q_UNUSED(id);
91  update();
92  }
93 
94  void SelectionTreeView::handleCustomContextMenuRequested(const QPoint& point)
95  {
96  QModelIndex index = indexAt(point);
97 
98  if (index.isValid())
99  {
100  QMenu menu;
101 
102  ModuleItem* item = itemFromIndex(index);
103  u32 id = item->id();
105 
112 
114  type==ModuleItem::TreeItemType::Module ? std::vector<u32>({id}) : std::vector<u32>(),
115  type==ModuleItem::TreeItemType::Gate ? std::vector<u32>({id}) : std::vector<u32>(),
116  type==ModuleItem::TreeItemType::Net ? std::vector<u32>({id}) : std::vector<u32>());
117 
118  menu.exec(viewport()->mapToGlobal(point));
119  }
120  }
121 
122  void SelectionTreeView::populate(bool mVisible, u32 groupingId)
123  {
124  SelectionTreeProxyModel* treeProxy = dynamic_cast<SelectionTreeProxyModel*>(model());
125  if (!treeProxy) return;
126  ModuleModel* treeModel = dynamic_cast<ModuleModel*>(treeProxy->sourceModel());
127  if (!treeModel) return;
128 
129  if (treeProxy->isGraphicsBusy())
130  return;
132  selectionModel()->clear();
133 
134  if (!groupingId)
135  {
136  if(mVisible)
137  {
138  QVector<u32> modIds = QtCompat::listToVector<u32>(gSelectionRelay->selectedModulesList());
139  QVector<u32> gateIds = QtCompat::listToVector<u32>(gSelectionRelay->selectedGatesList());
140  QVector<u32> netIds = QtCompat::listToVector<u32>(gSelectionRelay->selectedNetsList());
141  treeModel->populateTree(modIds, gateIds, netIds);
142  }
143  else treeModel->clear();
144  }
145  else
146  {
147  Grouping* grouping = gNetlist->get_grouping_by_id(groupingId);
148  QVector<u32> modIds = QtCompat::stdVectorToVector<u32>(grouping->get_module_ids());
149  QVector<u32> gateIds = QtCompat::stdVectorToVector<u32>(grouping->get_gate_ids());
150  QVector<u32> netIds = QtCompat::stdVectorToVector<u32>(grouping->get_net_ids());
151  treeModel->populateTree(modIds, gateIds, netIds);
152  }
153 
154  if (mVisible)
155  {
156  show();
158  QModelIndex defaultSel = treeProxy->index(0, 0, rootIndex());
159  if (defaultSel.isValid())
161  }
162  else
163  hide();
164  }
165 /*
166  void SelectionTreeView::handleFilterTextChanged(const QString& filter_text)
167  {
168  SelectionTreeProxyModel* treeProxy = dynamic_cast<SelectionTreeProxyModel*>(model());
169  if (!treeProxy) return;
170  treeProxy->handleFilterTextChanged(filter_text);
171  expandAll();
172  QModelIndex defaultSel = treeProxy->index(0, 0, rootIndex());
173  if (defaultSel.isValid())
174  selectionModel()->setCurrentIndex(defaultSel, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
175  }*/
176 
178  {
179  return dynamic_cast<SelectionTreeProxyModel*>(model());
180  }
181 
182  void SelectionTreeView::handleTreeViewItemFocusClicked(const ModuleItem* sti)
183  {
184  u32 itemId = sti->id();
185 
186  switch (sti->getType())
187  {
190  break;
193  break;
196  break;
197  default: break;
198  }
199  }
200 
201 } // namespace hal
GraphTabWidget * getGraphTabWidget()
Get hal's graph tab widget.
void handleGateFocus(u32 gateId)
void handleNetFocus(u32 netId)
void handleModuleFocus(u32 moduleId)
std::vector< u32 > get_gate_ids(const std::function< bool(Gate *)> &filter=nullptr) const
Definition: grouping.cpp:113
std::vector< u32 > get_module_ids(const std::function< bool(Module *)> &filter=nullptr) const
Definition: grouping.cpp:287
std::vector< u32 > get_net_ids(const std::function< bool(Net *)> &filter=nullptr) const
Definition: grouping.cpp:200
static void addPluginSubmenus(QMenu *contextMenu, Netlist *netlist, const std::vector< u32 > &modules, const std::vector< u32 > &gates, const std::vector< u32 > &nets)
void moduleColorChanged(u32 id) const
static void addModuleSubmenu(QMenu *contextMenu, u32 id)
static void addGateSubmenu(QMenu *contextMenu, u32 id)
static void addNetSubmenu(QMenu *contextMenu, u32 id)
An item in the ModuleModel.
Definition: module_item.h:48
u32 id() const
TreeItemType getType() const
A model for displaying multiple netlist elements.
Definition: module_model.h:54
void clear() override
void populateTree(const QVector< u32 > &modIds={}, const QVector< u32 > &gatIds={}, const QVector< u32 > &netIds={})
Grouping * get_grouping_by_id(u32 grouping_id) const
Definition: netlist.cpp:693
ModuleColorManager * getModuleColorManager() const
QList< u32 > selectedModulesList() const
QList< u32 > selectedNetsList() const
QList< u32 > selectedGatesList() const
Enables filtering of the SelectionTreeModel.
virtual void mouseDoubleClickEvent(QMouseEvent *event) override
void populate(bool mVisible, u32 groupingId=0)
void itemDoubleClicked(const ModuleItem *sti)
virtual void currentChanged(const QModelIndex &current, const QModelIndex &previous) override
SelectionTreeView(QWidget *parent=nullptr, bool isGrouping=false)
SelectionTreeProxyModel * proxyModel()
ModuleItem * itemFromIndex(const QModelIndex &index=QModelIndex()) const
void triggerSelection(const ModuleItem *sti)
uint32_t u32
Definition: defines.h:41
Definition: defines.h:45
ContentManager * gContentManager
Definition: plugin_gui.cpp:79
SelectionRelay * gSelectionRelay
Definition: plugin_gui.cpp:84
Netlist * gNetlist
Definition: gui_globals.h:69
NetlistRelay * gNetlistRelay
Definition: gui_globals.h:74
PinType type
void setDragDropMode(QAbstractItemView::DragDropMode behavior)
void setDragEnabled(bool enable)
virtual bool event(QEvent *event) override
QAbstractItemModel * model() const const
QModelIndex rootIndex() const const
void setSelectionMode(QAbstractItemView::SelectionMode mode)
QItemSelectionModel * selectionModel() const const
QWidget * viewport() const const
void setDefaultAlignment(Qt::Alignment alignment)
void setStretchLastSection(bool stretch)
virtual void clear()
virtual void setCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command)
QAction * exec()
void * internalPointer() const const
bool isValid() const const
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const override
virtual QModelIndex mapToSource(const QModelIndex &proxyIndex) const const override
AlignHCenter
CustomContextMenu
QHeaderView * header() const const
virtual QModelIndex indexAt(const QPoint &point) const const override
void setColumnWidth(int column, int width)
void setUniformRowHeights(bool uniform)
void setContextMenuPolicy(Qt::ContextMenuPolicy policy)
void customContextMenuRequested(const QPoint &pos)
void hide()
QPoint mapFromGlobal(const QPoint &pos) const const
QPoint mapToGlobal(const QPoint &pos) const const
void show()
void setSizePolicy(QSizePolicy)
void update()