QSS Solver GUI  4.5.3
comboboxdelegate.cpp
Go to the documentation of this file.
1 /*****************************************************************************
2 
3  This file is part of QSS Solver.
4 
5  QSS Solver is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  QSS Solver is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with QSS Solver. If not, see <http://www.gnu.org/licenses/>.
17 
18  ******************************************************************************/
19 
20 #include <QComboBox>
21 
22 #include "comboboxdelegate.hpp"
23 
24 ComboBoxDelegate::ComboBoxDelegate(QObject *parent) : QItemDelegate(parent) {}
25 
26 QWidget *ComboBoxDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem & /* option */, const QModelIndex & /* index */) const
27 {
28  QComboBox *editor = new QComboBox(parent);
29  editor->addItem("lines");
30  editor->addItem("steps");
31  editor->addItem("impulses");
32  editor->addItem("None");
33  editor->setCurrentIndex(0);
34  return editor;
35 }
36 
37 void ComboBoxDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
38 {
39  QString value = index.model()->data(index, Qt::EditRole).toString();
40 
41  QComboBox *cBox = static_cast<QComboBox *>(editor);
42  cBox->setCurrentIndex(cBox->findText(value));
43 }
44 
45 void ComboBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
46 {
47  QComboBox *cBox = static_cast<QComboBox *>(editor);
48  QString value = cBox->currentText();
49 
50  model->setData(index, value, Qt::EditRole);
51 }
52 
53 void ComboBoxDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex & /* index */) const
54 {
55  editor->setGeometry(option.rect);
56 }
ComboBoxDelegate::createEditor
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition: comboboxdelegate.cpp:26
comboboxdelegate.hpp
ComboBoxDelegate::updateEditorGeometry
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition: comboboxdelegate.cpp:53
ComboBoxDelegate::setEditorData
void setEditorData(QWidget *editor, const QModelIndex &index) const
Definition: comboboxdelegate.cpp:37
ComboBoxDelegate::ComboBoxDelegate
ComboBoxDelegate(QObject *parent=0)
Definition: comboboxdelegate.cpp:24
ComboBoxDelegate::setModelData
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
Definition: comboboxdelegate.cpp:45