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 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23 #include "vertexdelegate.h"
24 #include "surfacemesher.h"
29 VertexDelegate::VertexDelegate(int Column
, QList
<QString
> list
, QObject
*parent
)
30 : QItemDelegate(parent
)
33 this->Column
= Column
;
37 void VertexDelegate::paint(QPainter
*painter
,
38 const QStyleOptionViewItem
&option
,
39 const QModelIndex
&index
) const
41 if (index
.column() == Column
) {
42 QString text
= index
.model()->data(index
, Qt::DisplayRole
).toString();
44 QStyleOptionViewItem myOption
= option
;
45 myOption
.displayAlignment
= Qt::AlignRight
| Qt::AlignVCenter
;
47 drawDisplay(painter
, myOption
, myOption
.rect
, text
);
48 drawFocus(painter
, myOption
, myOption
.rect
);
50 QItemDelegate::paint(painter
, option
, index
);
54 QWidget
*VertexDelegate::createEditor(QWidget
*parent
,
55 const QStyleOptionViewItem
&option
,
56 const QModelIndex
&index
) const
58 if (index
.column() == Column
) {
59 QComboBox
*ComboEdit
= new QComboBox(parent
);
60 foreach(QString str
,list
) ComboEdit
->addItem(str
);
61 connect(ComboEdit
, SIGNAL(currentIndexChanged ( int )),this, SLOT(commitAndCloseEditor()));
64 return QItemDelegate::createEditor(parent
, option
, index
);
68 void VertexDelegate::setEditorData(QWidget
*editor
,
69 const QModelIndex
&index
) const
71 if (index
.column() == Column
) {
72 // int secs = index.model()->data(index, Qt::DisplayRole).toInt();
73 // QComboBox *ComboEdit = qobject_cast<QComboBox *>(editor);
74 // ComboEdit->setCurrentIndex(secs);
76 QItemDelegate::setEditorData(editor
, index
);
80 void VertexDelegate::setModelData(QWidget
*editor
,
81 QAbstractItemModel
*model
,
82 const QModelIndex
&index
) const
84 if (index
.column() == Column
) {
85 QComboBox
*ComboEdit
= qobject_cast
<QComboBox
*>(editor
);
86 model
->setData(index
, ComboEdit
->currentText());
88 QItemDelegate::setModelData(editor
, model
, index
);
92 void VertexDelegate::commitAndCloseEditor()
94 QComboBox
*editor
= qobject_cast
<QComboBox
*>(sender());
95 emit
commitData(editor
);
96 emit
closeEditor(editor
);