Subversion Repositories svn1-original

Rev

Rev 335 | 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)
161 david 31
    : QStyledItemDelegate(parent)
111 david 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
 
161 david 103
    //model->setData(index, "--:--:--", Qt::DisplayRole);
111 david 104
    model->setData(index, value, Qt::EditRole);
105
}
106
 
145 david 107
/*----------------------------------------------------------------------------
108
** FUNCTION           : updateEditorGeometry
109
**
110
** DESCRIPTION        : Updates the geometry of the editor widget
111
**
112
**
113
** INPUTS             : editor      - Target widget
114
**                      option      -
115
*                       index
116
**
117
** RETURNS            :
118
**
119
----------------------------------------------------------------------------*/
120
 
111 david 121
void timeDelegate::updateEditorGeometry(QWidget *editor,
122
    const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
123
{
124
    editor->setGeometry(option.rect);
125
}
115 david 126
 
161 david 127
/*----------------------------------------------------------------------------
128
** FUNCTION           : displayText
129
**
130
** DESCRIPTION        : Control the manner in which the text is displayed
131
**
132
**
133
** INPUTS             : value           - Data from the model
134
**                      locale          - Current local
135
**
136
** RETURNS            : Text to be displayed
137
**
138
----------------------------------------------------------------------------*/
139
 
140
 
141
QString timeDelegate::displayText ( const QVariant & value, const QLocale & locale ) const
142
{
143
    if ( value.toTime().isValid())
144
    {
145
        return (value.toTime().toString("hh:mm:ss"));
146
    }
147
    return (QString("--:--:--"));
148
}
149