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