@@ -166,7 +166,7 @@ void QgsDelimitedTextSourceSelect::on_buttonBox_accepted()
166
166
settings.setValue ( key + " /delimiterType" , " plain" );
167
167
else
168
168
settings.setValue ( key + " /delimiterType" , " regexp" );
169
- settings.setValue ( key + " /delimiterChars" , selectedChars () );
169
+ settings.setValue ( key + " /delimiterChars" , selectedChars (). join ( " " ) );
170
170
171
171
accept ();
172
172
}
@@ -181,37 +181,50 @@ void QgsDelimitedTextSourceSelect::on_buttonBox_rejected()
181
181
reject ();
182
182
}
183
183
184
- QString QgsDelimitedTextSourceSelect::selectedChars ()
184
+ QStringList QgsDelimitedTextSourceSelect::selectedChars ()
185
185
{
186
- QString chars = " " ;
186
+ QStringList chars;
187
187
if ( cbxDelimSpace->isChecked () )
188
- chars += " " ;
188
+ chars << " " ;
189
189
if ( cbxDelimTab->isChecked () )
190
- chars += " \\ t" ;
190
+ chars << " \\ t" ;
191
191
if ( cbxDelimSemicolon->isChecked () )
192
- chars += " ;" ;
192
+ chars << " ;" ;
193
193
if ( cbxDelimComma->isChecked () )
194
- chars += " ," ;
194
+ chars << " ," ;
195
195
if ( cbxDelimColon->isChecked () )
196
- chars += " :" ;
196
+ chars << " :" ;
197
197
return chars;
198
198
}
199
199
200
200
QStringList QgsDelimitedTextSourceSelect::splitLine ( QString line )
201
201
{
202
- QString delimiter = txtDelimiter->text ();
202
+ QString delimiter;
203
+ if ( delimiterSelection->isChecked () )
204
+ {
205
+ if ( selectedChars ().size () > 1 )
206
+ {
207
+ delimiter = " [" + selectedChars ().join ( " " ) + " ]" ;
208
+ }
209
+ else
210
+ {
211
+ delimiter = selectedChars ().join ( " " );
212
+ }
213
+ txtDelimiter->setText ( delimiter );
214
+ }
215
+ else
216
+ {
217
+ delimiter = txtDelimiter->text ();
218
+ }
203
219
204
220
if ( delimiterPlain->isChecked () )
205
221
{
206
222
return QgsDelimitedTextProvider::splitLine ( line, " plain" , delimiter );
207
223
}
208
224
209
- if ( delimiterSelection->isChecked () )
225
+ if ( delimiterSelection->isChecked () && selectedChars (). size () <= 1 )
210
226
{
211
- delimiter = " [" ;
212
- delimiter += selectedChars ();
213
- delimiter += " ]" ;
214
- txtDelimiter->setText ( delimiter );
227
+ return QgsDelimitedTextProvider::splitLine ( line, " plain" , delimiter );
215
228
}
216
229
217
230
return QgsDelimitedTextProvider::splitLine ( line, " regexp" , delimiter );
@@ -291,8 +304,6 @@ void QgsDelimitedTextSourceSelect::updateFieldLists()
291
304
292
305
QgsDebugMsg ( QString ( " Attempting to split the input line: %1 using delimiter %2" ).arg ( line ).arg ( txtDelimiter->text () ) );
293
306
294
- QString delimiter = txtDelimiter->text ();
295
-
296
307
QStringList fieldList = splitLine ( line );
297
308
298
309
QgsDebugMsg ( QString ( " Split line into %1 parts" ).arg ( fieldList.size () ) );
0 commit comments