Skip to content

Commit

Permalink
Merge pull request #6400 from ccrook/delim_text_ui_crs
Browse files Browse the repository at this point in the history
Delim text ui crs
  • Loading branch information
ccrook committed Feb 21, 2018
2 parents bb08b64 + 6759993 commit cb17e22
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 20 deletions.
33 changes: 33 additions & 0 deletions src/providers/delimitedtext/qgsdelimitedtextsourceselect.cpp
Expand Up @@ -92,6 +92,8 @@ QgsDelimitedTextSourceSelect::QgsDelimitedTextSourceSelect( QWidget *parent, Qt:
connect( cbxPointIsComma, &QAbstractButton::toggled, this, &QgsDelimitedTextSourceSelect::updateFieldsAndEnable );
connect( cbxXyDms, &QAbstractButton::toggled, this, &QgsDelimitedTextSourceSelect::updateFieldsAndEnable );

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

mFileWidget->setDialogTitle( tr( "Choose a Delimited Text File to Open" ) );
mFileWidget->setFilter( tr( "Text files" ) + " (*.txt *.csv *.dat *.wkt);;" + tr( "All files" ) + " (* *.*)" );
mFileWidget->setSelectedFilter( settings.value( mPluginKey + "/file_filter", "" ).toString() );
Expand Down Expand Up @@ -152,6 +154,7 @@ void QgsDelimitedTextSourceSelect::addButtonClicked()
url.addQueryItem( QStringLiteral( "xyDms" ), QStringLiteral( "yes" ) );
}

bool haveGeom = true;
if ( geomTypeXY->isChecked() )
{
if ( !cmbXField->currentText().isEmpty() && !cmbYField->currentText().isEmpty() )
Expand All @@ -176,8 +179,18 @@ void QgsDelimitedTextSourceSelect::addButtonClicked()
}
else
{
haveGeom = false;
url.addQueryItem( QStringLiteral( "geomType" ), QStringLiteral( "none" ) );
}
if ( haveGeom )
{
QgsCoordinateReferenceSystem crs = crsGeometry->crs();
if ( crs.isValid() )
{
url.addQueryItem( QStringLiteral( "crs" ), crs.authid() );
}

}

if ( ! geomTypeNone->isChecked() ) url.addQueryItem( QStringLiteral( "spatialIndex" ), cbxSpatialIndex->isChecked() ? "yes" : "no" );
url.addQueryItem( QStringLiteral( "subsetIndex" ), cbxSubsetIndex->isChecked() ? "yes" : "no" );
Expand All @@ -190,6 +203,12 @@ void QgsDelimitedTextSourceSelect::addButtonClicked()

// add the layer to the map
emit addVectorLayer( QString::fromLatin1( url.toEncoded() ), txtLayerName->text() );

// clear the file and layer name show something has happened, ready for another file

mFileWidget->setFilePath( QString() );
txtLayerName->setText( QString() );

