-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmemberdelegate.cpp
50 lines (45 loc) · 1.72 KB
/
memberdelegate.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
43
44
45
46
47
48
49
50
#include "memberdelegate.h"
MemberDelegate::MemberDelegate(QObject *parent) :
QItemDelegate(parent)
{
}
void MemberDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
return QItemDelegate::paint(painter, option, index);
}
QWidget *MemberDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
int dataType = index.data( DataTypeRole).toInt();
QWidget* returnWidget;
if(dataType==Date)
{
QString dateString = index.data(Qt::DisplayRole).toString();
QDate date = QDate::fromString(dateString, "yyyy-MM-dd");
if(!date.isValid())
returnWidget = new QDateEdit(parent);
else
returnWidget = new QDateEdit(date, parent);
returnWidget->setProperty("MemberListType", QVariant(Date));
return returnWidget;
}
/*
else if (dataType==Bool)
{
int data=index.data().toInt();
returnWidget = new QCheckBox();
((QCheckBox*) returnWidget)->setCheckState(data?Qt::Checked:Qt::Unchecked);
returnWidget->setProperty("MemberListType", QVariant(Bool));
return returnWidget;
}
*/
return QItemDelegate::createEditor(parent, option, index);
}
void MemberDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{
if(editor->property("MemberListType")==Date){
QDate date = ((QDateEdit*) editor)->date();
model->setData(index, date.toString("yyyy-MM-dd"));
}
else
QItemDelegate::setModelData(editor, model, index);
}