HAL
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  {
27 
28  mIsGrouping = isGrouping;
29 
31  setDragEnabled(true);
33  connect(this, &QTreeView::customContextMenuRequested, this, &SelectionTreeView::handleCustomContextMenuRequested);
34 
35  connect(this, &SelectionTreeView::itemDoubleClicked, this, &SelectionTreeView::handleTreeViewItemFocusClicked);
37  }
38 
40  {
41  setColumnWidth(0, 160);
42  setColumnWidth(1, 40);
43  setColumnWidth(2, 80);
45  }
46 
47  void SelectionTreeView::currentChanged(const QModelIndex& current, const QModelIndex& previous)
48  {
49  Q_UNUSED(previous);
50 
51  const ModuleItem* sti = current.isValid() ? itemFromIndex(current) : nullptr;
52 
54  }
55 
57  {
58  QPoint point = viewport()->mapFromGlobal(event->globalPos());
59  ;
60 
61  QModelIndex index = indexAt(point);
62 
63  if (index.isValid())
64  {
65  ModuleItem* item = itemFromIndex(index);
67  }
68  }
69 
71  {
72  SelectionTreeProxyModel* treeProxy = dynamic_cast<SelectionTreeProxyModel*>(model());
73  if (!treeProxy) return nullptr;
74 
75  // topmost element if no valid index given
76  QModelIndex proxyIndex = index.isValid() ? index : treeProxy->index(0, 0, rootIndex());
77 
78  if (!proxyIndex.isValid())
79  return nullptr;
80 
81  QModelIndex modelIndex = treeProxy->mapToSource(proxyIndex);
82  return static_cast<ModuleItem*>(modelIndex.internalPointer());
83  }
84 
86  {
87  Q_UNUSED(id);
88  update();
89  }
90 
91  void SelectionTreeView::handleCustomContextMenuRequested(const QPoint& point)
92  {
93  QModelIndex index = indexAt(point);
94 
95  if (index.isValid())
96  {
97  QMenu menu;
98 
99  ModuleItem* item = itemFromIndex(index);
100  u32 id = item->id();
102 
109 
111  type==ModuleItem::TreeItemType::Module ? std::vector<u32>({id}) : std::vector<u32>(),
112  type==ModuleItem::TreeItemType::Gate ? std::vector<u32>({id}) : std::vector<u32>(),
113  type==ModuleItem::TreeItemType::Net ? std::vector<u32>({id}) : std::vector<u32>());
114 
115  menu.exec(viewport()->mapToGlobal(point));
116  }
117  }
118 
119  void SelectionTreeView::populate(bool mVisible, u32 groupingId)
120  {
121  SelectionTreeProxyModel* treeProxy = dynamic_cast<SelectionTreeProxyModel*>(model());
122  if (!treeProxy) return;
123  ModuleModel* treeModel = dynamic_cast<ModuleModel*>(treeProxy->sourceModel());
124  if (!treeModel) return;
125 
126  if (treeProxy->isGraphicsBusy())
127  return;
129  selectionModel()->clear();
130 
131  if (!groupingId)
132  {
133  if(mVisible)
134  {
138  treeModel->populateTree(modIds, gateIds, netIds);
139  }
140  else treeModel->clear();
141  }
142  else
143  {
144  Grouping* grouping = gNetlist->get_grouping_by_id(groupingId);
148  treeModel->populateTree(modIds, gateIds, netIds);
149  }
150 
151  if (mVisible)
152  {
153  show();
155  QModelIndex defaultSel = treeProxy->index(0, 0, rootIndex());
156  if (defaultSel.isValid())
158  }
159  else
160  hide();
161  }
162 /*
163  void SelectionTreeView::handleFilterTextChanged(const QString& filter_text)
164  {
165  SelectionTreeProxyModel* treeProxy = dynamic_cast<SelectionTreeProxyModel*>(model());
166  if (!treeProxy) return;
167  treeProxy->handleFilterTextChanged(filter_text);
168  expandAll();
169  QModelIndex defaultSel = treeProxy->index(0, 0, rootIndex());
170  if (defaultSel.isValid())
171  selectionModel()->setCurrentIndex(defaultSel, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
172  }*/
173 
175  {
176  return dynamic_cast<SelectionTreeProxyModel*>(model());
177  }
178 
179  void SelectionTreeView::handleTreeViewItemFocusClicked(const ModuleItem* sti)
180  {
181  u32 itemId = sti->id();
182 
183  switch (sti->getType())
184  {
187  break;
190  break;
193  break;
194  default: break;
195  }
196  }
197 
198 } // 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 handleModuleColorChanged(u32 id)
void handleFilterTextChanged(const QString& filter_text);
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)
ContentManager * gContentManager
Definition: plugin_gui.cpp:78
SelectionRelay * gSelectionRelay
Definition: plugin_gui.cpp:83
Netlist * gNetlist
Definition: plugin_gui.cpp:80
NetlistRelay * gNetlistRelay
Definition: plugin_gui.cpp:81
quint32 u32
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)
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()