fixed edge display for volume cells
[engrid-github.git] / src / libengrid / guivolumedelegate.cpp
blob7063dc1b34b2d7b41ef79713844679d2da2f6326
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 #include "guivolumedelegate.h"
23 #include <QComboBox>
24 #include <QtDebug>
26 void GuiVolumeDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
28 if (index.column() >= first_column) {
29 QString text = index.model()->data(index, Qt::DisplayRole).toString();
30 QStyleOptionViewItem myOption = option;
31 myOption.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
32 drawDisplay(painter, myOption, myOption.rect, text);
33 drawFocus(painter, myOption, myOption.rect);
34 } else{
35 QItemDelegate::paint(painter, option, index);
39 QWidget *GuiVolumeDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
41 if (index.column() >= first_column) {
42 QComboBox *comboBox = new QComboBox(parent);
43 comboBox->addItem("A <<");
44 comboBox->addItem(">> B");
45 comboBox->addItem(" ");
46 connect(comboBox, SIGNAL(currentIndexChanged ( int )), this, SLOT(commitAndCloseEditor()));
47 return comboBox;
48 } else {
49 return QItemDelegate::createEditor(parent, option, index);
53 void GuiVolumeDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
55 if (index.column() >= first_column) {
56 int secs = index.model()->data(index, Qt::DisplayRole).toInt();
57 QComboBox *comboBox = qobject_cast<QComboBox *>(editor);
58 comboBox->setCurrentIndex(secs);
59 } else {
60 QItemDelegate::setEditorData(editor, index);
64 void GuiVolumeDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
66 if (index.column() >= first_column) {
67 QComboBox *comboBox = qobject_cast<QComboBox *>(editor);
68 model->setData(index, comboBox->currentText());
69 } else {
70 QItemDelegate::setModelData(editor, model, index);
74 void GuiVolumeDelegate::commitAndCloseEditor()
76 qDebug()<<"commitAndCloseEditor called";
77 QComboBox *editor = qobject_cast<QComboBox *>(sender());
78 emit commitData(editor);
79 emit closeEditor(editor);