Subversion Repositories svn1-original

Rev

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

Rev Author Line No. Line
145 david 1
/*============================================================================
2
**
3
**  Project/Product : 
4
**  Filename        : timedelegate.h
5
**  Author(s)       : DDP
6
**
7
**  Description     : A delgated widget to assist in the editing of time items
8
**                    within a table
9
**
10
**
11
***==========================================================================*/
12
 
111 david 13
#include <QtGui>
14
#include "timedelegate.h"
15
 
145 david 16
/*----------------------------------------------------------------------------
17
** FUNCTION           : timeDelegate
18
**
19
** DESCRIPTION        : Construct a new object
20
**
21
**                      A delegate that allows the user to change integer
22
**                      values from the model using a date time widget.
23
**
24
** INPUTS             : parent      - Parent object
25
**
26
** RETURNS            :
27
**
28
----------------------------------------------------------------------------*/
111 david 29
 
30
timeDelegate::timeDelegate(QObject *parent)
31
    : QItemDelegate(parent)
32
{
33
}
34
 
145 david 35
/*----------------------------------------------------------------------------
36
** FUNCTION           : createEditor
37
**
38
** DESCRIPTION        : Create an editor widget
39
**
40
**
41
** INPUTS             : parent
42
**                      option
43
**                      index
44
**
45
** RETURNS            : A QTimeEditor widget
46
**
47
----------------------------------------------------------------------------*/
48
 
49
 
111 david 50
QWidget *timeDelegate::createEditor(QWidget *parent,
51
    const QStyleOptionViewItem &/* option */,
52
    const QModelIndex &/* index */) const
53
{
54
    QTimeEdit *editor = new QTimeEdit(parent);
55
    editor->setDisplayFormat("hh:mm:ss");
56
 
57
    return editor;
58
}
59
 
145 david 60
/*----------------------------------------------------------------------------
61
** FUNCTION           : setEditorData
62
**
63
** DESCRIPTION        : Inserts model data into the editor widget
64
**
65
**
66
** INPUTS             : editor      - Ref to editor widget
67
**                      index       -
68
**
69
** RETURNS            :
70
**
71
----------------------------------------------------------------------------*/
72
 
111 david 73
void timeDelegate::setEditorData(QWidget *editor,
74
                                    const QModelIndex &index) const
75
{
76
    QTime value = index.model()->data(index, Qt::EditRole).toTime();
77
 
78
    QTimeEdit *timeEdit = static_cast<QTimeEdit*>(editor);
79
    timeEdit->setTime(value);
80
}
81
 
145 david 82
/*----------------------------------------------------------------------------
83
** FUNCTION           : setModelData
84
**
85
** DESCRIPTION        : Extract data from the editor widget and update the model
86
**
87
**
88
** INPUTS             : editor      - Target widget
89
**                      model       - Current model
90
**                      index       - Index into model
91
**
92
** RETURNS            :
93
**
94
----------------------------------------------------------------------------*/
115 david 95
 
111 david 96
void timeDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
97
                                   const QModelIndex &index) const
98
{
99
    QTimeEdit *timeEdit = static_cast<QTimeEdit*>(editor);
100
    timeEdit->interpretText();
101
    QTime value = timeEdit->time();
102
 
103
    model->setData(index, value, Qt::EditRole);
104
}
105
 
145 david 106
/*----------------------------------------------------------------------------
107
** FUNCTION           : updateEditorGeometry
108
**
109
** DESCRIPTION        : Updates the geometry of the editor widget
110
**
111
**
112
** INPUTS             : editor      - Target widget
113
**                      option      -
114
*                       index
115
**
116
** RETURNS            :
117
**
118
----------------------------------------------------------------------------*/
119
 
111 david 120
void timeDelegate::updateEditorGeometry(QWidget *editor,
121
    const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
122
{
123
    editor->setGeometry(option.rect);
124
}
115 david 125