1 // fichier enregistré en UTF-8
3 #include "IfacePurposeDelegate.h"
5 IfacePurposeDelegate::IfacePurposeDelegate(QObject *parent) : QItemDelegate(parent) {
7 lstPurpose.append("any");
8 lstPurpose.append("data");
9 lstPurpose.append("control");
10 lstPurpose.append("clock");
11 lstPurpose.append("reset");
12 lstPurpose.append("wishbone");
15 QWidget* IfacePurposeDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option , const QModelIndex &index) const {
19 QComboBox *lst = new QComboBox(parent);
20 lst->setSizeAdjustPolicy (QComboBox::AdjustToContents);
22 for(int i=0;i<lstPurpose.size();i++) {
23 lst->addItem(lstPurpose.at(i));
26 lst->installEventFilter(const_cast<IfacePurposeDelegate*>(this));
32 void IfacePurposeDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const {
35 int id = lstPurpose.indexOf(index.model()->data(index, Qt::DisplayRole).toString());
37 QComboBox *lst = static_cast<QComboBox*>(editor);
38 lst->setCurrentIndex(id);
42 void IfacePurposeDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const {
45 QComboBox *lst = static_cast<QComboBox*>(editor);
47 id = lst->currentIndex();
48 cout << "update display" << endl;
49 model->setData(index, lst->currentText(), Qt::DisplayRole);
52 void IfacePurposeDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &/* index */) const {
54 QSize size = editor->size();
56 QRect rect = option.rect;
57 rect.setWidth(size.width());
58 editor->setGeometry(rect);