HAL
gate_dialog.cpp
Go to the documentation of this file.
1 
4 #include "gui/gui_globals.h"
12 
13 #include <QDialogButtonBox>
14 #include <QGridLayout>
15 #include <QPushButton>
16 #include <QTabWidget>
17 #include <QTableView>
18 #include <QTreeView>
19 
20 namespace hal {
21  GateDialog::GateDialog(const QSet<u32> &selectable, const QString &title, GateSelectReceiver* receiver, QWidget* parent)
22  : QDialog(parent), mSelectedId(0), mReceiver(receiver),
23  mSelectableGates(selectable), mPickerModeActivated(false), mWindowTitle(title)
24  {
25  setWindowTitle(mWindowTitle + " …");
26  QGridLayout* layout = new QGridLayout(this);
27 
28  mButtonPick = new QPushButton("Pick gate from graph", this);
29  connect(mButtonPick, &QPushButton::pressed, this, &GateDialog::handlePickFromGraph);
30  layout->addWidget(mButtonPick, 0, 1);
31 
32  mSearchbar = new Searchbar(this);
33  layout->addWidget(mSearchbar, 1, 0, 1, 2);
34 
35  mTabWidget = new QTabWidget(this);
36 // mTreeView = new QTreeView(mTabWidget);
37 // mTabWidget->addTab(mTreeView, "Gate tree");
38 
39  mTableView = new GateSelectView(false,selectable,mTabWidget);
40  mGateTableProxyModel = static_cast<GateSelectProxy*>(mTableView->model());
42  mTabWidget->addTab(mTableView, "Gate list");
43 
44  if (!GateSelectHistory::instance()->isEmpty())
45  {
46  mLastUsed = new GateSelectView(true,selectable,mTabWidget);
47  if (mLastUsed->model()->rowCount())
48  {
50  mTabWidget->addTab(mLastUsed, "Recent selection");
51  }
52  else
53  delete mLastUsed;
54  }
55 
56  layout->addWidget(mTabWidget, 2, 0, 1, 2);
57 
58  /*
59  *
60  * TODO : tree view
61  mGateTreeProxyModel = new GateProxyModel(this);
62  mGateTreeProxyModel->setFilterKeyColumn(-1);
63  mGateTreeProxyModel->setDynamicSortFilter(true);
64  mGateTreeProxyModel->setSourceModel(gNetlistRelay->getGateModel());
65  //mGateProxyModel->setRecursiveFilteringEnabled(true);
66  mGateTreeProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
67  mTreeView->setModel(mGateTreeProxyModel);
68 */
69 
71  layout->addWidget(mButtonBox, 3, 1);
72 
73  mToggleSearchbar = new QAction(this);
74  mToggleSearchbar->setShortcut(QKeySequence(ContentManager::sSettingSearch->value().toString()));
75  addAction(mToggleSearchbar);
76 
77  mTabWidget->setCurrentIndex(1);
78  enableButtons();
79 
80  mSearchbar->setColumnNames(mGateTableProxyModel->getColumnNames());
81 
82  connect(mToggleSearchbar,&QAction::triggered,this,&GateDialog::handleToggleSearchbar);
86  connect(mSearchbar, &Searchbar::triggerNewSearch, mGateTableProxyModel, &GateSelectProxy::startSearch);
87 // connect(mTreeView->selectionModel(),&QItemSelectionModel::currentChanged,this,&GateDialog::handleTreeSelectionChanged);
88  if (receiver == nullptr)
89  {
90  mButtonPick->setDisabled(true);
91  mButtonPick->hide();
92  }
93  }
94 
95  void GateDialog::enableButtons()
96  {
97  mButtonBox->button(QDialogButtonBox::Ok)->setEnabled(mSelectedId>0);
98  mButtonPick->setEnabled(mTableView->model()->rowCount()>0);
99  QString target = "…";
100  if (mSelectedId>0)
101  {
102  Gate* g = gNetlist->get_gate_by_id(mSelectedId);
103  if (g) target = QString("%1[%2]").arg(QString::fromStdString(g->get_name())).arg(mSelectedId);
104  }
105  setWindowTitle(mWindowTitle + " " + target);
106  }
107 
108  u32 GateDialog::treeGateId(const QModelIndex& index)
109  {
110  Q_UNUSED(index);
111  return 0;
112  /*
113  GateModel* treeModel = static_cast<GateModel*>(mGateTreeProxyModel->sourceModel());
114  Q_ASSERT(treeModel);
115  QModelIndex sourceIndex = mGateTreeProxyModel->mapToSource(index);
116  if (!sourceIndex.isValid()) return 0;
117  GateItem* item = treeModel->getItem(sourceIndex);
118  if (!item) return 0;
119  return item->id();
120  */
121  }
122 
123  void GateDialog::handleTreeSelectionChanged(const QModelIndex& current, const QModelIndex& previous)
124  {
125  Q_UNUSED(current);
126  Q_UNUSED(previous);
127  /*
128  Q_UNUSED(previous);
129  u32 moduleId = treeGateId(current);
130  if (moduleId) handleTableSelection(moduleId,false);
131  */
132  }
133 
134  void GateDialog::handleTreeDoubleClick(const QModelIndex& index)
135  {
136  u32 moduleId = treeGateId(index);
137  if (moduleId) handleTableSelection(moduleId,true);
138  }
139 
140  void GateDialog::handleTableSelection(u32 id, bool doubleClick)
141  {
142  mSelectedId = GateSelectModel::isAccepted(id,mSelectableGates) ? id : 0;
143  enableButtons();
144  if (mSelectedId && doubleClick) accept();
145  }
146 
147  void GateDialog::handlePickFromGraph()
148  {
149  new GateSelectPicker(mSelectableGates, mReceiver);
150  mPickerModeActivated = true;
151  reject(); // wait for picker, no selection done in dialog
152  }
153 
155  {
156  GateSelectHistory::instance()->add(mSelectedId);
157  QDialog::accept();
158  }
159 
160  void GateDialog::handleToggleSearchbar()
161  {
162  if (mSearchbar->isHidden())
163  {
164  mSearchbar->show();
165  mSearchbar->setFocus();
166  }
167  else
168  {
169  mSearchbar->hide();
170  setFocus();
171  }
172  }
173 
175  {
176  mToggleSearchbar->setShortcut(seq);
177  }
178 }
179 
static SettingsItemKeybind * sSettingSearch
void handleTableSelection(u32 id, bool doubleClick)
void accept() override
void keybindToggleSearchbar(const QKeySequence &seq)
GateDialog(const QSet< u32 > &selectable=QSet< u32 >(), const QString &title=QString("Select gate"), GateSelectReceiver *receiver=nullptr, QWidget *parent=nullptr)
Definition: gate_dialog.cpp:21
Definition: gate.h:58
static GateSelectHistory * instance()
static bool isAccepted(u32 gateId, const QSet< u32 > &selectable)
The GateSelectPicker class instance gets spawned to pick module from graph.
The GateSelectProxy class allows sorting and filtering of module tables.
void startSearch(QString text, int options)
The GateSelectView class is the table widget for module selection.
void gateSelected(u32 gatId, bool doubleClick)
Gate * get_gate_by_id(const u32 gate_id) const
Definition: netlist.cpp:193
virtual QList< QString > getColumnNames()
A QFrame with a QLineEdit that can be used to input a substring to search for.
Definition: searchbar.h:48
void setColumnNames(QList< QString > list)
Definition: searchbar.cpp:130
void triggerNewSearch(const QString &text, int searchOptions)
void keySequenceChanged(QKeySequence value)
Netlist * gNetlist
Definition: plugin_gui.cpp:80
quint32 u32
i32 id
virtual int rowCount(const QModelIndex &parent) const const=0
QAbstractItemModel * model() const const
void setShortcut(const QKeySequence &shortcut)
void triggered(bool checked)
virtual void accept()
virtual void reject()
QPushButton * button(QDialogButtonBox::StandardButton which) const const
void addWidget(QWidget *w)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
QString fromStdString(const std::string &str)
int addTab(QWidget *page, const QString &label)
void setCurrentIndex(int index)
void addAction(QAction *action)
void setEnabled(bool)
void hide()
bool isHidden() const const
QLayout * layout() const const
void setDisabled(bool disable)
void setFocus()
void show()
void setWindowTitle(const QString &)