HAL  v4.5.0-83-g30c8f0afc
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
gate_selection_dialog.cpp
Go to the documentation of this file.
2 
4 #include <QGridLayout>
5 #include <QPushButton>
6 #include <QDialogButtonBox>
7 #include <QTableView>
8 #include <QHeaderView>
9 
10 #include "gui/gui_globals.h"
11 
12 namespace hal {
13 
14 
16  : QDialog(parent)
17  {
18  QGridLayout* layout = new QGridLayout(this);
19  mButAll = new QPushButton("All gates", this);
20  connect(mButAll,&QPushButton::clicked,this,&GateSelectionDialog::handleSelectAll);
21  layout->addWidget(mButAll,0,0);
22  mButSel = new QPushButton("Current GUI selection", this);
23  connect(mButSel,&QPushButton::clicked,this,&GateSelectionDialog::handleCurrentGuiSelection);
24  layout->addWidget(mButSel,0,1);
25  mButNone = new QPushButton("Clear selection", this);
26  connect(mButNone,&QPushButton::clicked,this,&GateSelectionDialog::handleClearSelection);
27  layout->addWidget(mButNone,0,2);
28  mTableView = new QTableView(this);
29 
32 
33  GateSelectProxy* prox = new GateSelectProxy(this);
34  // connect(sbar, &Searchbar::textEdited, prox, &GateSelectProxy::searchTextChanged);
35 
36  GateSelectModel* modl = new GateSelectModel(false,QSet<u32>(),mTableView);
37  prox->setSourceModel(modl);
38  mTableView->setModel(prox);
39 
40  // connect(selectionModel(), &QItemSelectionModel::currentChanged, this, &GateSelectView::handleCurrentChanged);
41  mTableView->setSortingEnabled(true);
42  mTableView->sortByColumn(2, Qt::AscendingOrder);
43  mTableView->resizeColumnsToContents();
44  mTableView->horizontalHeader()->setStretchLastSection(true);
45  mTableView->verticalHeader()->hide();
46  layout->addWidget(mTableView,1,0,1,3);
50  layout->addWidget(mButtonBox,2,1,1,2);
51  }
52 
53  void GateSelectionDialog::handleSelectAll()
54  {
55  mTableView->selectAll();
56  }
57 
58  void GateSelectionDialog::handleCurrentGuiSelection()
59  {
60  QSet<u32> guiGateSel = gSelectionRelay->selectedGates();
61 
62  const QAbstractItemModel* modl = mTableView->model(); // proxy model
63  int nrows = modl->rowCount();
64  mTableView->clearSelection();
65 
66  bool ok;
67 
68  for (int irow = 0; irow<nrows; irow++)
69  {
70  u32 gid = modl->data(modl->index(irow,0)).toUInt(&ok);
71  if (!ok) continue;
72  if (guiGateSel.contains(gid))
73  mTableView->selectRow(irow);
74  }
75  }
76 
77  void GateSelectionDialog::handleClearSelection()
78  {
79  mTableView->clearSelection();
80  }
81 
82  std::vector<Gate*> GateSelectionDialog::selectedGates() const
83  {
84  std::vector<Gate*> retval;
85  QItemSelectionModel *sm = mTableView->selectionModel();
86  if (!sm->hasSelection()) return retval;
87  QSet<u32> selGates;
88  bool ok;
89  for (const QModelIndex& inx : sm->selectedRows(0))
90  {
91  u32 gid = mTableView->model()->data(inx).toUInt(&ok);
92  if (!ok) continue;
93  selGates.insert(gid);
94  }
95 
96  for (u32 gid: selGates)
97  {
98  Gate* g = gNetlist->get_gate_by_id(gid);
99  if (g) retval.push_back(g);
100  }
101  return retval;
102  }
103 }
Definition: gate.h:58
The GateSelectModel class is the source model for module selection.
The GateSelectProxy class allows sorting and filtering of module tables.
std::vector< Gate * > selectedGates() const
GateSelectionDialog(QWidget *parent=nullptr)
Gate * get_gate_by_id(const u32 gate_id) const
Definition: netlist.cpp:193
const QSet< u32 > & selectedGates() const
uint32_t u32
Definition: defines.h:41
Definition: defines.h:45
SelectionRelay * gSelectionRelay
Definition: plugin_gui.cpp:83
Netlist * gNetlist
Definition: gui_globals.h:69
void clicked(bool checked)
virtual QVariant data(const QModelIndex &index, int role) const const=0
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const=0
virtual int rowCount(const QModelIndex &parent) const const=0
QAbstractItemModel * model() const const
virtual void selectAll()
void setSelectionBehavior(QAbstractItemView::SelectionBehavior behavior)
void setSelectionMode(QAbstractItemView::SelectionMode mode)
QItemSelectionModel * selectionModel() const const
virtual void accept()
virtual void reject()
void setStretchLastSection(bool stretch)
bool hasSelection() const const
QModelIndexList selectedRows(int column) const const
void addWidget(QWidget *w)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
bool contains(const T &value) const const
QSet::iterator insert(const T &value)
virtual void setSourceModel(QAbstractItemModel *sourceModel) override
AscendingOrder
void sortByColumn(int column)
QHeaderView * horizontalHeader() const const
void resizeColumnsToContents()
void selectRow(int row)
virtual void setModel(QAbstractItemModel *model) override
void setSortingEnabled(bool enable)
QHeaderView * verticalHeader() const const
uint toUInt(bool *ok) const const
void hide()
QLayout * layout() const const