Subversion Repositories svn1

Rev

Rev 331 | Details | Compare with Previous | Last modification | View Log | RSS feed

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