-
Notifications
You must be signed in to change notification settings - Fork 18
/
CTimeProperty.cpp
155 lines (108 loc) · 2.82 KB
/
CTimeProperty.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#include "CTimeProperty.h"
#include <QTimeEdit>
CTimeProperty::CTimeProperty(const QByteArray &id, const QString &name, const QTime &value, const QTime &defaultValue):
CBaseProperty(id, name),
m_defaultValue(defaultValue),
m_format("HH:mm:ss")
{
setTime(value);
}
CTimeProperty::CTimeProperty(CBaseProperty *top, const QByteArray &id, const QString &name, const QTime &value, const QTime &defaultValue):
CBaseProperty(top, id, name),
m_defaultValue(defaultValue),
m_format("HH:mm:ss")
{
setTime(value);
}
void CTimeProperty::setTime(const QTime &value)
{
m_value = value;
CBaseProperty::setValue();
}
QTime CTimeProperty::getTime() const
{
return m_value;
}
void CTimeProperty::setMaximumTime(const QTime &value)
{
m_maxTime = value;
CBaseProperty::setValue();
}
QTime CTimeProperty::getMaximumTime() const
{
return m_maxTime;
}
void CTimeProperty::setMinimumTime(const QTime &value)
{
m_minTime = value;
CBaseProperty::setValue();
}
QTime CTimeProperty::getMinimumTime() const
{
return m_minTime;
}
void CTimeProperty::setTimeRange(const QTime &min, const QTime &max)
{
m_maxTime = max;
m_minTime = min;
CBaseProperty::setValue();
}
void CTimeProperty::setDisplayFormat(const QString &format)
{
m_format = format;
displayValue();
}
QString CTimeProperty::displayFormat() const
{
return m_format;
}
// reimp
QVariant CTimeProperty::getVariantValue() const
{
return m_value;
}
void CTimeProperty::displayValue()
{
if (treeWidget())
treeWidget()->blockSignals(true);
QString timeString = m_format.isEmpty() ? m_value.toString(): m_value.toString(m_format);
setText(1, timeString);
setToolTip(1, timeString);
if (treeWidget())
treeWidget()->blockSignals(false);
}
void CTimeProperty::validateValue()
{
if (m_maxTime.isValid() && m_value > m_maxTime)
{
m_value = m_maxTime;
}
if (m_minTime.isValid() && m_value < m_minTime)
{
m_value = m_minTime;
}
}
QWidget* CTimeProperty::createEditor() const
{
QTimeEdit* timeEditor = new QTimeEdit();
return timeEditor;
}
void CTimeProperty::valueToEditor()
{
QTimeEdit* timeEditor = dynamic_cast<QTimeEdit*>(getActiveEditor());
if (timeEditor != NULL)
{
timeEditor->setTime(m_value);
timeEditor->setTimeRange(m_minTime, m_maxTime);
timeEditor->setDisplayFormat(m_format);
}
}
void CTimeProperty::valueFromEditor()
{
QTimeEdit* timeEditor = dynamic_cast<QTimeEdit*>(getActiveEditor());
if (timeEditor != NULL && timeEditor->time() != m_value)
{
setTime(timeEditor->time());
emitValueChanged();
}
}