Skip to content

Commit

Permalink
Custom true/false literals: expose to dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso authored and nyalldawson committed Nov 29, 2021
1 parent a94fc56 commit b37103d
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 26 deletions.
28 changes: 28 additions & 0 deletions src/providers/delimitedtext/qgsdelimitedtextsourceselect.cpp
Expand Up @@ -64,6 +64,7 @@ QgsDelimitedTextSourceSelect::QgsDelimitedTextSourceSelect( QWidget *parent, Qt:
cmbEncoding->setCurrentIndex( cmbEncoding->findText( QStringLiteral( "UTF-8" ) ) );

loadSettings();
mBooleanFalse->setEnabled( ! mBooleanTrue->text().isEmpty() );
updateFieldsAndEnable();

connect( txtLayerName, &QLineEdit::textChanged, this, &QgsDelimitedTextSourceSelect::enableAccept );
Expand Down Expand Up @@ -94,6 +95,17 @@ QgsDelimitedTextSourceSelect::QgsDelimitedTextSourceSelect( QWidget *parent, Qt:

connect( crsGeometry, &QgsProjectionSelectionWidget::crsChanged, this, &QgsDelimitedTextSourceSelect::updateFieldsAndEnable );

connect( mBooleanTrue, &QLineEdit::textChanged, mBooleanFalse, [ = ]
{
mBooleanFalse->setEnabled( ! mBooleanTrue->text().isEmpty() );
updateFieldsAndEnable();
} );

connect( mBooleanFalse, &QLineEdit::textChanged, mBooleanFalse, [ = ]
{
updateFieldsAndEnable();
} );

const QgsSettings settings;
mFileWidget->setDialogTitle( tr( "Choose a Delimited Text File to Open" ) );
mFileWidget->setFilter( tr( "Text files" ) + QStringLiteral( " (*.txt *.csv *.dat *.wkt);;" ) + tr( "All files" ) + QStringLiteral( " (* *.*)" ) );
Expand Down Expand Up @@ -238,6 +250,8 @@ void QgsDelimitedTextSourceSelect::loadSettings( const QString &subkey, bool loa
cbxSubsetIndex->setChecked( settings.value( key + "/subsetIndex", "false" ) == "true" );
cbxSpatialIndex->setChecked( settings.value( key + "/spatialIndex", "false" ) == "true" );
cbxWatchFile->setChecked( settings.value( key + "/watchFile", "false" ) == "true" );
mBooleanFalse->setText( settings.value( key + "/booleanFalse", "" ).toString() );
mBooleanTrue->setText( settings.value( key + "/booleanTrue", "" ).toString() );

if ( loadGeomSettings )
{
Expand Down Expand Up @@ -284,6 +298,8 @@ void QgsDelimitedTextSourceSelect::saveSettings( const QString &subkey, bool sav
settings.setValue( key + "/subsetIndex", cbxSubsetIndex->isChecked() ? "true" : "false" );
settings.setValue( key + "/spatialIndex", cbxSpatialIndex->isChecked() ? "true" : "false" );
settings.setValue( key + "/watchFile", cbxWatchFile->isChecked() ? "true" : "false" );
settings.setValue( key + "/booleanFalse", mBooleanFalse->text() );
settings.setValue( key + "/booleanTrue", mBooleanTrue->text() );
if ( saveGeomSettings )
{
QString geomColumnType = QStringLiteral( "none" );
Expand Down Expand Up @@ -777,6 +793,12 @@ bool QgsDelimitedTextSourceSelect::validate()
}

}

if ( mBooleanTrue->text().isEmpty() != mBooleanFalse->text().isEmpty() )
{
message = tr( "Custom boolean values for \"true\" or \"false\" is missing." );
}

lblStatus->setText( message );
return enabled;
}
Expand Down Expand Up @@ -843,6 +865,12 @@ QString QgsDelimitedTextSourceSelect::url( bool skipOverriddenTypes )
query.addQueryItem( QStringLiteral( "xyDms" ), QStringLiteral( "yes" ) );
}

if ( ! mBooleanFalse->text().isEmpty() && ! mBooleanTrue->text().isEmpty() )
{
query.addQueryItem( QStringLiteral( "booleanFalse" ), mBooleanFalse->text() );
query.addQueryItem( QStringLiteral( "booleanTrue" ), mBooleanTrue->text() );
}

bool haveGeom = true;
if ( geomTypeXY->isChecked() )
{
Expand Down
86 changes: 60 additions & 26 deletions src/ui/qgsdelimitedtextsourceselectbase.ui
Expand Up @@ -168,7 +168,7 @@
<x>0</x>
<y>0</y>
<width>703</width>
<height>579</height>
<height>608</height>
</rect>
</property>
<property name="sizePolicy">
Expand Down Expand Up @@ -673,7 +673,7 @@
<property name="collapsed" stdset="0">
<bool>true</bool>
</property>
<layout class="QGridLayout" name="gridLayout_7">
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<property name="rightMargin">
Expand Down Expand Up @@ -731,6 +731,25 @@
</item>
</layout>
</item>
<item row="0" column="1">
<widget class="QCheckBox" name="cbxPointIsComma">
<property name="enabled">
<bool>true</bool>
</property>
<property name="toolTip">
<string>Number fields use comma for a decimal separator</string>
</property>
<property name="statusTip">
<string>Number fields use comma for a decimal separator</string>
</property>
<property name="whatsThis">
<string>Number fields use comma for a decimal separator</string>
</property>
<property name="text">
<string>Decimal separator is comma</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="cbxUseHeader">
<property name="toolTip">
Expand Down Expand Up @@ -766,22 +785,13 @@
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QCheckBox" name="cbxPointIsComma">
<property name="enabled">
<bool>true</bool>
</property>
<property name="toolTip">
<string>Number fields use comma for a decimal separator</string>
</property>
<property name="statusTip">
<string>Number fields use comma for a decimal separator</string>
</property>
<property name="whatsThis">
<string>Number fields use comma for a decimal separator</string>
</property>
<item row="2" column="0">
<widget class="QCheckBox" name="cbxDetectTypes">
<property name="text">
<string>Decimal separator is comma</string>
<string>Detect field types</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
Expand All @@ -801,15 +811,39 @@
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="cbxDetectTypes">
<property name="text">
<string>Detect field types</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
<item row="3" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
<widget class="QLabel" name="mBoolTrueLabel">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Columns filled with '0/1', 'true/false', 't/f', and 'yes/no' (case insensitive) are automatically detected as boolean fields. An additional value for &lt;span style=&quot; font-weight:600;&quot;&gt;true&lt;/span&gt; can be specified here.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Boolean &lt;span style=&quot; font-weight:600;&quot;&gt;true&lt;/span&gt; custom value&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="mBooleanTrue"/>
</item>
</layout>
</item>
<item row="3" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_9">
<item>
<widget class="QLabel" name="mBooleanFalseLabel">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Columns filled with '0/1', 'true/false', 't/f', and 'yes/no' (case insensitive) are automatically detected as boolean fields. An additional value for &lt;span style=&quot; font-weight:600;&quot;&gt;false&lt;/span&gt; can be specified here.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Boolean &lt;span style=&quot; font-weight:600;&quot;&gt;false&lt;/span&gt; custom value&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="mBooleanFalse"/>
</item>
</layout>
</item>
</layout>
</widget>
Expand Down

0 comments on commit b37103d

Please sign in to comment.