Subversion Repositories svn1

Rev

Rev 111 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
107 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
//! [2]
35
 
36
//! [3]
37
void timeDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
38
                                   const QModelIndex &index) const
39
{
40
    QTimeEdit *timeEdit = static_cast<QTimeEdit*>(editor);
41
    timeEdit->interpretText();
42
    QTime value = timeEdit->time();
43
 
44
    model->setData(index, value, Qt::EditRole);
45
}
46
//! [3]
47
 
48
//! [4]
49
void timeDelegate::updateEditorGeometry(QWidget *editor,
50
    const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
51
{
52
    editor->setGeometry(option.rect);
53
}
54
//! [4]