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