]> AND Private Git Repository - blast.git/blob - IfacePurposeDelegate.cpp
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
finished testbench generation
[blast.git] / IfacePurposeDelegate.cpp
1 // fichier enregistré en UTF-8
2
3 #include "IfacePurposeDelegate.h"
4
5 IfacePurposeDelegate::IfacePurposeDelegate(QObject *parent) : QItemDelegate(parent) {
6   
7   lstPurpose.append("any");
8   lstPurpose.append("data");
9   lstPurpose.append("control");
10   lstPurpose.append("clock");
11   lstPurpose.append("reset");
12   lstPurpose.append("wishbone");
13 }
14
15 QWidget* IfacePurposeDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option , const QModelIndex &index) const {
16
17   int i;
18   
19   QComboBox *lst = new QComboBox(parent);
20   lst->setSizeAdjustPolicy (QComboBox::AdjustToContents);
21
22   for(int i=0;i<lstPurpose.size();i++) {
23     lst->addItem(lstPurpose.at(i));
24   }
25
26   lst->installEventFilter(const_cast<IfacePurposeDelegate*>(this));
27   lst->adjustSize();
28   
29   return lst;
30 }
31
32 void IfacePurposeDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const {
33
34
35   int id = lstPurpose.indexOf(index.model()->data(index, Qt::DisplayRole).toString());
36   
37   QComboBox *lst = static_cast<QComboBox*>(editor);
38   lst->setCurrentIndex(id);
39
40 }
41
42 void IfacePurposeDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const {
43
44   int id;
45   QComboBox *lst = static_cast<QComboBox*>(editor);
46
47   id = lst->currentIndex();
48   cout << "update display" << endl;
49   model->setData(index, lst->currentText(), Qt::DisplayRole);  
50 }
51
52 void IfacePurposeDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &/* index */) const {
53
54   QSize size = editor->size();
55
56   QRect rect = option.rect;
57   rect.setWidth(size.width());
58   editor->setGeometry(rect);
59
60 }