QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgsdatetimeeditconfig.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsdatetimeeditconfig.cpp
3  --------------------------------------
4  Date : 03.2014
5  Copyright : (C) 2014 Denis Rouzaud
6  Email : [email protected]
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 
16 #include "qgsdatetimeeditconfig.h"
17 #include "qgsdatetimeeditfactory.h"
18 #include "qgsvectorlayer.h"
20 
21 QgsDateTimeEditConfig::QgsDateTimeEditConfig( QgsVectorLayer *vl, int fieldIdx, QWidget *parent )
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 
396  // initialize
397  updateFieldFormat( mFieldFormatComboBox->currentIndex() );
398  displayFormatChanged( mDisplayFormatComboBox->currentIndex() );
399 }
400 
401 
402 void QgsDateTimeEditConfig::updateDemoWidget()
403 {
404  mDemoDateTimeEdit->setDisplayFormat( mDisplayFormatEdit->text() );
405  mDemoDateTimeEdit->setCalendarPopup( mCalendarPopupCheckBox->isChecked() );
406 }
407 
408 
409 void QgsDateTimeEditConfig::updateFieldFormat( int idx )
410 {
411  Q_UNUSED( idx )
412  const QString format = mFieldFormatComboBox->currentData().toString();
413  const bool custom = format.isEmpty();
414  if ( !custom )
415  {
416  mFieldFormatEdit->setText( format );
417  }
418  else if ( mFieldFormatEdit->text() == QgsDateTimeFieldFormatter::QT_ISO_FORMAT )
419  {
420  mFieldFormatEdit->setText( QgsDateTimeFieldFormatter::DISPLAY_FOR_ISO_FORMAT );
421  }
422 
423  mFieldFormatEdit->setEnabled( custom );
424  mFieldHelpToolButton->setVisible( custom );
425  if ( mFieldHelpToolButton->isHidden() && mDisplayHelpToolButton->isHidden() )
426  {
427  mHelpScrollArea->setVisible( false );
428  }
429 }
430 
431 
432 void QgsDateTimeEditConfig::updateDisplayFormat( const QString &fieldFormat )
433 {
434  if ( mDisplayFormatComboBox->currentIndex() == 0 )
435  {
436  // i.e. display format is default
437  if ( mFieldFormatComboBox->currentData() == QgsDateTimeFieldFormatter::QT_ISO_FORMAT )
438  {
439  mDisplayFormatEdit->setText( QgsDateTimeFieldFormatter::DISPLAY_FOR_ISO_FORMAT );
440  }
441  else
442  {
443  mDisplayFormatEdit->setText( fieldFormat );
444  }
445  }
446 }
447 
448 
449 void QgsDateTimeEditConfig::displayFormatChanged( int idx )
450 {
451  const bool custom = idx == 1;
452  mDisplayFormatEdit->setEnabled( custom );
453  mDisplayHelpToolButton->setVisible( custom );
454  if ( mFieldHelpToolButton->isHidden() && mDisplayHelpToolButton->isHidden() )
455  {
456  mHelpScrollArea->setVisible( false );
457  }
458  if ( !custom )
459  {
460  if ( mFieldFormatComboBox->currentData() == QgsDateTimeFieldFormatter::QT_ISO_FORMAT )
461  {
462  mDisplayFormatEdit->setText( QgsDateTimeFieldFormatter::DISPLAY_FOR_ISO_FORMAT );
463  }
464  else
465  {
466  mDisplayFormatEdit->setText( mFieldFormatEdit->text() );
467  }
468  }
469 }
470 
471 void QgsDateTimeEditConfig::showHelp( bool buttonChecked )
472 {
473  mFieldHelpToolButton->setChecked( buttonChecked );
474  mDisplayHelpToolButton->setChecked( buttonChecked );
475  mHelpScrollArea->setVisible( buttonChecked );
476 }
477 
478 
480 {
481  QVariantMap myConfig;
482 
483  myConfig.insert( QStringLiteral( "field_iso_format" ), mFieldFormatEdit->text() == QgsDateTimeFieldFormatter::QT_ISO_FORMAT );
484  myConfig.insert( QStringLiteral( "field_format" ), mFieldFormatEdit->text() );
485  myConfig.insert( QStringLiteral( "display_format" ), mDisplayFormatEdit->text() );
486  myConfig.insert( QStringLiteral( "calendar_popup" ), mCalendarPopupCheckBox->isChecked() );
487  myConfig.insert( QStringLiteral( "allow_null" ), mAllowNullCheckBox->isChecked() );
488 
489  return myConfig;
490 }
491 
492 void QgsDateTimeEditConfig::setConfig( const QVariantMap &config )
493 {
494  const QgsField fieldDef = layer()->fields().at( field() );
495  const QString fieldFormat = config.value( QStringLiteral( "field_format" ), QgsDateTimeFieldFormatter::defaultFormat( fieldDef.type() ) ).toString();
496  mFieldFormatEdit->setText( fieldFormat );
497 
498  const int idx = mFieldFormatComboBox->findData( fieldFormat );
499  if ( idx >= 0 )
500  {
501  mFieldFormatComboBox->setCurrentIndex( idx );
502  }
503  else
504  {
505  mFieldFormatComboBox->setCurrentIndex( 4 );
506  }
507 
508  const QString displayFormat = config.value( QStringLiteral( "display_format" ), QgsDateTimeFieldFormatter::defaultFormat( fieldDef.type() ) ).toString();
509  mDisplayFormatEdit->setText( displayFormat );
510  if ( displayFormat == mFieldFormatEdit->text() )
511  {
512  mDisplayFormatComboBox->setCurrentIndex( 0 );
513  }
514  else
515  {
516  mDisplayFormatComboBox->setCurrentIndex( 1 );
517  }
518 
519  mCalendarPopupCheckBox->setChecked( config.value( QStringLiteral( "calendar_popup" ), true ).toBool() );
520  mAllowNullCheckBox->setChecked( config.value( QStringLiteral( "allow_null" ), true ).toBool() );
521 }
QgsEditorConfigWidget
This class should be subclassed for every configurable editor widget type.
Definition: qgseditorconfigwidget.h:38
QgsDateTimeFieldFormatter::DATETIME_FORMAT
static QString DATETIME_FORMAT
Definition: qgsdatetimefieldformatter.h:50
field
const QgsField & field
Definition: qgsfield.h:463
qgsdatetimeeditfactory.h
QgsDateTimeEditConfig::setConfig
void setConfig(const QVariantMap &config) override
Update the configuration widget to represent the given configuration.
Definition: qgsdatetimeeditconfig.cpp:492
qgsdatetimefieldformatter.h
qgsvectorlayer.h
QgsDateTimeFieldFormatter::defaultFormat
static QString defaultFormat(QVariant::Type type)
Gets the default format in function of the type.
Definition: qgsdatetimefieldformatter.cpp:106
QgsDateTimeEditConfig::config
QVariantMap config() override
Create a configuration from the current GUI state.
Definition: qgsdatetimeeditconfig.cpp:479
QgsDateTimeEditConfig::QgsDateTimeEditConfig
QgsDateTimeEditConfig(QgsVectorLayer *vl, int fieldIdx, QWidget *parent=nullptr)
Definition: qgsdatetimeeditconfig.cpp:21
QgsDateTimeFieldFormatter::DISPLAY_FOR_ISO_FORMAT
static const QString DISPLAY_FOR_ISO_FORMAT
Definition: qgsdatetimefieldformatter.h:52
QgsDateTimeFieldFormatter::DATE_FORMAT
static QString DATE_FORMAT
Definition: qgsdatetimefieldformatter.h:48
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
QgsDateTimeFieldFormatter::QT_ISO_FORMAT
static const QString QT_ISO_FORMAT
Definition: qgsdatetimefieldformatter.h:51
QgsDateTimeFieldFormatter::TIME_FORMAT
static const QString TIME_FORMAT
Definition: qgsdatetimefieldformatter.h:49
QgsEditorConfigWidget::changed
void changed()
Emitted when the configuration of the widget is changed.
qgsdatetimeeditconfig.h
QgsField::type
QVariant::Type type
Definition: qgsfield.h:58
QgsField
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:50