fixed edge display for volume cells
[engrid-github.git] / src / libengrid / vertexdelegate.h
blobc501d90e2210bee3f6fe297b6a6b8787e1f9643e
1 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 // + +
3 // + This file is part of enGrid. +
4 // + +
5 // + Copyright 2008-2014 enGits GmbH +
6 // + +
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. +
11 // + +
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. +
16 // + +
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/>. +
19 // + +
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
30 public:
31 TriStateTableWidgetItem() : QTableWidgetItem()
33 QTableWidgetItem::setCheckState(Qt::Checked);
34 setData(Qt::CheckStateRole,Qt::Checked);
36 void setData(int role, const QVariant& value)
38 QVariant tmp = 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)
44 tmp = Qt::Checked;
45 else
46 tmp = Qt::Unchecked;
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
58 Q_OBJECT
60 public:
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;
68 private slots:
69 void commitAndCloseEditor();
71 private:
72 QList<QString> list;
73 int Column;
76 #endif