if ( widgetMode() == QgsProviderRegistry::WidgetMode::None )
{
accept();
Expand Down Expand Up @@ -280,6 +299,12 @@ void QgsDelimitedTextSourceSelect::loadSettings( const QString &subkey, bool loa
else geomTypeNone->setChecked( true );
cbxXyDms->setChecked( settings.value( key + "/xyDms", "false" ) == "true" );
swGeomType->setCurrentIndex( bgGeomType->checkedId() );
QString authid = settings.value( key + "/crs", "" ).toString();
QgsCoordinateReferenceSystem crs = QgsCoordinateReferenceSystem::fromOgcWmsCrs( authid );
if ( crs.isValid() )
{
crsGeometry->setCrs( crs );
}
}

}
Expand Down Expand Up @@ -317,6 +342,10 @@ void QgsDelimitedTextSourceSelect::saveSettings( const QString &subkey, bool sav
if ( geomTypeWKT->isChecked() ) geomColumnType = QStringLiteral( "wkt" );
settings.setValue( key + "/geomColumnType", geomColumnType );
settings.setValue( key + "/xyDms", cbxXyDms->isChecked() ? "true" : "false" );
if ( crsGeometry->crs().isValid() )
{
settings.setValue( key + "/crs", crsGeometry->crs().authid() );
}
}

}
Expand Down Expand Up @@ -703,6 +732,10 @@ bool QgsDelimitedTextSourceSelect::validate()
{
message = tr( "The WKT field name must be selected" );
}
else if ( ! geomTypeNone->isChecked() && ! crsGeometry->crs().isValid() )
{
message = tr( "The CRS must be selected" );
}
else
{
enabled = true;
Expand Down
94 changes: 74 additions & 20 deletions src/ui/qgsdelimitedtextsourceselectbase.ui
Expand Up @@ -79,7 +79,7 @@
</widget>
</item>
<item>
<widget class="QgsFileWidget" name="mFileWidget" native="true"/>
<widget class="QgsFileWidget" name="mFileWidget"/>
</item>
</layout>
</item>
Expand Down Expand Up @@ -117,19 +117,6 @@
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="lblEncoding">
<property name="text">
Expand Down Expand Up @@ -180,8 +167,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>704</width>
<height>694</height>
<width>714</width>
<height>514</height>
</rect>
</property>
<property name="sizePolicy">
Expand All @@ -202,7 +189,7 @@
<property name="title">
<string>File format</string>
</property>
<property name="collapsed" stdset="0">
<property name="collapsed">
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout_8">
Expand Down Expand Up @@ -384,6 +371,9 @@
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>txtDelimiterOther</cstring>
</property>
</widget>
</item>
<item>
Expand Down Expand Up @@ -507,6 +497,9 @@
<property name="alignment">
<set>Qt::AlignJustify|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>txtQuoteChars</cstring>
</property>
</widget>
</item>
<item>
Expand Down Expand Up @@ -561,6 +554,9 @@
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>txtEscapeChars</cstring>
</property>
</widget>
</item>
<item>
Expand Down Expand Up @@ -684,7 +680,7 @@
<property name="title">
<string>Record and fields options</string>
</property>
<property name="collapsed" stdset="0">
<property name="collapsed">
<bool>true</bool>
</property>
<layout class="QGridLayout" name="gridLayout_7">
Expand All @@ -704,6 +700,9 @@
<property name="text">
<string>Number of header lines to discard</string>
</property>
<property name="buddy">
<cstring>rowCounter</cstring>
</property>
</widget>
</item>
<item>
Expand Down Expand Up @@ -826,7 +825,7 @@
<property name="title">
<string>Geometry definition</string>
</property>
<property name="collapsed" stdset="0">
<property name="collapsed">
<bool>true</bool>
</property>
<layout class="QGridLayout" name="gridLayout">
Expand Down Expand Up @@ -1004,6 +1003,9 @@
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>cmbXField</cstring>
</property>
</widget>
</item>
<item row="2" column="0">
Expand All @@ -1020,6 +1022,9 @@
<property name="text">
<string>&lt;p align=&quot;left&quot;&gt;Y field&lt;/p&gt;</string>
</property>
<property name="buddy">
<cstring>cmbYField</cstring>
</property>
</widget>
</item>
</layout>
Expand Down Expand Up @@ -1127,6 +1132,19 @@
<widget class="QWidget" name="swpGeomNone"/>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="textLabelCrs">
<property name="text">
<string>Geometry CRS</string>
</property>
<property name="buddy">
<cstring>crsGeometry</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QgsProjectionSelectionWidget" name="crsGeometry"/>
</item>
</layout>
</widget>
</item>
Expand All @@ -1141,7 +1159,7 @@
<property name="title">
<string>Layer settings</string>
</property>
<property name="collapsed" stdset="0">
<property name="collapsed">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_14">
Expand Down Expand Up @@ -1289,14 +1307,50 @@
<extends>QWidget</extends>
<header>qgsfilewidget.h</header>
</customwidget>
<customwidget>
<class>QgsProjectionSelectionWidget</class>
<extends>QWidget</extends>
<header>qgsprojectionselectionwidget.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>txtLayerName</tabstop>
<tabstop>cmbEncoding</tabstop>
<tabstop>scrollArea</tabstop>
<tabstop>fileFormatGroupBox</tabstop>
<tabstop>delimiterCSV</tabstop>
<tabstop>delimiterRegexp</tabstop>
<tabstop>delimiterChars</tabstop>
<tabstop>cbxDelimTab</tabstop>
<tabstop>cbxDelimColon</tabstop>
<tabstop>cbxDelimSpace</tabstop>
<tabstop>cbxDelimSemicolon</tabstop>
<tabstop>cbxDelimComma</tabstop>
<tabstop>txtDelimiterOther</tabstop>
<tabstop>txtQuoteChars</tabstop>
<tabstop>txtEscapeChars</tabstop>
<tabstop>recordOptionsGroupBox</tabstop>
<tabstop>rowCounter</tabstop>
<tabstop>cbxUseHeader</tabstop>
<tabstop>cbxPointIsComma</tabstop>
<tabstop>cbxTrimFields</tabstop>
<tabstop>cbxSkipEmptyFields</tabstop>
<tabstop>geometryDefinitionGroupBox</tabstop>
<tabstop>geomTypeXY</tabstop>
<tabstop>geomTypeWKT</tabstop>
<tabstop>geomTypeNone</tabstop>
<tabstop>cmbXField</tabstop>
<tabstop>cmbYField</tabstop>
<tabstop>cbxXyDms</tabstop>
<tabstop>crsGeometry</tabstop>
<tabstop>layeSettingsGroupBox</tabstop>
<tabstop>cbxSpatialIndex</tabstop>
<tabstop>cbxSubsetIndex</tabstop>
<tabstop>cbxWatchFile</tabstop>
<tabstop>tblSample</tabstop>
<tabstop>cmbWktField</tabstop>
<tabstop>cmbGeometryType</tabstop>
<tabstop>txtDelimiterRegexp</tabstop>
</tabstops>
<resources/>
<connections>
Expand Down

0 comments on commit cb17e22

Please sign in to comment.