QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
qgsdatetimeeditconfig.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsdatetimeeditconfig.cpp
3 --------------------------------------
4 Date : 03.2014
5 Copyright : (C) 2014 Denis Rouzaud
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
17#include "moc_qgsdatetimeeditconfig.cpp"
19#include "qgsvectorlayer.h"
21
23 : QgsEditorConfigWidget( vl, fieldIdx, parent )
24{
25 setupUi( this );
26
27 mFieldFormatComboBox->clear();
28 mFieldFormatComboBox->addItem( tr( "Date" ), QgsDateTimeFieldFormatter::DATE_FORMAT );
29 mFieldFormatComboBox->addItem( tr( "Time" ), QgsDateTimeFieldFormatter::TIME_FORMAT );
30 mFieldFormatComboBox->addItem( tr( "Date Time" ), QgsDateTimeFieldFormatter::DATETIME_FORMAT );
31 mFieldFormatComboBox->addItem( tr( "ISO Date Time" ), QgsDateTimeFieldFormatter::QT_ISO_FORMAT );
32 mFieldFormatComboBox->addItem( tr( "Custom" ), QString() );
33
34 mHelpLabel->setTextFormat( Qt::RichText );
35 mHelpLabel->setText(
36 QStringLiteral(
37 "<html><head/><body>"
38 "<table border=\"0\" style=\"margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px;\" cellspacing=\"2\" cellpadding=\"0\" bgcolor=\"#f6f6f6\">"
39 "<thead><tr>"
40 "<td style=\"vertical-align:top; padding-left:10; padding-right:15; padding-top:5; padding-bottom:5;\">"
41 "<p align=\"left\"><span style=\"font-family:'Open Sans,sans-serif'; font-size:12px; font-weight:600; color:#363534;\">"
42 )
43 + tr( "Qt ISO Date format" )
44 + QStringLiteral( "</span></p>"
45 "</td>"
46 "</tr></thead>"
47 "<tr>"
48 "<td bgcolor=\"#ffffff\" style=\"vertical-align:top; padding-left:10; padding-right:10; padding-top:3; padding-bottom:3;\">"
49 "<p><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e; background-color:#ffffff;\">"
50 "<a href=\"http://www.iso.org/iso/catalogue_detail?csnumber=40874\">" ) //#spellok
51 + tr( "ISO 8601" )
52 + QStringLiteral( "</a> " )
53 + tr( "extended format: either <code>yyyy-MM-dd</code> for dates or <code>yyyy-MM-ddTHH:mm:ss</code> (e.g. 2017-07-24T15:46:29), or with a time-zone suffix (Z for UTC otherwise an offset as [+|-]HH:mm) where appropriate for combined dates and times." )
54 + QStringLiteral(
55 "</span></p>"
56 "</td>"
57 "</tr>"
58 "</table>"
59 "<br>"
60 "<table border=\"0\" style=\"margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px;\" cellspacing=\"2\" cellpadding=\"0\" bgcolor=\"#f6f6f6\">"
61 "<thead><tr>"
62 "<td style=\"vertical-align:top; padding-left:10; padding-right:15; padding-top:5; padding-bottom:5;\">"
63 "<p align=\"center\"><span style=\"font-family:'Open Sans,sans-serif'; font-size:12px; font-weight:600; color:#363534;\">"
64 )
65 + tr( "Format" )
66 + QStringLiteral( "</span></p>"
67 "</td>"
68 "<td style=\"vertical-align:top; padding-left:10; padding-right:15; padding-top:5; padding-bottom:5;\">"
69 "<p align=\"center\"><span style=\"font-family:'Open Sans,sans-serif'; font-size:12px; font-weight:600; color:#363534;\">" )
70 + tr( "Examples result" )
71 + QStringLiteral( "</span></p>"
72 "</td>"
73 "</tr></thead>"
74 "<tr>"
75 "<td bgcolor=\"#f6f6f6\" style=\"vertical-align:top; padding-left:10; padding-right:10; padding-top:3; padding-bottom:3;\">"
76 "<p><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e; background-color:#f6f6f6;\">dd.MM.yyyy</span></p>"
77 "</td>"
78 "<td bgcolor=\"#f6f6f6\" style=\"vertical-align:top; padding-left:10; padding-right:10; padding-top:3; padding-bottom:3;\">"
79 "<p><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e; background-color:#f6f6f6;\">21.05.2001</span></p>"
80 "</td>"
81 "</tr>"
82 "<tr>"
83 "<td bgcolor=\"#ffffff\" style=\"vertical-align:top; padding-left:10; padding-right:10; padding-top:3; padding-bottom:3;\">"
84 "<p><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e; background-color:#ffffff;\">ddd MMMM d yy</span></p>"
85 "</td>"
86 "<td bgcolor=\"#ffffff\" style=\"vertical-align:top; padding-left:10; padding-right:10; padding-top:3; padding-bottom:3;\">"
87 "<p><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e; background-color:#ffffff;\">Tue May 21 01</span></p>"
88 "</td>"
89 "</tr>"
90 "<tr>"
91 "<td bgcolor=\"#f6f6f6\" style=\"vertical-align:top; padding-left:10; padding-right:10; padding-top:3; padding-bottom:3;\">"
92 "<p><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e; background-color:#f6f6f6;\">hh:mm:ss.zzz</span></p>"
93 "</td>"
94 "<td bgcolor=\"#f6f6f6\" style=\"vertical-align:top; padding-left:10; padding-right:10; padding-top:3; padding-bottom:3;\">"
95 "<p><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e; background-color:#f6f6f6;\">14:13:09.042</span></p>"
96 "</td>"
97 "</tr>"
98 "<tr>"
99 "<td bgcolor=\"#ffffff\" style=\"vertical-align:top; padding-left:10; padding-right:10; padding-top:3; padding-bottom:3;\">"
100 "<p><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e; background-color:#ffffff;\">h:m:s ap</span></p>"
101 "</td>"
102 "<td bgcolor=\"#ffffff\" style=\"vertical-align:top; padding-left:10; padding-right:10; padding-top:3; padding-bottom:3;\">"
103 "<p><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e; background-color:#ffffff;\">2:13:9 pm</span></p>"
104 "</td>"
105 "</tr>"
106 "</table>"
107 "<p><br/></p>"
108 "<table border=\"0\" style=\"margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px;\" cellspacing=\"2\" cellpadding=\"0\" bgcolor=\"#f6f6f6\">"
109 "<thead><tr>"
110 "<td style=\"vertical-align:top; padding-left:10; padding-right:15; padding-top:5; padding-bottom:5;\">"
111 "<p align=\"center\"><span style=\"font-family:'Open Sans,sans-serif'; font-size:12px; font-weight:600; color:#363534;\">" )
112 + tr( "Expression" )
113 + QStringLiteral( "</span></p>"
114 "</td>"
115 "<td style=\"vertical-align:top; padding-left:10; padding-right:15; padding-top:5; padding-bottom:5;\">"
116 "<p align=\"center\"><span style=\"font-family:'Open Sans,sans-serif'; font-size:12px; font-weight:600; color:#363534;\">" )
117 + tr( "Date output" )
118 + QStringLiteral( "</span></p>"
119 "</td>"
120 "</tr></thead>"
121 "<tr>"
122 "<td bgcolor=\"#f6f6f6\" style=\"vertical-align:top; padding-left:10; padding-right:10; padding-top:3; padding-bottom:3;\">"
123 "<p><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e; background-color:#f6f6f6;\">d</span></p>"
124 "</td>"
125 "<td bgcolor=\"#f6f6f6\" style=\"vertical-align:top; padding-left:10; padding-right:10; padding-top:3; padding-bottom:3;\">"
126 "<p><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e; background-color:#f6f6f6;\">" )
127 + tr( "the day as number without a leading zero (1 to 31)" )
128 + QStringLiteral( "</span></p>"
129 "</td>"
130 "</tr>"
131 "<tr>"
132 "<td bgcolor=\"#ffffff\" style=\"vertical-align:top; padding-left:10; padding-right:10; padding-top:3; padding-bottom:3;\">"
133 "<p><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e; background-color:#ffffff;\">dd</span></p>"
134 "</td>"
135 "<td bgcolor=\"#ffffff\" style=\"vertical-align:top; padding-left:10; padding-right:10; padding-top:3; padding-bottom:3;\">"
136 "<p><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e; background-color:#ffffff;\">" )
137 + tr( "the day as number with a leading zero (01 to 31)" )
138 + QStringLiteral( "</span></p>"
139 "</td>"
140 "</tr>"
141 "<tr>"
142 "<td bgcolor=\"#f6f6f6\" style=\"vertical-align:top; padding-left:10; padding-right:10; padding-top:3; padding-bottom:3;\">"
143 "<p><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e; background-color:#f6f6f6;\">ddd</span></p>"
144 "</td>"
145 "<td bgcolor=\"#f6f6f6\" style=\"vertical-align:top; padding-left:10; padding-right:10; padding-top:3; padding-bottom:3;\">"
146 "<p><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e; background-color:#f6f6f6;\">" )
147 + tr( "the abbreviated localized day name (e.g. 'Mon' to 'Sun'). Uses the system locale to localize the name, i.e. " )
148 + QStringLiteral( "</span><a href=\"http://qt-project.org/doc/qt-5/qlocale.html#system\"><span style=\"font-family:'Arial,Open Sans,sans-serif'; font-size:12px; font-weight:600; text-decoration: underline; color:#00732f;\">QLocale</span></a><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e;\">().</span></p>"
149 "</td>"
150 "</tr>"
151 "<tr>"
152 "<td bgcolor=\"#ffffff\" style=\"vertical-align:top; padding-left:10; padding-right:10; padding-top:3; padding-bottom:3;\">"
153 "<p><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e; background-color:#ffffff;\">dddd</span></p>"
154 "</td>"
155 "<td bgcolor=\"#ffffff\" style=\"vertical-align:top; padding-left:10; padding-right:10; padding-top:3; padding-bottom:3;\">"
156 "<p><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e; background-color:#ffffff;\">" )
157 + tr( "the long localized day name (e.g. 'Monday' to '" )
158 + QStringLiteral( "</span><a href=\"http://qt-project.org/doc/qt-5/qt.html#DayOfWeek-enum\"><span style=\"font-family:'Arial,Open Sans,sans-serif'; font-size:12px; font-weight:600; text-decoration: underline; color:#00732f;\">Qt::Sunday</span></a><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e;\">')." )
159 + tr( "Uses the system locale to localize the name, i.e. " )
160 + QStringLiteral( "</span><a href=\"http://qt-project.org/doc/qt-5/qlocale.html#system\"><span style=\"font-family:'Arial,Open Sans,sans-serif'; font-size:12px; font-weight:600; text-decoration: underline; color:#00732f;\">QLocale</span></a><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e;\">().</span></p>"
161 "</td>"
162 "</tr>"
163 "<tr>"
164 "<td bgcolor=\"#f6f6f6\" style=\"vertical-align:top; padding-left:10; padding-right:10; padding-top:3; padding-bottom:3;\">"
165 "<p><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e; background-color:#f6f6f6;\">M</span></p>"
166 "</td>"
167 "<td bgcolor=\"#f6f6f6\" style=\"vertical-align:top; padding-left:10; padding-right:10; padding-top:3; padding-bottom:3;\">"
168 "<p><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e; background-color:#f6f6f6;\">" )
169 + tr( "the month as number without a leading zero (1-12)" )
170 + QStringLiteral( "</span></p>"
171 "</td>"
172 "</tr>"
173 "<tr>"
174 "<td bgcolor=\"#ffffff\" style=\"vertical-align:top; padding-left:10; padding-right:10; padding-top:3; padding-bottom:3;\">"
175 "<p><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e; background-color:#ffffff;\">MM</span></p>"
176 "</td>"
177 "<td bgcolor=\"#ffffff\" style=\"vertical-align:top; padding-left:10; padding-right:10; padding-top:3; padding-bottom:3;\">"
178 "<p><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e; background-color:#ffffff;\">" )
179 + tr( "the month as number with a leading zero (01-12)" )
180 + QStringLiteral( "</span></p>"
181 "</td>"
182 "</tr>"
183 "<tr>"
184 "<td bgcolor=\"#f6f6f6\" style=\"vertical-align:top; padding-left:10; padding-right:10; padding-top:3; padding-bottom:3;\">"
185 "<p><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e; background-color:#f6f6f6;\">MMM</span></p>"
186 "</td>"
187 "<td bgcolor=\"#f6f6f6\" style=\"vertical-align:top; padding-left:10; padding-right:10; padding-top:3; padding-bottom:3;\">"
188 "<p><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e; background-color:#f6f6f6;\">" )
189 + tr( "the abbreviated localized month name (e.g. 'Jan' to 'Dec'). Uses the system locale to localize the name, i.e." )
190 + QStringLiteral( "</span><a href=\"http://qt-project.org/doc/qt-5/qlocale.html#system\"><span style=\"font-family:'Arial,Open Sans,sans-serif'; font-size:12px; font-weight:600; text-decoration: underline; color:#00732f;\">QLocale</span></a><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e;\">().</span></p>"
191 "</td>"
192 "</tr>"
193 "<tr>"
194 "<td bgcolor=\"#ffffff\" style=\"vertical-align:top; padding-left:10; padding-right:10; padding-top:3; padding-bottom:3;\">"
195 "<p><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e; background-color:#ffffff;\">MMMM</span></p>"
196 "</td>"
197 "<td bgcolor=\"#ffffff\" style=\"vertical-align:top; padding-left:10; padding-right:10; padding-top:3; padding-bottom:3;\">"
198 "<p><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e; background-color:#ffffff;\">" )
199 + tr( "the long localized month name (e.g. 'January' to 'December'). Uses the system locale to localize the name, i.e." )
200 + QStringLiteral( "</span><a href=\"http://qt-project.org/doc/qt-5/qlocale.html#system\"><span style=\"font-family:'Arial,Open Sans,sans-serif'; font-size:12px; font-weight:600; text-decoration: underline; color:#00732f;\">QLocale</span></a><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e;\">().</span></p>"
201 "</td>"
202 "</tr>"
203 "<tr>"
204 "<td bgcolor=\"#f6f6f6\" style=\"vertical-align:top; padding-left:10; padding-right:10; padding-top:3; padding-bottom:3;\">"
205 "<p><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e; background-color:#f6f6f6;\">yy</span></p>"
206 "</td>"
207 "<td bgcolor=\"#f6f6f6\" style=\"vertical-align:top; padding-left:10; padding-right:10; padding-top:3; padding-bottom:3;\">"
208 "<p><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e; background-color:#f6f6f6;\">" )
209 + tr( "the year as two digit number (00-99)" )
210 + QStringLiteral( "</span></p>"
211 "</td>"
212 "</tr>"
213 "<tr>"
214 "<td bgcolor=\"#ffffff\" style=\"vertical-align:top; padding-left:10; padding-right:10; padding-top:3; padding-bottom:3;\">"
215 "<p><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e; background-color:#ffffff;\">yyyy</span></p>"
216 "</td>"
217 "<td bgcolor=\"#ffffff\" style=\"vertical-align:top; padding-left:10; padding-right:10; padding-top:3; padding-bottom:3;\">"
218 "<p><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e; background-color:#ffffff;\">" )
219 + tr( "the year as four digit number" )
220 + QStringLiteral( "</span></p>"
221 "</td>"
222 "</tr>"
223 "</table>"
224 "<p><br/></p>"
225 "<table border=\"0\" style=\"margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px;\" cellspacing=\"2\" cellpadding=\"0\" bgcolor=\"#f6f6f6\">"
226 "<thead><tr>"
227 "<td style=\"vertical-align:top; padding-left:10; padding-right:15; padding-top:5; padding-bottom:5;\">"
228 "<p align=\"center\"><span style=\"font-family:'Open Sans,sans-serif'; font-size:12px; font-weight:600; color:#363534;\">" )
229 + tr( "Expression" )
230 + QStringLiteral( "</span></p>"
231 "</td>"
232 "<td style=\"vertical-align:top; padding-left:10; padding-right:15; padding-top:5; padding-bottom:5;\">"
233 "<p align=\"center\"><span style=\"font-family:'Open Sans,sans-serif'; font-size:12px; font-weight:600; color:#363534;\">" )
234 + tr( "Time output" )
235 + QStringLiteral( "</span></p>"
236 "</td>"
237 "</tr></thead>"
238 "<tr>"
239 "<td bgcolor=\"#f6f6f6\" style=\"vertical-align:top; padding-left:10; padding-right:10; padding-top:3; padding-bottom:3;\">"
240 "<p><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e; background-color:#f6f6f6;\">h</span></p>"
241 "</td>"
242 "<td bgcolor=\"#f6f6f6\" style=\"vertical-align:top; padding-left:10; padding-right:10; padding-top:3; padding-bottom:3;\">"
243 "<p><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e; background-color:#f6f6f6;\">" )
244 + tr( "the hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display)" )
245 + QStringLiteral( "</span></p>"
246 "</td>"
247 "</tr>"
248 "<tr>"
249 "<td bgcolor=\"#ffffff\" style=\"vertical-align:top; padding-left:10; padding-right:10; padding-top:3; padding-bottom:3;\">"
250 "<p><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e; background-color:#ffffff;\">hh</span></p>"
251 "</td>"
252 "<td bgcolor=\"#ffffff\" style=\"vertical-align:top; padding-left:10; padding-right:10; padding-top:3; padding-bottom:3;\">"
253 "<p><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e; background-color:#ffffff;\">" )
254 + tr( "the hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display)" )
255 + QStringLiteral( "</span></p>"
256 "</td>"
257 "</tr>"
258 "<tr>"
259 "<td bgcolor=\"#f6f6f6\" style=\"vertical-align:top; padding-left:10; padding-right:10; padding-top:3; padding-bottom:3;\">"
260 "<p><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e; background-color:#f6f6f6;\">H</span></p>"
261 "</td>"
262 "<td bgcolor=\"#f6f6f6\" style=\"vertical-align:top; padding-left:10; padding-right:10; padding-top:3; padding-bottom:3;\">"
263 "<p><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e; background-color:#f6f6f6;\">" )
264 + tr( "the hour without a leading zero (0 to 23, even with AM/PM display)" )
265 + QStringLiteral( "</span></p>"
266 "</td>"
267 "</tr>"
268 "<tr>"
269 "<td bgcolor=\"#ffffff\" style=\"vertical-align:top; padding-left:10; padding-right:10; padding-top:3; padding-bottom:3;\">"
270 "<p><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e; background-color:#ffffff;\">HH</span></p>"
271 "</td>"
272 "<td bgcolor=\"#ffffff\" style=\"vertical-align:top; padding-left:10; padding-right:10; padding-top:3; padding-bottom:3;\">"
273 "<p><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e; background-color:#ffffff;\">" )
274 + tr( "the hour with a leading zero (00 to 23, even with AM/PM display)" )
275 + QStringLiteral( "</span></p>"
276 "</td>"
277 "</tr>"
278 "<tr>"
279 "<td bgcolor=\"#f6f6f6\" style=\"vertical-align:top; padding-left:10; padding-right:10; padding-top:3; padding-bottom:3;\">"
280 "<p><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e; background-color:#f6f6f6;\">m</span></p>"
281 "</td>"
282 "<td bgcolor=\"#f6f6f6\" style=\"vertical-align:top; padding-left:10; padding-right:10; padding-top:3; padding-bottom:3;\">"
283 "<p><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e; background-color:#f6f6f6;\">" )
284 + tr( "the minute without a leading zero (0 to 59)" )
285 + QStringLiteral( "</span></p>"
286 "</td>"
287 "</tr>"
288 "<tr>"
289 "<td bgcolor=\"#ffffff\" style=\"vertical-align:top; padding-left:10; padding-right:10; padding-top:3; padding-bottom:3;\">"
290 "<p><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e; background-color:#ffffff;\">mm</span></p>"
291 "</td>"
292 "<td bgcolor=\"#ffffff\" style=\"vertical-align:top; padding-left:10; padding-right:10; padding-top:3; padding-bottom:3;\">"
293 "<p><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e; background-color:#ffffff;\">" )
294 + tr( "the minute with a leading zero (00 to 59)" )
295 + QStringLiteral( "</span></p>"
296 "</td>"
297 "</tr>"
298 "<tr>"
299 "<td bgcolor=\"#f6f6f6\" style=\"vertical-align:top; padding-left:10; padding-right:10; padding-top:3; padding-bottom:3;\">"
300 "<p><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e; background-color:#f6f6f6;\">s</span></p>"
301 "</td>"
302 "<td bgcolor=\"#f6f6f6\" style=\"vertical-align:top; padding-left:10; padding-right:10; padding-top:3; padding-bottom:3;\">"
303 "<p><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e; background-color:#f6f6f6;\">" )
304 + tr( "the second without a leading zero (0 to 59)" )
305 + QStringLiteral( "</span></p>"
306 "</td>"
307 "</tr>"
308 "<tr>"
309 "<td bgcolor=\"#ffffff\" style=\"vertical-align:top; padding-left:10; padding-right:10; padding-top:3; padding-bottom:3;\">"
310 "<p><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e; background-color:#ffffff;\">ss</span></p>"
311 "</td>"
312 "<td bgcolor=\"#ffffff\" style=\"vertical-align:top; padding-left:10; padding-right:10; padding-top:3; padding-bottom:3;\">"
313 "<p><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e; background-color:#ffffff;\">" )
314 + tr( "the second with a leading zero (00 to 59)" )
315 + QStringLiteral( "</span></p>"
316 "</td>"
317 "</tr>"
318 "<tr>"
319 "<td bgcolor=\"#f6f6f6\" style=\"vertical-align:top; padding-left:10; padding-right:10; padding-top:3; padding-bottom:3;\">"
320 "<p><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e; background-color:#f6f6f6;\">z</span></p>"
321 "</td>"
322 "<td bgcolor=\"#f6f6f6\" style=\"vertical-align:top; padding-left:10; padding-right:10; padding-top:3; padding-bottom:3;\">"
323 "<p><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e; background-color:#f6f6f6;\">" )
324 + tr( "the milliseconds without trailing zeroes (0 to 999)" )
325 + QStringLiteral( "</span></p>"
326 "</td>"
327 "</tr>"
328 "<tr>"
329 "<td bgcolor=\"#ffffff\" style=\"vertical-align:top; padding-left:10; padding-right:10; padding-top:3; padding-bottom:3;\">"
330 "<p><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e; background-color:#ffffff;\">zzz</span></p>"
331 "</td>"
332 "<td bgcolor=\"#ffffff\" style=\"vertical-align:top; padding-left:10; padding-right:10; padding-top:3; padding-bottom:3;\">"
333 "<p><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e; background-color:#ffffff;\">" )
334 + tr( "the milliseconds with trailing zeroes (000 to 999)" )
335 + QStringLiteral( "</span></p>"
336 "</td>"
337 "</tr><tr>"
338 "<td bgcolor=\"#f6f6f6\" style=\"vertical-align:top; padding-left:10; padding-right:10; padding-top:3; padding-bottom:3;\">"
339 "<p><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e; background-color:#f6f6f6;\">AP or A</span></p>"
340 "</td>"
341 "<td bgcolor=\"#f6f6f6\" style=\"vertical-align:top; padding-left:10; padding-right:10; padding-top:3; padding-bottom:3;\">"
342 "<p><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e; background-color:#f6f6f6;\">" )
343 + tr( "use AM/PM display." )
344 + QStringLiteral( "</span><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; font-style:italic; color:#66666e;\">A/AP</span><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e;\"> " )
345 + tr( "will be replaced by either" )
346 + QStringLiteral( "&quot;AM&quot;" )
347 + tr( "or" )
348 + QStringLiteral( "&quot;PM&quot;.</span></p>"
349 "</td>"
350 "</tr>"
351 "<tr>"
352 "<td bgcolor=\"#ffffff\" style=\"vertical-align:top; padding-left:10; padding-right:10; padding-top:3; padding-bottom:3;\">"
353 "<p><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e; background-color:#ffffff;\">ap " )
354 + tr( "or" )
355 + QStringLiteral( " a</span></p>"
356 "</td>"
357 "<td bgcolor=\"#ffffff\" style=\"vertical-align:top; padding-left:10; padding-right:10; padding-top:3; padding-bottom:3;\">"
358 "<p><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e; background-color:#ffffff;\">" )
359 + tr( "use am/pm display." )
360 + QStringLiteral( "</span><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; font-style:italic; color:#66666e;\">a/ap</span><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e;\"> " )
361 + tr( "will be replaced by either " )
362 + QStringLiteral( "&quot;am&quot;" )
363 + tr( "or" )
364 + QStringLiteral( "&quot;pm&quot;.</span></p>"
365 "</td>"
366 "</tr>"
367 "<tr>"
368 "<td bgcolor=\"#f6f6f6\" style=\"vertical-align:top; padding-left:10; padding-right:10; padding-top:3; padding-bottom:3;\">"
369 "<p><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e; background-color:#f6f6f6;\">t</span></p>"
370 "</td>"
371 "<td bgcolor=\"#f6f6f6\" style=\"vertical-align:top; padding-left:10; padding-right:10; padding-top:3; padding-bottom:3;\">"
372 "<p><span style=\"font-family:'Open Sans,sans-serif'; font-size:11px; color:#66666e; background-color:#f6f6f6;\">" )
373 + tr( "the timezone (for example &quot;CEST&quot;)" )
374 + QStringLiteral( "</span></p>"
375 "</td>"
376 "</tr>"
377 "</table>"
378 "<p><br/></p>"
379 "</body></html>" )
380 );
381
382 mDemoDateTimeEdit->setDateTime( QDateTime::currentDateTime() );
383
384 connect( mDisplayFormatEdit, &QLineEdit::textChanged, this, &QgsDateTimeEditConfig::updateDemoWidget );
385 connect( mCalendarPopupCheckBox, &QAbstractButton::toggled, this, &QgsDateTimeEditConfig::updateDemoWidget );
386
387 connect( mFieldFormatComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsDateTimeEditConfig::updateFieldFormat );
388 connect( mFieldFormatEdit, &QLineEdit::textChanged, this, &QgsDateTimeEditConfig::updateDisplayFormat );
389 connect( mDisplayFormatComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsDateTimeEditConfig::displayFormatChanged );
390
391 connect( mFieldHelpToolButton, &QAbstractButton::clicked, this, &QgsDateTimeEditConfig::showHelp );
392 connect( mDisplayHelpToolButton, &QAbstractButton::clicked, this, &QgsDateTimeEditConfig::showHelp );
393
394 connect( mFieldFormatEdit, &QLineEdit::textChanged, this, &QgsEditorConfigWidget::changed );
395 connect( mDisplayFormatEdit, &QLineEdit::textChanged, this, &QgsEditorConfigWidget::changed );
396 connect( mCalendarPopupCheckBox, &QAbstractButton::toggled, this, &QgsEditorConfigWidget::changed );
397 connect( mAllowNullCheckBox, &QAbstractButton::toggled, this, &QgsEditorConfigWidget::changed );
398 connect( mFieldFormatGroupBox, &QGroupBox::toggled, this, [=]( bool checked ) {
399 //reset to default value when unchecking
400 if ( !checked )
401 {
402 const QgsField fieldDef = layer()->fields().at( field() );
403 const QString fieldFormat = QgsDateTimeFieldFormatter::defaultFormat( fieldDef.type() );
404 setFieldFormatCombo( fieldFormat );
405 }
406 } );
407
408 // initialize
409 updateFieldFormat( mFieldFormatComboBox->currentIndex() );
410 displayFormatChanged( mDisplayFormatComboBox->currentIndex() );
411}
412
413
414void QgsDateTimeEditConfig::updateDemoWidget()
415{
416 // Use a UTC datetime if the format string includes a Z
417 if ( mDisplayFormatEdit->text().indexOf( "Z" ) > 0 )
418 {
419 mDemoDateTimeEdit->setTimeSpec( Qt::UTC );
420 mDemoDateTimeEdit->setDateTime( QDateTime::currentDateTimeUtc() );
421 }
422 else
423 {
424 mDemoDateTimeEdit->setTimeSpec( Qt::LocalTime );
425 mDemoDateTimeEdit->setDateTime( QDateTime::currentDateTime() );
426 }
427
428 mDemoDateTimeEdit->setDisplayFormat( mDisplayFormatEdit->text() );
429 mDemoDateTimeEdit->setCalendarPopup( mCalendarPopupCheckBox->isChecked() );
430}
431
432
433void QgsDateTimeEditConfig::updateFieldFormat( int idx )
434{
435 Q_UNUSED( idx )
436 const QString format = mFieldFormatComboBox->currentData().toString();
437 const bool custom = format.isEmpty();
438 if ( !custom )
439 {
440 mFieldFormatEdit->setText( format );
441 }
442 else if ( mFieldFormatEdit->text() == QgsDateTimeFieldFormatter::QT_ISO_FORMAT )
443 {
444 mFieldFormatEdit->setText( QgsDateTimeFieldFormatter::DISPLAY_FOR_ISO_FORMAT );
445 }
446
447 mFieldFormatEdit->setEnabled( custom );
448 mFieldHelpToolButton->setVisible( custom );
449 if ( mFieldHelpToolButton->isHidden() && mDisplayHelpToolButton->isHidden() )
450 {
451 mHelpScrollArea->setVisible( false );
452 }
453}
454
455
456void QgsDateTimeEditConfig::updateDisplayFormat( const QString &fieldFormat )
457{
458 if ( mDisplayFormatComboBox->currentIndex() == 0 )
459 {
460 // i.e. display format is default
461 if ( mFieldFormatComboBox->currentData() == QgsDateTimeFieldFormatter::QT_ISO_FORMAT )
462 {
463 mDisplayFormatEdit->setText( QgsDateTimeFieldFormatter::DISPLAY_FOR_ISO_FORMAT );
464 }
465 else if ( fieldFormat == QgsDateTimeFieldFormatter::DATE_FORMAT )
466 {
467 mDisplayFormatEdit->setText( QgsDateTimeFieldFormatter::DATE_DISPLAY_FORMAT );
468 }
469 else if ( fieldFormat == QgsDateTimeFieldFormatter::DATETIME_FORMAT )
470 {
471 mDisplayFormatEdit->setText( QgsDateTimeFieldFormatter::DATETIME_DISPLAY_FORMAT );
472 }
473 else
474 {
475 mDisplayFormatEdit->setText( fieldFormat );
476 }
477 }
478}
479
480
481void QgsDateTimeEditConfig::displayFormatChanged( int idx )
482{
483 const bool custom = idx == 1;
484 mDisplayFormatEdit->setEnabled( custom );
485 mDisplayHelpToolButton->setVisible( custom );
486 if ( mFieldHelpToolButton->isHidden() && mDisplayHelpToolButton->isHidden() )
487 {
488 mHelpScrollArea->setVisible( false );
489 }
490 if ( !custom )
491 {
492 if ( mFieldFormatComboBox->currentData() == QgsDateTimeFieldFormatter::QT_ISO_FORMAT )
493 {
494 mDisplayFormatEdit->setText( QgsDateTimeFieldFormatter::DISPLAY_FOR_ISO_FORMAT );
495 }
496 else
497 {
498 mDisplayFormatEdit->setText( mFieldFormatEdit->text() );
499 }
500 }
501}
502
503void QgsDateTimeEditConfig::showHelp( bool buttonChecked )
504{
505 mFieldHelpToolButton->setChecked( buttonChecked );
506 mDisplayHelpToolButton->setChecked( buttonChecked );
507 mHelpScrollArea->setVisible( buttonChecked );
508}
509
510
512{
513 QVariantMap myConfig;
514
515 myConfig.insert( QStringLiteral( "field_format_overwrite" ), mFieldFormatGroupBox->isChecked() );
516 myConfig.insert( QStringLiteral( "field_iso_format" ), mFieldFormatEdit->text() == QgsDateTimeFieldFormatter::QT_ISO_FORMAT );
517 myConfig.insert( QStringLiteral( "field_format" ), mFieldFormatEdit->text() );
518 myConfig.insert( QStringLiteral( "display_format" ), mDisplayFormatEdit->text() );
519 myConfig.insert( QStringLiteral( "calendar_popup" ), mCalendarPopupCheckBox->isChecked() );
520 myConfig.insert( QStringLiteral( "allow_null" ), mAllowNullCheckBox->isChecked() );
521
522 return myConfig;
523}
524
525void QgsDateTimeEditConfig::setConfig( const QVariantMap &config )
526{
527 mFieldFormatGroupBox->setChecked( config.value( QStringLiteral( "field_format_overwrite" ), false ).toBool() );
528 const QgsField fieldDef = layer()->fields().at( field() );
529 const QString fieldFormat = config.value( QStringLiteral( "field_format" ), QgsDateTimeFieldFormatter::defaultFormat( fieldDef.type() ) ).toString();
530 setFieldFormatCombo( fieldFormat );
531
532 const QString displayFormat = config.value( QStringLiteral( "display_format" ), QgsDateTimeFieldFormatter::defaultDisplayFormat( fieldDef.type() ) ).toString();
533 mDisplayFormatEdit->setText( displayFormat );
534 if ( displayFormat == mFieldFormatEdit->text() )
535 {
536 mDisplayFormatComboBox->setCurrentIndex( 0 );
537 }
538 else
539 {
540 mDisplayFormatComboBox->setCurrentIndex( 1 );
541 }
542
543 mCalendarPopupCheckBox->setChecked( config.value( QStringLiteral( "calendar_popup" ), true ).toBool() );
544 mAllowNullCheckBox->setChecked( config.value( QStringLiteral( "allow_null" ), true ).toBool() );
545}
546
547void QgsDateTimeEditConfig::setFieldFormatCombo( const QString &fieldFormat )
548{
549 mFieldFormatEdit->setText( fieldFormat );
550
551 const int idx = mFieldFormatComboBox->findData( fieldFormat );
552 if ( idx >= 0 )
553 {
554 mFieldFormatComboBox->setCurrentIndex( idx );
555 }
556 else
557 {
558 mFieldFormatComboBox->setCurrentIndex( 4 );
559 }
560}
QVariantMap config() override
Create a configuration from the current GUI state.
void setConfig(const QVariantMap &config) override
Update the configuration widget to represent the given configuration.
QgsDateTimeEditConfig(QgsVectorLayer *vl, int fieldIdx, QWidget *parent=nullptr)
static const QString QT_ISO_FORMAT
Date time format was localized by applyLocaleChange before QGIS 3.30.
static const QString DISPLAY_FOR_ISO_FORMAT
static QString defaultDisplayFormat(QMetaType::Type type)
Gets the default display format in function of the type.
static QString defaultFormat(QMetaType::Type type)
Gets the default format in function of the type.
static QString DATETIME_DISPLAY_FORMAT
Date display format is localized by applyLocaleChange.
static const QString TIME_FORMAT
Date format was localized by applyLocaleChange before QGIS 3.30.
This class should be subclassed for every configurable editor widget type.
int field()
Returns the field for which this configuration widget applies.
QgsVectorLayer * layer()
Returns the layer for which this configuration widget applies.
void changed()
Emitted when the configuration of the widget is changed.
Encapsulate a field in an attribute table or data source.
Definition qgsfield.h:53
QMetaType::Type type
Definition qgsfield.h:60
QgsField at(int i) const
Returns the field at particular index (must be in range 0..N-1).
Represents a vector layer which manages a vector based data sets.