HAL  v4.5.0-83-g30c8f0afc
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 
5 #include "gui/gui_globals.h"
13 
14 #include <QApplication>
15 #include <QClipboard>
16 #include <QHeaderView>
17 #include <QMenu>
18 #include <QMouseEvent>
19 
20 namespace hal
21 {
22  SelectionTreeView::SelectionTreeView(QWidget* parent, bool isGrouping) : QTreeView(parent)
23  {
25  // all rows are plain single line text, so the view must not measure each of them separately
29 
30  mIsGrouping = isGrouping;
31 
33  setDragEnabled(true);
35  connect(this, &QTreeView::customContextMenuRequested, this, &SelectionTreeView::handleCustomContextMenuRequested);
36 
37  connect(this, &SelectionTreeView::itemDoubleClicked, this, &SelectionTreeView::handleTreeViewItemFocusClicked);
39  }
40 
42  {
43  setColumnWidth(0, 160);
44  setColumnWidth(1, 40);
45  setColumnWidth(2, 80);
47  }
48 
49  void SelectionTreeView::currentChanged(const QModelIndex& current, const QModelIndex& previous)
50  {
51  Q_UNUSED(previous);
52 
53  const ModuleItem* sti = current.isValid() ? itemFromIndex(current) : nullptr;
54 
56  }
57 
59  {
60  QPoint point = viewport()->mapFromGlobal(event->globalPos());
61  ;
62 
63  QModelIndex index = indexAt(point);
64 
65  if (index.isValid())
66  {
69  }
70  }
71 
73  {
74  SelectionTreeProxyModel* treeProxy = dynamic_cast<SelectionTreeProxyModel*>(model());
75  if (!treeProxy) return nullptr;
76 
77  // topmost element if no valid index given
78  QModelIndex proxyIndex = index.isValid() ? index : treeProxy->index(0, 0, rootIndex());
79 
80  if (!proxyIndex.isValid())
81  return nullptr;
82 
83  QModelIndex modelIndex = treeProxy->mapToSource(proxyIndex);
84  return static_cast<ModuleItem*>(modelIndex.internalPointer());
85  }
86 
88  {
89  Q_UNUSED(id);
90  update();
91  }
92 
93  void SelectionTreeView::handleCustomContextMenuRequested(const QPoint& point)
94  {
95  QModelIndex index = indexAt(point);
96 
97  if (index.isValid())
98  {
99  QMenu menu;
100 
101  ModuleItem* item = itemFromIndex(index);
102  u32 id = item->id();
104 
111 
113  type==ModuleItem::TreeItemType::Module ? std::vector<u32>({id}) : std::vector<u32>(),
114  type==ModuleItem::TreeItemType::Gate ? std::vector<u32>({id}) : std::vector<u32>(),
115  type==ModuleItem::TreeItemType::Net ? std::vector<u32>({id}) : std::vector<u32>());
116 
117  menu.exec(viewport()->mapToGlobal(point));
118  }
119  }
120 
121  void SelectionTreeView::populate(bool mVisible, u32 groupingId)
122  {
123  SelectionTreeProxyModel* treeProxy = dynamic_cast<SelectionTreeProxyModel*>(model());
124  if (!treeProxy) return;
125  ModuleModel* treeModel = dynamic_cast<ModuleModel*>(treeProxy->sourceModel());
126  if (!treeModel) return;
127 
128  if (treeProxy->isGraphicsBusy())
129  return;
131  selectionModel()->clear();
132 
133  if (!groupingId)
134  {
135  if(mVisible)
136  {
140  treeModel->populateTree(modIds, gateIds, netIds);
141  }
142  else treeModel->clear();
143  }
144  else
145  {
146  Grouping* grouping = gNetlist->get_grouping_by_id(groupingId);
150  treeModel->populateTree(modIds, gateIds, netIds);
151  }
152 
153  if (mVisible)
154  {
155  show();
157  QModelIndex defaultSel = treeProxy->index(0, 0, rootIndex());
158  if (defaultSel.isValid())
160  }
161  else
162  hide();
163  }
164 /*
165  void SelectionTreeView::handleFilterTextChanged(const QString& filter_text)
166  {
167  SelectionTreeProxyModel* treeProxy = dynamic_cast<SelectionTreeProxyModel*>(model());
168  if (!treeProxy) return;
169  treeProxy->handleFilterTextChanged(filter_text);
170  expandAll();
171  QModelIndex defaultSel = treeProxy->index(0, 0, rootIndex());
172  if (defaultSel.isValid())
173  selectionModel()->setCurrentIndex(defaultSel, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
174  }*/
175 
177  {
178  return dynamic_cast<SelectionTreeProxyModel*>(model());
179  }
180 
181  void SelectionTreeView::handleTreeViewItemFocusClicked(const ModuleItem* sti)
182  {
183  u32 itemId = sti->id();
184 
185  switch (sti->getType())
186  {
189  break;
192  break;
195  break;
196  default: break;
197  }
198  }
199 
200 } // 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:691
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:78
SelectionRelay * gSelectionRelay
Definition: plugin_gui.cpp:83
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)
QVector< T > fromList(const QList< T > &list)
QVector< T > fromStdVector(const std::vector< T > &vector)
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()