Added not yet working vtkinteractorstyle subclass + fixed sigabrt when switching...
[engrid.git] / vertexdelegate.cpp
blobadec3f9c09e002d8a36508e4e5ef3fadd9bf9689
1 #include <QtGui>
3 #include "vertexdelegate.h"
4 #include "createspecialmapping.h"
6 #include <iostream>
7 using namespace std;
9 VertexDelegate::VertexDelegate(int durationColumn, QList<QString> list, QObject *parent)
10 : QItemDelegate(parent)
12 this->list = list;
13 this->durationColumn = durationColumn;
16 void VertexDelegate::paint(QPainter *painter,
17 const QStyleOptionViewItem &option,
18 const QModelIndex &index) const
20 if (index.column() == durationColumn) {
21 QString text = index.model()->data(index, Qt::DisplayRole).toString();
23 QStyleOptionViewItem myOption = option;
24 myOption.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
26 drawDisplay(painter, myOption, myOption.rect, text);
27 drawFocus(painter, myOption, myOption.rect);
28 } else{
29 QItemDelegate::paint(painter, option, index);
33 QWidget *VertexDelegate::createEditor(QWidget *parent,
34 const QStyleOptionViewItem &option,
35 const QModelIndex &index) const
37 if (index.column() == durationColumn) {
38 QComboBox *ComboEdit = new QComboBox(parent);
39 foreach(QString str,list) ComboEdit->addItem(str);
40 connect(ComboEdit, SIGNAL(editingFinished()),
41 this, SLOT(commitAndCloseEditor()));
42 return ComboEdit;
43 } else {
44 return QItemDelegate::createEditor(parent, option, index);
48 void VertexDelegate::setEditorData(QWidget *editor,
49 const QModelIndex &index) const
51 if (index.column() == durationColumn) {
52 // int secs = index.model()->data(index, Qt::DisplayRole).toInt();
53 QComboBox *ComboEdit = qobject_cast<QComboBox *>(editor);
54 // ComboEdit->setCurrentIndex(secs);
55 } else {
56 QItemDelegate::setEditorData(editor, index);
60 void VertexDelegate::setModelData(QWidget *editor,
61 QAbstractItemModel *model,
62 const QModelIndex &index) const
64 if (index.column() == durationColumn) {
65 QComboBox *ComboEdit = qobject_cast<QComboBox *>(editor);
66 model->setData(index, ComboEdit->currentText());
67 } else {
68 QItemDelegate::setModelData(editor, model, index);
72 void VertexDelegate::commitAndCloseEditor()
74 QComboBox *editor = qobject_cast<QComboBox *>(sender());
75 emit commitData(editor);
76 emit closeEditor(editor);