3 #include "vertexdelegate.h"
4 #include "createspecialmapping.h"
9 VertexDelegate::VertexDelegate(int durationColumn
, QList
<QString
> list
, QObject
*parent
)
10 : QItemDelegate(parent
)
13 this->durationColumn
= durationColumn
;
16 void VertexDelegate::paint(QPainter
*painter
,
17 const QStyleOptionViewItem
&option
,
18 const QModelIndex
&index
) const
20 if (index
.column() == durationColumn
) {
21 QString text
= index
.model()->data(index
, Qt::DisplayRole
).toString();
23 QStyleOptionViewItem myOption
= option
;
24 myOption
.displayAlignment
= Qt::AlignRight
| Qt::AlignVCenter
;
26 drawDisplay(painter
, myOption
, myOption
.rect
, text
);
27 drawFocus(painter
, myOption
, myOption
.rect
);
29 QItemDelegate::paint(painter
, option
, index
);
33 QWidget
*VertexDelegate::createEditor(QWidget
*parent
,
34 const QStyleOptionViewItem
&option
,
35 const QModelIndex
&index
) const
37 if (index
.column() == durationColumn
) {
38 QComboBox
*ComboEdit
= new QComboBox(parent
);
39 foreach(QString str
,list
) ComboEdit
->addItem(str
);
40 connect(ComboEdit
, SIGNAL(editingFinished()),
41 this, SLOT(commitAndCloseEditor()));
44 return QItemDelegate::createEditor(parent
, option
, index
);
48 void VertexDelegate::setEditorData(QWidget
*editor
,
49 const QModelIndex
&index
) const
51 if (index
.column() == durationColumn
) {
52 // int secs = index.model()->data(index, Qt::DisplayRole).toInt();
53 QComboBox
*ComboEdit
= qobject_cast
<QComboBox
*>(editor
);
54 // ComboEdit->setCurrentIndex(secs);
56 QItemDelegate::setEditorData(editor
, index
);
60 void VertexDelegate::setModelData(QWidget
*editor
,
61 QAbstractItemModel
*model
,
62 const QModelIndex
&index
) const
64 if (index
.column() == durationColumn
) {
65 QComboBox
*ComboEdit
= qobject_cast
<QComboBox
*>(editor
);
66 model
->setData(index
, ComboEdit
->currentText());
68 QItemDelegate::setModelData(editor
, model
, index
);
72 void VertexDelegate::commitAndCloseEditor()
74 QComboBox
*editor
= qobject_cast
<QComboBox
*>(sender());
75 emit
commitData(editor
);
76 emit
closeEditor(editor
);