1 #ifndef VERTEXDELEGATE_H
2 #define VERTEXDELEGATE_H
4 #include <QItemDelegate>
5 #include <QTableWidgetItem>
7 //Thanks to jpnurmi from qt@irc.freenode.net for this class ;)
8 class TriStateTableWidgetItem
: public QTableWidgetItem
11 TriStateTableWidgetItem() : QTableWidgetItem()
13 QTableWidgetItem::setCheckState(Qt::Checked
);
14 setData(Qt::CheckStateRole
,Qt::Checked
);
16 void setData(int role
, const QVariant
& value
)
19 if (role
== Qt::CheckStateRole
)
21 if (data(role
) == Qt::Unchecked
&& value
== Qt::Checked
)
22 tmp
= Qt::PartiallyChecked
;
23 else if (data(role
) == Qt::PartiallyChecked
&& value
== Qt::Checked
)
28 QTableWidgetItem::setData(role
, tmp
);
30 void setCheckState(Qt::CheckState S
){
31 QTableWidgetItem::setData(Qt::CheckStateRole
, S
);
35 class VertexDelegate
: public QItemDelegate
40 VertexDelegate(int durationColumn
, QList
<QString
> list
, QObject
*parent
= 0);
42 void paint(QPainter
*painter
, const QStyleOptionViewItem
&option
,
43 const QModelIndex
&index
) const;
44 QWidget
*createEditor(QWidget
*parent
,
45 const QStyleOptionViewItem
&option
,
46 const QModelIndex
&index
) const;
47 void setEditorData(QWidget
*editor
, const QModelIndex
&index
) const;
48 void setModelData(QWidget
*editor
, QAbstractItemModel
*model
,
49 const QModelIndex
&index
) const;
52 void commitAndCloseEditor();