1 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + This file is part of enGrid. +
5 // + Copyright 2008-2014 enGits GmbH +
7 // + enGrid is free software: you can redistribute it and/or modify +
8 // + it under the terms of the GNU General Public License as published by +
9 // + the Free Software Foundation, either version 3 of the License, or +
10 // + (at your option) any later version. +
12 // + enGrid is distributed in the hope that it will be useful, +
13 // + but WITHOUT ANY WARRANTY; without even the implied warranty of +
14 // + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
15 // + GNU General Public License for more details. +
17 // + You should have received a copy of the GNU General Public License +
18 // + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +
20 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
21 #ifndef VERTEXDELEGATE_H
22 #define VERTEXDELEGATE_H
24 #include <QItemDelegate>
25 #include <QTableWidgetItem>
27 //Thanks to jpnurmi from qt@irc.freenode.net for this class ;)
28 class TriStateTableWidgetItem
: public QTableWidgetItem
31 TriStateTableWidgetItem() : QTableWidgetItem()
33 QTableWidgetItem::setCheckState(Qt::Checked
);
34 setData(Qt::CheckStateRole
,Qt::Checked
);
36 void setData(int role
, const QVariant
& value
)
39 if (role
== Qt::CheckStateRole
)
41 if (data(role
) == Qt::Unchecked
&& value
== Qt::Checked
)
42 tmp
= Qt::PartiallyChecked
;
43 else if (data(role
) == Qt::PartiallyChecked
&& value
== Qt::Checked
)
48 QTableWidgetItem::setData(role
, tmp
);
50 void setCheckState(Qt::CheckState S
){
51 QTableWidgetItem::setData(Qt::CheckStateRole
, S
);
55 /// Creates a combobox for use in a table
56 class VertexDelegate
: public QItemDelegate
61 VertexDelegate(int Column
, QList
<QString
> list
, QObject
*parent
= 0);
63 void paint(QPainter
*painter
, const QStyleOptionViewItem
&option
, const QModelIndex
&index
) const;
64 QWidget
*createEditor(QWidget
*parent
, const QStyleOptionViewItem
&option
, const QModelIndex
&index
) const;
65 void setEditorData(QWidget
*editor
, const QModelIndex
&index
) const;
66 void setModelData(QWidget
*editor
, QAbstractItemModel
*model
, const QModelIndex
&index
) const;
69 void commitAndCloseEditor();