HAL  v4.5.0-83-g30c8f0afc
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
module_elements_tree.cpp
Go to the documentation of this file.
3 #include "gui/gui_globals.h"
6 
7 #include <QMenu>
8 #include <QHeaderView>
9 #include <QApplication>
10 #include <QClipboard>
11 
12 namespace hal
13 {
14 
15  ModuleElementsTree::ModuleElementsTree(QWidget *parent) : QTreeView(parent), mModuleID(-1)
16  {
19  // all rows are plain single line text, so the view must not measure each of them separately
25  mProxyModel = new FilterElementsProxyModel(this);
26  mModel = new ModuleModel(mProxyModel);
27  mProxyModel->setSourceModel(mModel);
28  mProxyModel->setFilterNets(true);
29  setModel(mProxyModel);
30 
31  //connections
33  //connect(mModel, &ModuleTreeModel::numberOfSubmodulesChanged, this, &ModuleElementsTree::handleNumberSubmodulesChanged);
34  }
35 
37  {
38  Module* m = gNetlist->get_module_by_id(moduleID);
39  if(!m) return;
40 
41  setModule(m);
42  }
43 
45  {
46  if(!m) return;
47 
48  // One selection change sets the same module twice, once directly from SelectionDetailsWidget and once
49  // through the selection tree it populates on the way. Rebuilding the tree of a large module is
50  // expensive, so skip it if that module is already on display. The model keeps itself up to date
51  // through the netlist relay, the rebuild is not what refreshes it.
52  if (mModuleID == (int)m->get_id() && mModel->getItem(m->get_id()) != nullptr)
53  return;
54 
55  mModel->populateTree({m->get_id()});
56  setRootIndex(mProxyModel->mapFromSource(mModel->getIndexFromItem(mModel->getItem(m->get_id())))); // hide top-element m in TreeView
57 
58  mModuleID = m->get_id();
59  }
60 
62  {
63  mModel->clear();
64  mModuleID = -1;
65  }
66 
68  {
69  QModelIndex clickedIndex = indexAt(pos);
70  if(!clickedIndex.isValid())
71  return;
72 
73  ModuleItem* clickedItem = dynamic_cast<ModuleItem*>(mModel->getItemFromIndex(mProxyModel->mapToSource(clickedIndex)));
74  u32 id = clickedItem->id();
75  ModuleItem::TreeItemType type = clickedItem->getType();
76  QMenu menu;
77 
84 
86  type==ModuleItem::TreeItemType::Module ? std::vector<u32>({id}) : std::vector<u32>(),
87  type==ModuleItem::TreeItemType::Gate ? std::vector<u32>({id}) : std::vector<u32>(),
88  type==ModuleItem::TreeItemType::Net ? std::vector<u32>({id}) : std::vector<u32>());
89 
90  menu.exec(this->viewport()->mapToGlobal(pos));
91  }
92 
93  void ModuleElementsTree::handleNumberSubmodulesChanged(const int number)
94  {
95  Q_EMIT updateText(QString("Submodules(%1)").arg(number));
96  }
97 }
QModelIndex getIndexFromItem(BaseTreeItem *item) const
BaseTreeItem * getItemFromIndex(QModelIndex index) const
Enables filtering of nets or gates in the ModuleModel.
static void addPluginSubmenus(QMenu *contextMenu, Netlist *netlist, const std::vector< u32 > &modules, const std::vector< u32 > &gates, const std::vector< u32 > &nets)
static void addModuleSubmenu(QMenu *contextMenu, u32 id)
static void addGateSubmenu(QMenu *contextMenu, u32 id)
static void addNetSubmenu(QMenu *contextMenu, u32 id)
void handleContextMenuRequested(const QPoint &pos)
void updateText(const QString &newHeadline)
ModuleElementsTree(QWidget *parent=nullptr)
u32 get_id() const
Definition: module.cpp:82
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
ModuleItem * getItem(const QModelIndex &index) const
void clear() override
void populateTree(const QVector< u32 > &modIds={}, const QVector< u32 > &gatIds={}, const QVector< u32 > &netIds={})
Module * get_module_by_id(u32 module_id) const
Definition: netlist.cpp:613
uint32_t u32
Definition: defines.h:41
Definition: defines.h:45
Netlist * gNetlist
Definition: gui_globals.h:69
PinType type
void setSelectionBehavior(QAbstractItemView::SelectionBehavior behavior)
void setSelectionMode(QAbstractItemView::SelectionMode mode)
QWidget * viewport() const const
void setStretchLastSection(bool stretch)
QAction * exec()
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 mapFromSource(const QModelIndex &sourceIndex) const const override
virtual QModelIndex mapToSource(const QModelIndex &proxyIndex) const const override
virtual void setSourceModel(QAbstractItemModel *sourceModel) override
CustomContextMenu
QHeaderView * header() const const
virtual QModelIndex indexAt(const QPoint &point) const const override
virtual void setModel(QAbstractItemModel *model) override
virtual void setRootIndex(const QModelIndex &index) override
void setUniformRowHeights(bool uniform)
void setContextMenuPolicy(Qt::ContextMenuPolicy policy)
void customContextMenuRequested(const QPoint &pos)
void setFocusPolicy(Qt::FocusPolicy policy)
QPoint mapToGlobal(const QPoint &pos) const const
void setSizePolicy(QSizePolicy)