HAL
pin_delegate.cpp
Go to the documentation of this file.
2 
3 #include "gui/gui_globals.h"
5 
6 #include <QComboBox>
7 #include <QApplication>
8 #include <QLineEdit>
9 #include <QPainter>
10 #include <QPushButton>
11 #include <QSpinBox>
12 #include <gui/pin_model/pin_item.h>
14 
15 namespace hal
16 {
17 
19  {
20 
21  }
22 
24  {
25  PinItem::TreeItemType itemType = static_cast<PinItem*>(index.internalPointer())->getItemType();
26  //TODO create editors
27 
28  // Column 0: Name, Column 1: Type, Column 2: Direction, Column 3: Delete button
29  switch(index.column()){
30  case 0:{
31  auto lineEdit = new QLineEdit(parent);
32  lineEdit->setFocusPolicy(Qt::StrongFocus);
33  return lineEdit;
34  }
35  case 1: {
36  //dont create a widget for dummyEntries
38  return nullptr;
39  auto comboBox = new QComboBox(parent);
40  //TODO provide enum to string method
41  comboBox->addItem("input");
42  comboBox->addItem("output");
43  comboBox->addItem("inout");
44  comboBox->addItem("internal");
45  comboBox->setFocusPolicy(Qt::StrongFocus);
46  return comboBox;
47  }
48  case 2:{
49  //dont create a widget for dummyEntries
51  return nullptr;
52 
53  auto comboBox = new QComboBox(parent);
54  //TODO provide enum to string method
55  comboBox->addItem("none");
56  comboBox->addItem("power");
57  comboBox->addItem("ground");
58  comboBox->addItem("lut");
59  comboBox->addItem("state");
60  comboBox->addItem("neg_state");
61  comboBox->addItem("clock");
62  comboBox->addItem("enable");
63  comboBox->addItem("set");
64  comboBox->addItem("reset");
65  comboBox->addItem("data");
66  comboBox->addItem("address");
67  comboBox->addItem("io_pad");
68  comboBox->addItem("select");
69  comboBox->addItem("carry");
70  comboBox->addItem("sum");
71  comboBox->setFocusPolicy(Qt::StrongFocus);
72  return comboBox;
73  }
74  case 3:{
75  qInfo() << "create editor for 3";
76  }
77  }
78 
79 
80  return nullptr;
81  }
82 
83  void PinDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const
84  {
85  //TODO set editor data if direction or type is selected
86  //qInfo() << "Editing row: " << index.row() << " column: " << index.column();
87  auto pinItem = static_cast<PinItem*>(index.internalPointer());
88  PinItem::TreeItemType itemType = pinItem->getItemType();
89 
90  switch(index.column()){
91  case 0: {
92  //name editor
93  auto lineEdit = static_cast<QLineEdit*>(editor);
95  lineEdit->setText(pinItem->getName());
96  }
97  break;
98  }
99  case 1: {
100  //direction editor
101  //TODO currently only pins can change the direction while groups does not allow modification
103  break;
104  auto comboBox = static_cast<QComboBox*>(editor);
105  comboBox->setCurrentText(pinItem->getDirectionAsText());
106  break;
107  }
108  case 2: {
109  //type editor
111  break;
112  auto comboBox = static_cast<QComboBox*>(editor);
113  comboBox->setCurrentText(pinItem->getPinTypeAsText());
114  break;
115  }
116  }
117 
118  }
119 
120  void PinDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const
121  {
122  //TODO cast editor to corresponding column
123  PinItem::TreeItemType itemType = static_cast<PinItem*>(index.internalPointer())->getItemType();
124  auto pinModel = static_cast<PinModel*>(model);
125 
126  switch(index.column()){
127  case 0: {
128  //name column
129  auto lineEdit = static_cast<QLineEdit*>(editor);
130  QString text = lineEdit->text();
131  if (!text.isEmpty())
132  pinModel->handleEditName(index, text);
133  break;
134  }
135  case 1:{
136  //direction column
137  //TODO currently only pins can change the direction while groups does not allow modification
139  break;
140  auto comboBox = static_cast<QComboBox*>(editor);
141  QString text = comboBox->currentText();
142  if(!text.isEmpty())
143  pinModel->handleEditDirection(index, text);
144  break;
145  }
146  case 2:{
147  //type column
149  break;
150  auto comboBox = static_cast<QComboBox*>(editor);
151  QString text = comboBox->currentText();
152  if(!text.isEmpty())
153  pinModel->handleEditType(index, text);
154  break;
155  }
156  }
157  }
158 
159 
161  {
162  //QStyledItemDelegate::updateEditorGeometry(editor, option, index);
163  editor->setGeometry(option.rect);
164  }
165 
166  void PinDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
167  {
168  //TODO colorize dummy entries and invalid pins
169 
170  PinItem::TreeItemType itemType = static_cast<PinItem*>(index.internalPointer())->getItemType();
172  painter->fillRect(option.rect, Qt::darkRed);
173  }
174  QStyledItemDelegate::paint(painter, option, index);
175  }
176 }
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override
PinDelegate(QObject *parent=0)
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override
void setEditorData(QWidget *editor, const QModelIndex &index) const override
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override
An item in the PinModel.
Definition: pin_item.h:48
TreeItemType getItemType() const
Definition: pin_item.cpp:132
option(PL_GUI "PL_GUI" ON) if(PL_GUI OR BUILD_ALL_PLUGINS) cmake_minimum_required(VERSION 3.1.0) if(APPLE AND CMAKE_HOST_APPLE AND NOT Qt5_DIR) set(Qt5_DIR "/usr/local/opt/qt@5/lib/cmake") endif(APPLE AND CMAKE_HOST_APPLE AND NOT Qt5_DIR) find_package(Qt5 COMPONENTS Core REQUIRED) find_package(Qt5 COMPONENTS Widgets REQUIRED) if(Qt5Widgets_FOUND) message(VERBOSE "Qt5Widgets_INCLUDE_DIRS
Definition: CMakeLists.txt:1
void setCurrentText(const QString &text)
void setText(const QString &)
int column() const const
void * internalPointer() const const
QObject * parent() const const
void fillRect(const QRectF &rectangle, const QBrush &brush)
bool isEmpty() const const
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const const override
StrongFocus
void setGeometry(int x, int y, int w, int h)