-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgendercelldelegate.cpp
40 lines (32 loc) · 1.17 KB
/
gendercelldelegate.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
#include "gendercelldelegate.h"
GenderCellDelegate::GenderCellDelegate(int genderColumn, QObject *parent)
: QSqlRelationalDelegate(parent)
{
this->genderColumn=genderColumn;
}
void GenderCellDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
if(index.column() == genderColumn) {
const QAbstractItemModel *auxmodel = index.model();
if (auxmodel->data(index,Qt::DisplayRole).toInt()==0){
painter->drawText(option.rect, tr("Masculino"));
} else {
painter->drawText(option.rect, tr("Femenino"));
}
} else {
QSqlRelationalDelegate::paint(painter, option, index);
}
}
void GenderCellDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{
if(index.column() == genderColumn) {
const QAbstractItemModel *auxmodel = index.model();
if (auxmodel->data(index,Qt::DisplayRole).toInt()==0){
model->setData(index, "Masculino");
} else {
model->setData(index, "Femenino");
}
} else {
QSqlRelationalDelegate::setModelData(editor, model, index);
}
}