-
Notifications
You must be signed in to change notification settings - Fork 0
/
silodelegate.cpp
49 lines (44 loc) · 1.13 KB
/
silodelegate.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
/*
* silodelegate.cpp
*
* Created on: Dec 10, 2008
* Author: Vincent
*/
#include "silodelegate.h"
#include "common.h"
#include <QLineEdit>
using namespace Silo;
SiloDelegate::SiloDelegate(QObject *parent) :
QStyledItemDelegate(parent) {
}
QWidget *SiloDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem &, const QModelIndex &index) const {
switch (index.column()) {
case ID_LABEL:
case ID_COMMENT:
return new QLineEdit(parent);
default:
return 0;
}
}
void SiloDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const {
switch (index.column()) {
case ID_LABEL:
case ID_COMMENT:
((QLineEdit *) editor)->setText(index.data(Qt::DisplayRole).toString());
return;
}
}
void SiloDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const {
switch (index.column()) {
case ID_LABEL:
case ID_COMMENT:
model->setData(index, ((QLineEdit*) editor)->text(), Qt::DisplayRole);
return;
}
}
void SiloDelegate::updateEditorGeometry(QWidget *editor,
const QStyleOptionViewItem &option, const QModelIndex &index) const {
editor->setGeometry(option.rect);
}