Subversion Repositories svn1-original

Rev

Rev 115 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 115 Rev 145
Line -... Line 1...
-
 
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
 
1
#include <QtGui>
13
#include <QtGui>
2
#include "timedelegate.h"
14
#include "timedelegate.h"
3
 
15
 
-
 
16
/*----------------------------------------------------------------------------
-
 
17
** FUNCTION           : timeDelegate
4
/*
18
**
5
    timedelegate.cpp
19
** DESCRIPTION        : Construct a new object
6
 
20
**
7
    A delegate that allows the user to change integer values from the model
21
**                      A delegate that allows the user to change integer
8
    using a date time widget.
22
**                      values from the model using a date time widget.
-
 
23
**
-
 
24
** INPUTS             : parent      - Parent object
-
 
25
**
-
 
26
** RETURNS            :
9
*/
27
**
-
 
28
----------------------------------------------------------------------------*/
10
 
29
 
11
timeDelegate::timeDelegate(QObject *parent)
30
timeDelegate::timeDelegate(QObject *parent)
12
    : QItemDelegate(parent)
31
    : QItemDelegate(parent)
13
{
32
{
14
}
33
}
15
 
34
 
-
 
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
 
16
QWidget *timeDelegate::createEditor(QWidget *parent,
50
QWidget *timeDelegate::createEditor(QWidget *parent,
17
    const QStyleOptionViewItem &/* option */,
51
    const QStyleOptionViewItem &/* option */,
18
    const QModelIndex &/* index */) const
52
    const QModelIndex &/* index */) const
19
{
53
{
20
    QTimeEdit *editor = new QTimeEdit(parent);
54
    QTimeEdit *editor = new QTimeEdit(parent);
21
    editor->setDisplayFormat("hh:mm:ss");
55
    editor->setDisplayFormat("hh:mm:ss");
22
 
56
 
23
    return editor;
57
    return editor;
24
}
58
}
25
 
59
 
-
 
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
 
26
void timeDelegate::setEditorData(QWidget *editor,
73
void timeDelegate::setEditorData(QWidget *editor,
27
                                    const QModelIndex &index) const
74
                                    const QModelIndex &index) const
28
{
75
{
29
    QTime value = index.model()->data(index, Qt::EditRole).toTime();
76
    QTime value = index.model()->data(index, Qt::EditRole).toTime();
30
 
77
 
31
    QTimeEdit *timeEdit = static_cast<QTimeEdit*>(editor);
78
    QTimeEdit *timeEdit = static_cast<QTimeEdit*>(editor);
32
    timeEdit->setTime(value);
79
    timeEdit->setTime(value);
33
}
80
}
34
 
81
 
-
 
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
----------------------------------------------------------------------------*/
35
 
95
 
36
void timeDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
96
void timeDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
37
                                   const QModelIndex &index) const
97
                                   const QModelIndex &index) const
38
{
98
{
39
    QTimeEdit *timeEdit = static_cast<QTimeEdit*>(editor);
99
    QTimeEdit *timeEdit = static_cast<QTimeEdit*>(editor);
Line 41... Line 101...
41
    QTime value = timeEdit->time();
101
    QTime value = timeEdit->time();
42
 
102
 
43
    model->setData(index, value, Qt::EditRole);
103
    model->setData(index, value, Qt::EditRole);
44
}
104
}
45
 
105
 
-
 
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
 
46
void timeDelegate::updateEditorGeometry(QWidget *editor,
120
void timeDelegate::updateEditorGeometry(QWidget *editor,
47
    const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
121
    const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
48
{
122
{
49
    editor->setGeometry(option.rect);
123
    editor->setGeometry(option.rect);
50
}
124
}