-
Notifications
You must be signed in to change notification settings - Fork 0
/
genderitemdelegate.cpp
42 lines (37 loc) · 1.22 KB
/
genderitemdelegate.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "genderitemdelegate.h"
#include <Qt/qcombobox.h>
GenderItemDelegate::GenderItemDelegate(QObject *parent) :
QItemDelegate(parent)
{
}
GenderItemDelegate::GenderItemDelegate(int genderColumn, QObject *parent):
QItemDelegate(parent)
{
this->genderColumn=genderColumn;
}
void GenderItemDelegate::setEditorData (QWidget * editor, const QModelIndex & index ) const {
if(index.column() == genderColumn) {
QComboBox *combobox = qobject_cast<QComboBox*>(editor);
Q_ASSERT(combobox);
if(index.data().toString() == "0") {
combobox->setCurrentIndex(0);
} else {
combobox->setCurrentIndex(1);
}
} else {
QItemDelegate::setEditorData(editor, index);
}
}
void GenderItemDelegate::setModelData ( QWidget * editor, QAbstractItemModel * model, const QModelIndex & index ) const {
if(index.column() == genderColumn) {
QComboBox *combobox = qobject_cast<QComboBox*>(editor);
Q_ASSERT(combobox);
if(combobox->currentIndex() == 0) {
model->setData(index, "Masculino");
} else {
model->setData(index, "Femenino");
}
} else {
QItemDelegate::setModelData(editor, model, index);
}
}