Skip to content

Commit c2813f8

Browse files
authoredMar 27, 2023
Merge pull request #52063 from signedav/fix_date_search
Datetime Widget Config: "Protect" field format change possiblities
2 parents 9b860f6 + 5a2138d commit c2813f8

File tree

3 files changed

+123
-93
lines changed

3 files changed

+123
-93
lines changed
 

‎src/gui/editorwidgets/qgsdatetimeeditconfig.cpp

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,16 @@ QgsDateTimeEditConfig::QgsDateTimeEditConfig( QgsVectorLayer *vl, int fieldIdx,
392392
connect( mDisplayFormatEdit, &QLineEdit::textChanged, this, &QgsEditorConfigWidget::changed );
393393
connect( mCalendarPopupCheckBox, &QAbstractButton::toggled, this, &QgsEditorConfigWidget::changed );
394394
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+
} );
395405

396406
// initialize
397407
updateFieldFormat( mFieldFormatComboBox->currentIndex() );
@@ -488,6 +498,7 @@ QVariantMap QgsDateTimeEditConfig::config()
488498
{
489499
QVariantMap myConfig;
490500

501+
myConfig.insert( QStringLiteral( "field_format_overwrite" ), mFieldFormatGroupBox->isChecked() );
491502
myConfig.insert( QStringLiteral( "field_iso_format" ), mFieldFormatEdit->text() == QgsDateTimeFieldFormatter::QT_ISO_FORMAT );
492503
myConfig.insert( QStringLiteral( "field_format" ), mFieldFormatEdit->text() );
493504
myConfig.insert( QStringLiteral( "display_format" ), mDisplayFormatEdit->text() );
@@ -499,19 +510,10 @@ QVariantMap QgsDateTimeEditConfig::config()
499510

500511
void QgsDateTimeEditConfig::setConfig( const QVariantMap &config )
501512
{
513+
mFieldFormatGroupBox->setChecked( config.value( QStringLiteral( "field_format_overwrite" ), false ).toBool() );
502514
const QgsField fieldDef = layer()->fields().at( field() );
503515
const QString fieldFormat = config.value( QStringLiteral( "field_format" ), QgsDateTimeFieldFormatter::defaultFormat( fieldDef.type() ) ).toString();
504-
mFieldFormatEdit->setText( fieldFormat );
505-
506-
const int idx = mFieldFormatComboBox->findData( fieldFormat );
507-
if ( idx >= 0 )
508-
{
509-
mFieldFormatComboBox->setCurrentIndex( idx );
510-
}
511-
else
512-
{
513-
mFieldFormatComboBox->setCurrentIndex( 4 );
514-
}
516+
setFieldFormatCombo( fieldFormat );
515517

516518
const QString displayFormat = config.value( QStringLiteral( "display_format" ), QgsDateTimeFieldFormatter::defaultDisplayFormat( fieldDef.type() ) ).toString();
517519
mDisplayFormatEdit->setText( displayFormat );
@@ -527,3 +529,18 @@ void QgsDateTimeEditConfig::setConfig( const QVariantMap &config )
527529
mCalendarPopupCheckBox->setChecked( config.value( QStringLiteral( "calendar_popup" ), true ).toBool() );
528530
mAllowNullCheckBox->setChecked( config.value( QStringLiteral( "allow_null" ), true ).toBool() );
529531
}
532+
533+
void QgsDateTimeEditConfig::setFieldFormatCombo( const QString &fieldFormat )
534+
{
535+
mFieldFormatEdit->setText( fieldFormat );
536+
537+
const int idx = mFieldFormatComboBox->findData( fieldFormat );
538+
if ( idx >= 0 )
539+
{
540+
mFieldFormatComboBox->setCurrentIndex( idx );
541+
}
542+
else
543+
{
544+
mFieldFormatComboBox->setCurrentIndex( 4 );
545+
}
546+
}

‎src/gui/editorwidgets/qgsdatetimeeditconfig.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ class GUI_EXPORT QgsDateTimeEditConfig : public QgsEditorConfigWidget, private U
4242
void updateDisplayFormat( const QString &fieldFormat );
4343
void displayFormatChanged( int idx );
4444
void showHelp( bool buttonChecked );
45+
46+
private:
47+
void setFieldFormatCombo( const QString &fieldFormat );
4548
};
4649

