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