@@ -97,49 +97,22 @@ QgsOgrSourceSelect::QgsOgrSourceSelect( QWidget *parent, Qt::WindowFlags fl, Qgs
97
97
}
98
98
cmbDatabaseTypes->blockSignals ( false );
99
99
cmbConnections->blockSignals ( false );
100
- }
101
-
102
- QgsOgrSourceSelect::~QgsOgrSourceSelect ()
103
- {
104
- QgsSettings settings;
105
- settings.setValue ( QStringLiteral ( " Windows/OpenVectorLayer/geometry" ), saveGeometry () );
106
- }
107
100
108
- QStringList QgsOgrSourceSelect::openFile ()
109
- {
110
- QStringList selectedFiles;
111
- QgsDebugMsg ( " Vector file filters: " + mVectorFileFilter );
112
- QString enc = encoding ();
113
- QString title = tr ( " Open an OGR Supported Vector Layer" );
114
- QgsGuiUtils::openFilesRememberingFilter ( QStringLiteral ( " lastVectorFileFilter" ), mVectorFileFilter , selectedFiles, enc, title );
101
+ mFileWidget ->setDialogTitle ( tr ( " Open OGR Supported Vector Dataset(s)" ) );
102
+ mFileWidget ->setFilter ( mVectorFileFilter );
103
+ mFileWidget ->setStorageMode ( QgsFileWidget::GetMultipleFiles );
115
104
116
- return selectedFiles;
105
+ connect ( mFileWidget , &QgsFileWidget::fileChanged, this , [ = ]( const QString & path )
106
+ {
107
+ mVectorPath = path;
108
+ emit enableButtons ( ! mVectorPath .isEmpty () );
109
+ } );
117
110
}
118
111
119
- QString QgsOgrSourceSelect::openDirectory ()
112
+ QgsOgrSourceSelect::~QgsOgrSourceSelect ()
120
113
{
121
114
QgsSettings settings;
122
-
123
- bool haveLastUsedDir = settings.contains ( QStringLiteral ( " /UI/LastUsedDirectory" ) );
124
- QString lastUsedDir = settings.value ( QStringLiteral ( " UI/LastUsedDirectory" ), QDir::homePath () ).toString ();
125
- if ( !haveLastUsedDir )
126
- lastUsedDir = QLatin1String ( " " );
127
-
128
- QString path = QFileDialog::getExistingDirectory ( this ,
129
- tr ( " Open Directory" ), lastUsedDir,
130
- QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks );
131
-
132
- settings.setValue ( QStringLiteral ( " UI/LastUsedDirectory" ), path );
133
- // process path if it is grass
134
- if ( cmbDirectoryTypes->currentText () == QLatin1String ( " Grass Vector" ) )
135
- {
136
- #ifdef Q_OS_WIN
137
- // replace backslashes with forward slashes
138
- path.replace ( ' \\ ' , ' /' );
139
- #endif
140
- path = path + " /head" ;
141
- }
142
- return path;
115
+ settings.setValue ( QStringLiteral ( " Windows/OpenVectorLayer/geometry" ), saveGeometry () );
143
116
}
144
117
145
118
QStringList QgsOgrSourceSelect::dataSources ()
@@ -272,29 +245,6 @@ void QgsOgrSourceSelect::setSelectedConnection()
272
245
QgsDebugMsg ( " Setting selected connection to " + cmbConnections->currentText () );
273
246
}
274
247
275
-
276
- void QgsOgrSourceSelect::on_buttonSelectSrc_clicked ()
277
- {
278
- if ( radioSrcFile->isChecked () )
279
- {
280
- QStringList selected = openFile ();
281
- if ( !selected.isEmpty () )
282
- {
283
- inputSrcDataset->setText ( selected.join ( QStringLiteral ( " ;" ) ) );
284
- addButton ()->setFocus ();
285
- emit enableButtons ( true );
286
- }
287
- }
288
- else if ( radioSrcDirectory->isChecked () )
289
- {
290
- inputSrcDataset->setText ( openDirectory () );
291
- }
292
- else if ( !radioSrcDatabase->isChecked () )
293
- {
294
- Q_ASSERT ( !" SHOULD NEVER GET HERE" );
295
- }
296
- }
297
-
298
248
void QgsOgrSourceSelect::addButtonClicked ()
299
249
{
300
250
QgsSettings settings;
@@ -359,27 +309,37 @@ void QgsOgrSourceSelect::addButtonClicked()
359
309
}
360
310
else if ( radioSrcFile->isChecked () )
361
311
{
362
- if ( inputSrcDataset-> text () .isEmpty () )
312
+ if ( mVectorPath .isEmpty () )
363
313
{
364
314
QMessageBox::information ( this ,
365
315
tr ( " Add vector layer" ),
366
316
tr ( " No layers selected." ) );
367
317
return ;
368
318
}
369
319
370
- mDataSources << inputSrcDataset-> text (). split ( ' ; ' );
320
+ mDataSources << QgsFileWidget::splitFilePaths ( mVectorPath );
371
321
}
372
322
else if ( radioSrcDirectory->isChecked () )
373
323
{
374
- if ( inputSrcDataset-> text () .isEmpty () )
324
+ if ( mVectorPath .isEmpty () )
375
325
{
376
326
QMessageBox::information ( this ,
377
327
tr ( " Add vector layer" ),
378
328
tr ( " No directory selected." ) );
379
329
return ;
380
330
}
381
331
382
- mDataSources << inputSrcDataset->text ();
332
+ // process path if it is grass
333
+ if ( cmbDirectoryTypes->currentText () == QLatin1String ( " Grass Vector" ) )
334
+ {
335
+ #ifdef Q_OS_WIN
336
+ // replace backslashes with forward slashes
337
+ mVectorPath .replace ( ' \\ ' , ' /' );
338
+ #endif
339
+ mVectorPath = mVectorPath + " /head" ;
340
+ }
341
+
342
+ mDataSources << mVectorPath ;
383
343
}
384
344
385
345
// Save the used encoding
@@ -402,6 +362,12 @@ void QgsOgrSourceSelect::on_radioSrcFile_toggled( bool checked )
402
362
fileGroupBox->show ();
403
363
dbGroupBox->hide ();
404
364
protocolGroupBox->hide ();
365
+
366
+ mFileWidget ->setDialogTitle ( tr ( " Open an OGR Supported Vector Layer" ) );
367
+ mFileWidget ->setFilter ( mVectorFileFilter );
368
+ mFileWidget ->setStorageMode ( QgsFileWidget::GetMultipleFiles );
369
+ mFileWidget ->setFilePath ( QString () );
370
+
405
371
mDataSourceType = QStringLiteral ( " file" );
406
372
}
407
373
}
@@ -415,6 +381,11 @@ void QgsOgrSourceSelect::on_radioSrcDirectory_toggled( bool checked )
415
381
fileGroupBox->show ();
416
382
dbGroupBox->hide ();
417
383
protocolGroupBox->hide ();
384
+
385
+ mFileWidget ->setDialogTitle ( tr ( " Open Directory" ) );
386
+ mFileWidget ->setStorageMode ( QgsFileWidget::GetDirectory );
387
+ mFileWidget ->setFilePath ( QString () );
388
+
418
389
mDataSourceType = QStringLiteral ( " directory" );
419
390
}
420
391
}
0 commit comments