4750
#endif // QGSDATETIMEEDITCONFIG_H

‎src/ui/editorwidgets/qgsdatetimeeditconfig.ui

Lines changed: 92 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,14 @@
1414
<string notr="true">Form</string>
1515
</property>
1616
<layout class="QGridLayout" name="gridLayout">
17-
<item row="4" column="0">
17+
<item row="9" column="0">
18+
<widget class="Line" name="line">
19+
<property name="orientation">
20+
<enum>Qt::Horizontal</enum>
21+
</property>
22+
</widget>
23+
</item>
24+
<item row="5" column="0">
1825
<widget class="QgsScrollArea" name="mHelpScrollArea">
1926
<property name="sizePolicy">
2027
<sizepolicy hsizetype="Expanding" vsizetype="MinimumExpanding">
@@ -30,8 +37,8 @@
3037
<rect>
3138
<x>0</x>
3239
<y>0</y>
33-
<width>478</width>
34-
<height>971</height>
40+
<width>484</width>
41+
<height>68</height>
3542
</rect>
3643
</property>
3744
<layout class="QGridLayout" name="gridLayout_5">
@@ -52,86 +59,10 @@
5259
</widget>
5360
</widget>
5461
</item>
55-
<item row="10" column="0">
56-
<spacer name="verticalSpacer">
57-
<property name="orientation">
58-
<enum>Qt::Vertical</enum>
59-
</property>
60-
<property name="sizeHint" stdset="0">
61-
<size>
62-
<width>20</width>
63-
<height>40</height>
64-
</size>
65-
</property>
66-
</spacer>
67-
</item>
68-
<item row="8" column="0">
69-
<widget class="Line" name="line">
70-
<property name="orientation">
71-
<enum>Qt::Horizontal</enum>
72-
</property>
73-
</widget>
74-
</item>
75-
<item row="0" column="0">
76-
<widget class="QGroupBox" name="groupBox_2">
77-
<property name="title">
78-
<string>Field Format</string>
79-
</property>
80-
<layout class="QGridLayout" name="gridLayout_3">
81-
<item row="0" column="0">
82-
<widget class="QComboBox" name="mFieldFormatComboBox">
83-
<property name="minimumSize">
84-
<size>
85-
<width>120</width>
86-
<height>0</height>
87-
</size>
88-
</property>
89-
</widget>
90-
</item>
91-
<item row="0" column="1">
92-
<widget class="QLineEdit" name="mFieldFormatEdit">
93-
<property name="enabled">
94-
<bool>true</bool>
95-
</property>
96-
</widget>
97-
</item>
98-
<item row="0" column="3">
99-
<spacer name="horizontalSpacer">
100-
<property name="orientation">
101-
<enum>Qt::Horizontal</enum>
102-
</property>
103-
<property name="sizeHint" stdset="0">
104-
<size>
105-
<width>40</width>
106-
<height>20</height>
107-
</size>
108-
</property>
109-
</spacer>
110-
</item>
111-
<item row="0" column="2">
112-
<widget class="QToolButton" name="mFieldHelpToolButton">
113-
<property name="text">
114-
<string>…</string>
115-
</property>
116-
<property name="icon">
117-
<iconset resource="../../../images/images.qrc">
118-
<normaloff>:/images/themes/default/mActionHelpContents.svg</normaloff>:/images/themes/default/mActionHelpContents.svg</iconset>
119-
</property>
120-
<property name="checkable">
121-
<bool>true</bool>
122-
</property>
123-
<property name="checked">
124-
<bool>false</bool>
125-
</property>
126-
</widget>
127-
</item>
128-
</layout>
129-
</widget>
130-
</item>
13162
<item row="2" column="0">
132-
<widget class="QGroupBox" name="groupBox">
63+
<widget class="QGroupBox" name="mDisplayFormatGroupBox">
13364
<property name="title">
134-
<string>Widget Display</string>
65+
<string>Display Format</string>
13566
</property>
13667
<layout class="QGridLayout" name="gridLayout_2">
13768
<item row="0" column="3">
@@ -214,7 +145,85 @@
214145
</layout>
215146
</widget>
216147
</item>
217-
<item row="9" column="0">
148+
<item row="11" column="0">
149+
<spacer name="verticalSpacer">
150+
<property name="orientation">
151+
<enum>Qt::Vertical</enum>
152+
</property>
153+
<property name="sizeHint" stdset="0">
154+
<size>
155+
<width>20</width>
156+
<height>40</height>
157+
</size>
158+
</property>
159+
</spacer>
160+
</item>
161+
<item row="4" column="0">
162+
<widget class="QGroupBox" name="mFieldFormatGroupBox">
163+
<property name="toolTip">
164+
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;The field format allows customizing the format in which the date will be stored in the datasource. &lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;Overwriting the field format is&lt;span style=&quot; font-weight:600; font-style:italic;&quot;/&gt;usually&lt;span style=&quot; font-weight:600; font-style:italic;&quot;/&gt;intended for fields that are &lt;span style=&quot; font-weight:600; font-style:italic;&quot;&gt;not&lt;/span&gt; of a date type.&lt;/p&gt;&lt;p&gt;For the display format of the date widget, use the section above.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
165+
</property>
166+
<property name="title">
167+
<string>Overwrite Field Format</string>
168+
</property>
169+
<property name="checkable">
170+
<bool>true</bool>
171+
</property>
172+
<property name="checked">
173+
<bool>false</bool>
174+
</property>
175+
<layout class="QGridLayout" name="gridLayout_3">
176+
<item row="0" column="2">
177+
<widget class="QToolButton" name="mFieldHelpToolButton">
178+
<property name="text">
179+
<string>…</string>
180+
</property>
181+
<property name="icon">
182+
<iconset resource="../../../images/images.qrc">
183+
<normaloff>:/images/themes/default/mActionHelpContents.svg</normaloff>:/images/themes/default/mActionHelpContents.svg</iconset>
184+
</property>
185+
<property name="checkable">
186+
<bool>true</bool>
187+
</property>
188+
<property name="checked">
189+
<bool>false</bool>
190+
</property>
191+
</widget>
192+
</item>
193+
<item row="0" column="3">
194+
<spacer name="horizontalSpacer">
195+
<property name="orientation">
196+
<enum>Qt::Horizontal</enum>
197+
</property>
198+
<property name="sizeHint" stdset="0">
199+
<size>
200+
<width>40</width>
201+
<height>20</height>
202+
</size>
203+
</property>
204+
</spacer>
205+
</item>
206+
<item row="0" column="1">
207+
<widget class="QLineEdit" name="mFieldFormatEdit">
208+
<property name="enabled">
209+
<bool>false</bool>
210+
</property>
211+
</widget>
212+
</item>
213+
<item row="0" column="0">
214+
<widget class="QComboBox" name="mFieldFormatComboBox">
215+
<property name="minimumSize">
216+
<size>
217+
<width>120</width>
218+
<height>0</height>
219+
</size>
220+
</property>
221+
</widget>
222+
</item>
223+
</layout>
224+
</widget>
225+
</item>
226+
<item row="3" column="0">
218227
<layout class="QHBoxLayout" name="horizontalLayout_3">
219228
<item>
220229
<widget class="QLabel" name="label">
@@ -258,6 +267,7 @@
258267
</tabstops>
259268
<resources>
260269
<include location="../../../images/images.qrc"/>
270+
<include location="../../../images/images.qrc"/>
261271
</resources>
262272
<connections/>
263273
</ui>

0 commit comments

Comments
 (0)
Please sign in to comment.