Skip to content

Commit cb17e22

Browse files
authoredFeb 21, 2018
Merge pull request #6400 from ccrook/delim_text_ui_crs
Delim text ui crs
2 parents bb08b64 + 6759993 commit cb17e22

File tree

2 files changed

+107
-20
lines changed

2 files changed

+107
-20
lines changed
 

‎src/providers/delimitedtext/qgsdelimitedtextsourceselect.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ QgsDelimitedTextSourceSelect::QgsDelimitedTextSourceSelect( QWidget *parent, Qt:
9292
connect( cbxPointIsComma, &QAbstractButton::toggled, this, &QgsDelimitedTextSourceSelect::updateFieldsAndEnable );
9393
connect( cbxXyDms, &QAbstractButton::toggled, this, &QgsDelimitedTextSourceSelect::updateFieldsAndEnable );
9494

95+
connect( crsGeometry, &QgsProjectionSelectionWidget::crsChanged, this, &QgsDelimitedTextSourceSelect::updateFieldsAndEnable );
96+
9597
mFileWidget->setDialogTitle( tr( "Choose a Delimited Text File to Open" ) );
9698
mFileWidget->setFilter( tr( "Text files" ) + " (*.txt *.csv *.dat *.wkt);;" + tr( "All files" ) + " (* *.*)" );
9799
mFileWidget->setSelectedFilter( settings.value( mPluginKey + "/file_filter", "" ).toString() );
@@ -152,6 +154,7 @@ void QgsDelimitedTextSourceSelect::addButtonClicked()
152154
url.addQueryItem( QStringLiteral( "xyDms" ), QStringLiteral( "yes" ) );
153155
}
154156

157+
bool haveGeom = true;
155158
if ( geomTypeXY->isChecked() )
156159
{
157160
if ( !cmbXField->currentText().isEmpty() && !cmbYField->currentText().isEmpty() )
@@ -176,8 +179,18 @@ void QgsDelimitedTextSourceSelect::addButtonClicked()
176179
}
177180
else
178181
{
182+
haveGeom = false;
179183
url.addQueryItem( QStringLiteral( "geomType" ), QStringLiteral( "none" ) );
180184
}
185+
if ( haveGeom )
186+
{
187+
QgsCoordinateReferenceSystem crs = crsGeometry->crs();
188+
if ( crs.isValid() )
189+
{
190+
url.addQueryItem( QStringLiteral( "crs" ), crs.authid() );
191+
}
192+
193+
}
181194

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

191204
// add the layer to the map
192205
emit addVectorLayer( QString::fromLatin1( url.toEncoded() ), txtLayerName->text() );
206+
207+
// clear the file and layer name show something has happened, ready for another file
208+
209+
mFileWidget->setFilePath( QString() );
210+
txtLayerName->setText( QString() );
211+
193212
if ( widgetMode() == QgsProviderRegistry::WidgetMode::None )
194213
{
195214
accept();
@@ -280,6 +299,12 @@ void QgsDelimitedTextSourceSelect::loadSettings( const QString &subkey, bool loa
280299
else geomTypeNone->setChecked( true );
281300
cbxXyDms->setChecked( settings.value( key + "/xyDms", "false" ) == "true" );
282301
swGeomType->setCurrentIndex( bgGeomType->checkedId() );
302+
QString authid = settings.value( key + "/crs", "" ).toString();
303+
QgsCoordinateReferenceSystem crs = QgsCoordinateReferenceSystem::fromOgcWmsCrs( authid );
304+
if ( crs.isValid() )
305+
{
306+
crsGeometry->setCrs( crs );
307+
}
283308
}
284309

285310
}
@@ -317,6 +342,10 @@ void QgsDelimitedTextSourceSelect::saveSettings( const QString &subkey, bool sav
317342
if ( geomTypeWKT->isChecked() ) geomColumnType = QStringLiteral( "wkt" );
318343
settings.setValue( key + "/geomColumnType", geomColumnType );
319344
settings.setValue( key + "/xyDms", cbxXyDms->isChecked() ? "true" : "false" );
345+
if ( crsGeometry->crs().isValid() )
346+
{
347+
settings.setValue( key + "/crs", crsGeometry->crs().authid() );
348+
}
320349
}
321350

