2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 // + This file is part of enGrid. +
6 // + Copyright 2008-2012 enGits GmbH +
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. +
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. +
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/>. +
21 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23 #include "guivolumedelegate.h"
28 void GuiVolumeDelegate::paint(QPainter
*painter
, const QStyleOptionViewItem
&option
, const QModelIndex
&index
) const
30 if (index
.column() >= first_column
) {
31 QString text
= index
.model()->data(index
, Qt::DisplayRole
).toString();
32 QStyleOptionViewItem myOption
= option
;
33 myOption
.displayAlignment
= Qt::AlignRight
| Qt::AlignVCenter
;
34 drawDisplay(painter
, myOption
, myOption
.rect
, text
);
35 drawFocus(painter
, myOption
, myOption
.rect
);
37 QItemDelegate::paint(painter
, option
, index
);
41 QWidget
*GuiVolumeDelegate::createEditor(QWidget
*parent
, const QStyleOptionViewItem
&option
, const QModelIndex
&index
) const
43 if (index
.column() >= first_column
) {
44 QComboBox
*comboBox
= new QComboBox(parent
);
45 comboBox
->addItem("A <<");
46 comboBox
->addItem(">> B");
47 comboBox
->addItem(" ");
48 connect(comboBox
, SIGNAL(currentIndexChanged ( int )), this, SLOT(commitAndCloseEditor()));
51 return QItemDelegate::createEditor(parent
, option
, index
);
55 void GuiVolumeDelegate::setEditorData(QWidget
*editor
, const QModelIndex
&index
) const
57 if (index
.column() >= first_column
) {
58 int secs
= index
.model()->data(index
, Qt::DisplayRole
).toInt();
59 QComboBox
*comboBox
= qobject_cast
<QComboBox
*>(editor
);
60 comboBox
->setCurrentIndex(secs
);
62 QItemDelegate::setEditorData(editor
, index
);
66 void GuiVolumeDelegate::setModelData(QWidget
*editor
, QAbstractItemModel
*model
, const QModelIndex
&index
) const
68 if (index
.column() >= first_column
) {
69 QComboBox
*comboBox
= qobject_cast
<QComboBox
*>(editor
);
70 model
->setData(index
, comboBox
->currentText());
72 QItemDelegate::setModelData(editor
, model
, index
);
76 void GuiVolumeDelegate::commitAndCloseEditor()
78 qDebug()<<"commitAndCloseEditor called";
79 QComboBox
*editor
= qobject_cast
<QComboBox
*>(sender());
80 emit
commitData(editor
);
81 emit
closeEditor(editor
);