added automatix CAD fix
[engrid.git] / src / vertexdelegate.cpp
blob7e6a58cafe35dfaeba88d0e7e819600f040bbdcc
1 //
2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + +
4 // + This file is part of enGrid. +
5 // + +
6 // + Copyright 2008,2009 Oliver Gloth +
7 // + +
8 // + enGrid is free software: you can redistribute it and/or modify +
9 // + it under the terms of the GNU General Public License as published by +
10 // + the Free Software Foundation, either version 3 of the License, or +
11 // + (at your option) any later version. +
12 // + +
13 // + enGrid is distributed in the hope that it will be useful, +
14 // + but WITHOUT ANY WARRANTY; without even the implied warranty of +
15 // + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
16 // + GNU General Public License for more details. +
17 // + +
18 // + You should have received a copy of the GNU General Public License +
19 // + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +
20 // + +
21 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23 #include <QtGui>
25 #include "vertexdelegate.h"
26 #include "surfacemesher.h"
28 #include <iostream>
29 using namespace std;
31 VertexDelegate::VertexDelegate(int Column, QList<QString> list, QObject *parent)
32 : QItemDelegate(parent)
34 this->list = list;
35 this->Column = Column;
39 void VertexDelegate::paint(QPainter *painter,
40 const QStyleOptionViewItem &option,
41 const QModelIndex &index) const
43 if (index.column() == Column) {
44 QString text = index.model()->data(index, Qt::DisplayRole).toString();
46 QStyleOptionViewItem myOption = option;
47 myOption.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
49 drawDisplay(painter, myOption, myOption.rect, text);
50 drawFocus(painter, myOption, myOption.rect);
51 } else{
52 QItemDelegate::paint(painter, option, index);
56 QWidget *VertexDelegate::createEditor(QWidget *parent,
57 const QStyleOptionViewItem &option,
58 const QModelIndex &index) const
60 if (index.column() == Column) {
61 QComboBox *ComboEdit = new QComboBox(parent);
62 foreach(QString str,list) ComboEdit->addItem(str);
63 connect(ComboEdit, SIGNAL(currentIndexChanged ( int )),this, SLOT(commitAndCloseEditor()));
64 return ComboEdit;
65 } else {
66 return QItemDelegate::createEditor(parent, option, index);
70 void VertexDelegate::setEditorData(QWidget *editor,
71 const QModelIndex &index) const
73 if (index.column() == Column) {
74 // int secs = index.model()->data(index, Qt::DisplayRole).toInt();
75 // QComboBox *ComboEdit = qobject_cast<QComboBox *>(editor);
76 // ComboEdit->setCurrentIndex(secs);
77 } else {
78 QItemDelegate::setEditorData(editor, index);
82 void VertexDelegate::setModelData(QWidget *editor,
83 QAbstractItemModel *model,
84 const QModelIndex &index) const
86 if (index.column() == Column) {
87 QComboBox *ComboEdit = qobject_cast<QComboBox *>(editor);
88 model->setData(index, ComboEdit->currentText());
89 } else {
90 QItemDelegate::setModelData(editor, model, index);
94 void VertexDelegate::commitAndCloseEditor()
96 QComboBox *editor = qobject_cast<QComboBox *>(sender());
97 emit commitData(editor);
98 emit closeEditor(editor);