-
Notifications
You must be signed in to change notification settings - Fork 18
/
CDateProperty.cpp
166 lines (115 loc) · 3.07 KB
/
CDateProperty.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
156
157
158
159
160
161
162
163
164
165
166
#include "CDateProperty.h"
#include <QDateEdit>
#include <QCalendarWidget>
CDateProperty::CDateProperty(const QByteArray &id, const QString &name, const QDate &value, const QDate &defaultValue):
CBaseProperty(id, name),
m_defaultValue(defaultValue)
{
setDate(value);
}
CDateProperty::CDateProperty(CBaseProperty *top, const QByteArray &id, const QString &name, const QDate &value, const QDate &defaultValue):
CBaseProperty(top, id, name),
m_defaultValue(defaultValue)
{
setDate(value);
}
void CDateProperty::setDate(const QDate &value)
{
m_value = value;
CBaseProperty::setValue();
}
QDate CDateProperty::getDate() const
{
return m_value;
}
void CDateProperty::setMaximumDate(const QDate &value)
{
m_maxDate = value;
CBaseProperty::setValue();
}
QDate CDateProperty::getMaximumDate() const
{
return m_maxDate;
}
void CDateProperty::setMinimumDate(const QDate &value)
{
m_minDate = value;
CBaseProperty::setValue();
}
QDate CDateProperty::getMinimumDate() const
{
return m_minDate;
}
void CDateProperty::setDateRange(const QDate &min, const QDate &max)
{
m_maxDate = max;
m_minDate = min;
CBaseProperty::setValue();
}
void CDateProperty::setDisplayFormat(const QString &format)
{
m_format = format;
displayValue();
}
QString CDateProperty::displayFormat() const
{
return m_format;
}
// reimp
QVariant CDateProperty::getVariantValue() const
{
return m_value;
}
void CDateProperty::displayValue()
{
if (treeWidget())
treeWidget()->blockSignals(true);
QString dateString = m_format.isEmpty() ? m_value.toString(): m_value.toString(m_format);
setText(1, dateString);
setToolTip(1, dateString);
if (treeWidget())
treeWidget()->blockSignals(false);
}
void CDateProperty::validateValue()
{
if (m_maxDate.isValid() && m_value > m_maxDate)
{
m_value = m_maxDate;
}
if (m_minDate.isValid() && m_value < m_minDate)
{
m_value = m_minDate;
}
}
QWidget* CDateProperty::createEditor() const
{
QDateEdit* dateEditor = new QDateEdit();
dateEditor->setCalendarPopup(true);
return dateEditor;
}
void CDateProperty::valueToEditor()
{
QDateEdit* dateEditor = dynamic_cast<QDateEdit*>(getActiveEditor());
if (dateEditor != NULL)
{
dateEditor->setDate(m_value);
if (m_minDate.isValid())
dateEditor->setMinimumDate(m_minDate);
else
dateEditor->clearMinimumDate();
if (m_maxDate.isValid())
dateEditor->setMaximumDate(m_maxDate);
else
dateEditor->clearMaximumDate();
dateEditor->setDisplayFormat(m_format);
}
}
void CDateProperty::valueFromEditor()
{
QDateEdit* dateEditor = dynamic_cast<QDateEdit*>(getActiveEditor());
if (dateEditor != NULL && dateEditor->date() != m_value)
{
setDate(dateEditor->date());
emitValueChanged();
}
}