HAL  v4.5.0-83-g30c8f0afc
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
boolean_dialog.cpp
Go to the documentation of this file.
2 #include <QDialogButtonBox>
3 #include <QPushButton>
4 #include <QRadioButton>
5 #include <QGridLayout>
6 #include <QTableWidget>
7 #include <QLineEdit>
8 #include <QFrame>
9 #include <QVBoxLayout>
10 
11 namespace hal {
13  : QDialog(parent), mHandleTableEdit(true)
14  {
18 
19  setWindowTitle("Create Boolean Waveform");
20  setMinimumWidth(640);
21 
22  QGridLayout* layout = new QGridLayout(this);
23  QFrame* fExpression = new QFrame(this);
25  fExpression->setLineWidth(2);
26  QVBoxLayout* layExpression = new QVBoxLayout(fExpression);
27  mEnterExpression = new QRadioButton("Enter boolean expression:");
28  connect(mEnterExpression,&QRadioButton::toggled,this,&BooleanDialog::handleExpressionToggled);
29  layExpression->addWidget(mEnterExpression);
30  mLineEdit = new QLineEdit(fExpression);
31  if (inputList.isEmpty())
33  else
34  {
35  QString def(inputList.at(0)->name());
36  for (int i=1; i<inputList.size(); i++)
37  def += ("&" + inputList.at(i)->name());
38  mLineEdit->setText(def);
40  }
41  layExpression->addWidget(mLineEdit);
42  layout->addWidget(fExpression,0,0,1,2);
43 
44  QFrame* fTable = new QFrame(this);
46  fTable->setLineWidth(2);
47  QVBoxLayout* layTable = new QVBoxLayout(fTable);
48  mEnterTable = new QRadioButton("Enter table with accepted combinations:");
49  connect(mEnterTable,&QRadioButton::toggled,this,&BooleanDialog::handleTableToggled);
50  layTable->addWidget(mEnterTable);
51  mTableWidget = new QTableWidget(this);
52  mTableWidget->setDisabled(true);
53  if (inputList.isEmpty())
54  mEnterTable->setDisabled(true);
55  else
56  {
57  mTableWidget->setRowCount(inputList.size());
58  mTableWidget->setColumnCount(2);
59  for (int irow=0; irow<inputList.size(); irow++)
60  {
61  WaveData* wd = inputList.at(irow);
62  mTableWidget->setItem(irow,0,new QTableWidgetItem(QString::number(wd->id())));
63  mTableWidget->setItem(irow,1,new QTableWidgetItem(wd->name()));
64  for (int icol=0; icol<2; icol++)
65  mTableWidget->item(irow,icol)->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled);
66  mTableWidget->setColumnWidth(0,60);
67  mTableWidget->setColumnWidth(1,360);
68  }
69  addEmptyTableColumn(2);
70  mTableWidget->setHorizontalHeaderLabels({"ID", "Name", "1."});
71  }
72  connect(mTableWidget,&QTableWidget::cellChanged,this,&BooleanDialog::handleTableCellChanged);
73  layTable->addWidget(mTableWidget);
74  layout->addWidget(fTable,1,0,1,2);
75  layout->addWidget(dbb,2,1);
76  mEnterExpression->setChecked(true);
77  }
78 
79  void BooleanDialog::addEmptyTableColumn(int icol)
80  {
81  if (mTableWidget->columnCount()<=icol)
82  {
83  mTableWidget->setColumnCount(icol+1);
84  mTableWidget->setColumnWidth(icol,36);
85  mTableWidget->setHorizontalHeaderItem(icol,new QTableWidgetItem(QString("%1.").arg(icol-1)));
86  }
87  for (int irow=0; irow < mTableWidget->rowCount(); irow++)
88  {
91  mTableWidget->setItem(irow,icol,twi);
92  }
93  }
94 
95  void BooleanDialog::handleTableCellChanged(int irow, int icol)
96  {
97  if (!mHandleTableEdit) return;
98  mHandleTableEdit = false;
99  bool rejected = true;
100  int n = mTableWidget->columnCount();
101  QString txt = mTableWidget->item(irow,icol)->text();
102  if (txt == "0" || txt == "1")
103  rejected = false;
104  if (txt == "X" || txt == "x")
105  {
106  rejected = false;
107  mTableWidget->item(irow,icol)->setText("0");
108  int j = n-1;
109  if (icol+1 >= n)
110  {
111  addEmptyTableColumn(n++);
112  j = n-1;
113  }
114  for (int i=0; i<mTableWidget->rowCount(); i++)
115  mTableWidget->item(i,j)->setText(i==irow?QString("1"):mTableWidget->item(i,icol)->text());
116  if (j+1 >= n)
117  addEmptyTableColumn(n);
118  }
119  if (rejected)
120  mTableWidget->item(irow,icol)->setText("");
121  else if (icol+1 >= n)
122  addEmptyTableColumn(icol+1);
123  mHandleTableEdit = true;
124  }
125 
126 
127  void BooleanDialog::activateExpression(bool enable)
128  {
129  if (enable)
130  mEnterTable->setChecked(false);
131  else
132  mEnterExpression->setChecked(false);
133  mTableWidget->setDisabled(enable);
134  mLineEdit->setEnabled(enable);
135  }
136 
137  void BooleanDialog::handleExpressionToggled(bool state)
138  {
139  activateExpression(state);
140  }
141 
142  void BooleanDialog::handleTableToggled(bool state)
143  {
144  activateExpression(!state);
145  }
146 
148  {
149  return mEnterExpression->isChecked();
150  }
151 
153  {
154  return mLineEdit->text().trimmed();
155  }
156 
158  {
159  QSet<int> val;
160  for (int icol = 2; icol < mTableWidget->columnCount(); icol++)
161  {
162  bool incomplete = false;
163  int v = 0;
164  for (int irow = 0; irow < mTableWidget->rowCount(); irow++)
165  {
166  QString txt = mTableWidget->item(irow,icol)->text();
167  if (txt!="0")
168  {
169  if (txt == "1")
170  v |= (1<<irow);
171  else
172  {
173  incomplete = true;
174  break;
175  }
176  }
177  }
178  if (!incomplete)
179  val.insert(v);
180  }
181  return val.toList();
182  }
183 }
bool hasExpression() const
BooleanDialog(const QList< WaveData * > inputList, QWidget *parent=nullptr)
QList< int > tableValues() const
QString expression() const
QString name() const
Definition: wave_data.h:104
u32 id() const
Definition: wave_data.h:103
Definition: defines.h:45
void setChecked(bool)
void toggled(bool checked)
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
virtual void accept()
virtual void reject()
void rejected()
QPushButton * button(QDialogButtonBox::StandardButton which) const const
void setLineWidth(int)
void setFrameStyle(int style)
void addWidget(QWidget *w)
void setText(const QString &)
const T & at(int i) const const
bool isEmpty() const const
int size() const const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QSet::iterator insert(const T &value)
QList< T > toList() const const
QString number(int n, int base)
ItemIsSelectable
void setColumnWidth(int column, int width)
void cellChanged(int row, int column)
QTableWidgetItem * item(int row, int column) const const
void setColumnCount(int columns)
void setHorizontalHeaderItem(int column, QTableWidgetItem *item)
void setHorizontalHeaderLabels(const QStringList &labels)
void setItem(int row, int column, QTableWidgetItem *item)
void setRowCount(int rows)
void setFlags(Qt::ItemFlags flags)
void setText(const QString &text)
QString text() const const
void setEnabled(bool)
QLayout * layout() const const
void setMinimumWidth(int minw)
void setDisabled(bool disable)
void setWindowTitle(const QString &)