322351
}
@@ -703,6 +732,10 @@ bool QgsDelimitedTextSourceSelect::validate()
703732
{
704733
message = tr( "The WKT field name must be selected" );
705734
}
735+
else if ( ! geomTypeNone->isChecked() && ! crsGeometry->crs().isValid() )
736+
{
737+
message = tr( "The CRS must be selected" );
738+
}
706739
else
707740
{
708741
enabled = true;

‎src/ui/qgsdelimitedtextsourceselectbase.ui

Lines changed: 74 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
</widget>
8080
</item>
8181
<item>
82-
<widget class="QgsFileWidget" name="mFileWidget" native="true"/>
82+
<widget class="QgsFileWidget" name="mFileWidget"/>
8383
</item>
8484
</layout>
8585
</item>
@@ -117,19 +117,6 @@
117117
</property>
118118
</widget>
119119
</item>
120-
<item>
121-
<spacer name="horizontalSpacer_3">
122-
<property name="orientation">
123-
<enum>Qt::Horizontal</enum>
124-
</property>
125-
<property name="sizeHint" stdset="0">
126-
<size>
127-
<width>40</width>
128-
<height>20</height>
129-
</size>
130-
</property>
131-
</spacer>
132-
</item>
133120
<item>
134121
<widget class="QLabel" name="lblEncoding">
135122
<property name="text">
@@ -180,8 +167,8 @@
180167
<rect>
181168
<x>0</x>
182169
<y>0</y>
183-
<width>704</width>
184-
<height>694</height>
170+
<width>714</width>
171+
<height>514</height>
185172
</rect>
186173
</property>
187174
<property name="sizePolicy">
@@ -202,7 +189,7 @@
202189
<property name="title">
203190
<string>File format</string>
204191
</property>
205-
<property name="collapsed" stdset="0">
192+
<property name="collapsed">
206193
<bool>false</bool>
207194
</property>
208195
<layout class="QGridLayout" name="gridLayout_8">
@@ -384,6 +371,9 @@
384371
<property name="alignment">
385372
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
386373
</property>
374+
<property name="buddy">
375+
<cstring>txtDelimiterOther</cstring>
376+
</property>
387377
</widget>
388378
</item>
389379
<item>
@@ -507,6 +497,9 @@
507497
<property name="alignment">
508498
<set>Qt::AlignJustify|Qt::AlignVCenter</set>
509499
</property>
500+
<property name="buddy">
501+
<cstring>txtQuoteChars</cstring>
502+
</property>
510503
</widget>
511504
</item>
512505
<item>
@@ -561,6 +554,9 @@
561554
<property name="alignment">
562555
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
563556
</property>
557+
<property name="buddy">
558+
<cstring>txtEscapeChars</cstring>
559+
</property>
564560
</widget>
565561
</item>
566562
<item>
@@ -684,7 +680,7 @@
684680
<property name="title">
685681
<string>Record and fields options</string>
686682
</property>
687-
<property name="collapsed" stdset="0">
683+
<property name="collapsed">
688684
<bool>true</bool>
689685
</property>
690686
<layout class="QGridLayout" name="gridLayout_7">
@@ -704,6 +700,9 @@
704700
<property name="text">
705701
<string>Number of header lines to discard</string>
706702
</property>
703+
<property name="buddy">
704+
<cstring>rowCounter</cstring>
705+
</property>
707706
</widget>
708707
</item>
709708
<item>
@@ -826,7 +825,7 @@
826825
<property name="title">
827826
<string>Geometry definition</string>
828827
</property>
829-
<property name="collapsed" stdset="0">
828+
<property name="collapsed">
830829
<bool>true</bool>
831830
</property>
832831
<layout class="QGridLayout" name="gridLayout">
@@ -1004,6 +1003,9 @@
10041003
<property name="alignment">
10051004
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
10061005
</property>
1006+
<property name="buddy">
1007+
<cstring>cmbXField</cstring>
1008+
</property>
10071009
</widget>
10081010
</item>
10091011
<item row="2" column="0">
@@ -1020,6 +1022,9 @@
10201022
<property name="text">
10211023
<string>&lt;p align=&quot;left&quot;&gt;Y field&lt;/p&gt;</string>
10221024
</property>
1025+
<property name="buddy">
1026+
<cstring>cmbYField</cstring>
1027+
</property>
10231028
</widget>
10241029
</item>
10251030
</layout>
@@ -1127,6 +1132,19 @@
11271132
<widget class="QWidget" name="swpGeomNone"/>
11281133
</widget>
11291134
</item>
1135+
<item row="1" column="0">
1136+
<widget class="QLabel" name="textLabelCrs">
1137+
<property name="text">
1138+
<string>Geometry CRS</string>
1139+
</property>
1140+
<property name="buddy">
1141+
<cstring>crsGeometry</cstring>
1142+
</property>
1143+
</widget>
1144+
</item>
1145+
<item row="1" column="1">
1146+
<widget class="QgsProjectionSelectionWidget" name="crsGeometry"/>
1147+
</item>
11301148
</layout>
11311149
</widget>
11321150
</item>
@@ -1141,7 +1159,7 @@
11411159
<property name="title">
11421160
<string>Layer settings</string>
11431161
</property>
1144-
<property name="collapsed" stdset="0">
1162+
<property name="collapsed">
11451163
<bool>true</bool>
11461164
</property>
11471165
<layout class="QVBoxLayout" name="verticalLayout_14">
@@ -1289,14 +1307,50 @@
12891307
<extends>QWidget</extends>
12901308
<header>qgsfilewidget.h</header>
12911309
</customwidget>
1310+
<customwidget>
1311+
<class>QgsProjectionSelectionWidget</class>
1312+
<extends>QWidget</extends>
1313+
<header>qgsprojectionselectionwidget.h</header>
1314+
</customwidget>
12921315
</customwidgets>
12931316
<tabstops>
12941317
<tabstop>txtLayerName</tabstop>
12951318
<tabstop>cmbEncoding</tabstop>
1319+
<tabstop>scrollArea</tabstop>
1320+
<tabstop>fileFormatGroupBox</tabstop>
1321+
<tabstop>delimiterCSV</tabstop>
1322+
<tabstop>delimiterRegexp</tabstop>
1323+
<tabstop>delimiterChars</tabstop>
1324+
<tabstop>cbxDelimTab</tabstop>
1325+
<tabstop>cbxDelimColon</tabstop>
1326+
<tabstop>cbxDelimSpace</tabstop>
1327+
<tabstop>cbxDelimSemicolon</tabstop>
1328+
<tabstop>cbxDelimComma</tabstop>
1329+
<tabstop>txtDelimiterOther</tabstop>
1330+
<tabstop>txtQuoteChars</tabstop>
1331+
<tabstop>txtEscapeChars</tabstop>
1332+
<tabstop>recordOptionsGroupBox</tabstop>
1333+
<tabstop>rowCounter</tabstop>
1334+
<tabstop>cbxUseHeader</tabstop>
12961335
<tabstop>cbxPointIsComma</tabstop>
1336+
<tabstop>cbxTrimFields</tabstop>
1337+
<tabstop>cbxSkipEmptyFields</tabstop>
1338+
<tabstop>geometryDefinitionGroupBox</tabstop>
1339+
<tabstop>geomTypeXY</tabstop>
1340+
<tabstop>geomTypeWKT</tabstop>
12971341
<tabstop>geomTypeNone</tabstop>
1342+
<tabstop>cmbXField</tabstop>
1343+
<tabstop>cmbYField</tabstop>
1344+
<tabstop>cbxXyDms</tabstop>
1345+
<tabstop>crsGeometry</tabstop>
1346+
<tabstop>layeSettingsGroupBox</tabstop>
12981347
<tabstop>cbxSpatialIndex</tabstop>
12991348
<tabstop>cbxSubsetIndex</tabstop>
1349+
<tabstop>cbxWatchFile</tabstop>
1350+
<tabstop>tblSample</tabstop>
1351+
<tabstop>cmbWktField</tabstop>
1352+
<tabstop>cmbGeometryType</tabstop>
1353+
<tabstop>txtDelimiterRegexp</tabstop>
13001354
</tabstops>
13011355
<resources/>
13021356
<connections>

0 commit comments

Comments
 (0)
Please sign in to comment.