Subversion Repositories svn1-original

Rev

Rev 111 | Rev 145 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
111 david 1
#include <QtGui>
2
#include "timedelegate.h"
3
 
4
/*
5
    timedelegate.cpp
6
 
7
    A delegate that allows the user to change integer values from the model
8
    using a date time widget.
9
*/
10
 
11
timeDelegate::timeDelegate(QObject *parent)
12
    : QItemDelegate(parent)
13
{
14
}
15
 
16
QWidget *timeDelegate::createEditor(QWidget *parent,
17
    const QStyleOptionViewItem &/* option */,
18
    const QModelIndex &/* index */) const
19
{
20
    QTimeEdit *editor = new QTimeEdit(parent);
21
    editor->setDisplayFormat("hh:mm:ss");
22
 
23
    return editor;
24
}
25
 
26
void timeDelegate::setEditorData(QWidget *editor,
27
                                    const QModelIndex &index) const
28
{
29
    QTime value = index.model()->data(index, Qt::EditRole).toTime();
30
 
31
    QTimeEdit *timeEdit = static_cast<QTimeEdit*>(editor);
32
    timeEdit->setTime(value);
33
}
34
 
115 david 35
 
111 david 36
void timeDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
37
                                   const QModelIndex &index) const
38
{
39
    QTimeEdit *timeEdit = static_cast<QTimeEdit*>(editor);
40
    timeEdit->interpretText();
41
    QTime value = timeEdit->time();
42
 
43
    model->setData(index, value, Qt::EditRole);
44
}
45
 
46
void timeDelegate::updateEditorGeometry(QWidget *editor,
47
    const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
48
{
49
    editor->setGeometry(option.rect);
50
}
115 david 51