26
26
27
27
#include < QDomDocument>
28
28
#include < QDomElement>
29
+ #include < QFileDialog>
29
30
#include < QPushButton>
30
31
#include < QMessageBox>
32
+ #include < QSettings>
31
33
#include < QUrl>
32
34
33
35
QgsHandleBadLayersHandler::QgsHandleBadLayersHandler ()
@@ -71,7 +73,6 @@ QgsHandleBadLayers::QgsHandleBadLayers( const QList<QDomNode> &layers, const QDo
71
73
72
74
connect ( mLayerList , SIGNAL ( itemSelectionChanged () ), this , SLOT ( selectionChanged () ) );
73
75
connect ( mBrowseButton , SIGNAL ( clicked () ), this , SLOT ( browseClicked () ) );
74
- connect ( buttonBox, SIGNAL ( accepted () ), this , SLOT ( accept () ) );
75
76
connect ( buttonBox->button ( QDialogButtonBox::Apply ), SIGNAL ( clicked () ), this , SLOT ( apply () ) );
76
77
77
78
mLayerList ->clear ();
@@ -94,12 +95,14 @@ QgsHandleBadLayers::QgsHandleBadLayers( const QList<QDomNode> &layers, const QDo
94
95
QString name = node.namedItem ( " layername" ).toElement ().text ();
95
96
QString type = node.toElement ().attribute ( " type" );
96
97
QString datasource = node.namedItem ( " datasource" ).toElement ().text ();
97
- QString provider = type == " vector" ? node.namedItem ( " provider" ).toElement ().text () : tr ( " none" );
98
+ QString provider = node.namedItem ( " provider" ).toElement ().text ();
99
+ QString vectorProvider = type == " vector" ? provider : tr ( " none" );
100
+ bool providerFileBased = ( QgsProviderRegistry::instance ()->getProviderCapabilities ( provider ) & QgsDataProvider::File ) != 0 ;
98
101
99
102
QgsDebugMsg ( QString ( " name=%1 type=%2 provider=%3 datasource='%4'" )
100
103
.arg ( name )
101
104
.arg ( type )
102
- .arg ( provider )
105
+ .arg ( vectorProvider )
103
106
.arg ( datasource ) );
104
107
105
108
mLayerList ->setRowCount ( j + 1 );
@@ -112,10 +115,11 @@ QgsHandleBadLayers::QgsHandleBadLayers( const QList<QDomNode> &layers, const QDo
112
115
mLayerList ->setItem ( j, 0 , item );
113
116
114
117
item = new QTableWidgetItem ( type );
118
+ item->setData ( Qt::UserRole + 0 , providerFileBased );
115
119
item->setFlags ( item->flags () & ~Qt::ItemIsEditable );
116
120
mLayerList ->setItem ( j, 1 , item );
117
121
118
- item = new QTableWidgetItem ( provider );
122
+ item = new QTableWidgetItem ( vectorProvider );
119
123
item->setFlags ( item->flags () & ~Qt::ItemIsEditable );
120
124
mLayerList ->setItem ( j, 2 , item );
121
125
@@ -143,6 +147,10 @@ void QgsHandleBadLayers::selectionChanged()
143
147
if ( item->column () != 0 )
144
148
continue ;
145
149
150
+ bool providerFileBased = mLayerList ->item ( item->row (), 1 )->data ( Qt::UserRole + 0 ).toBool ();
151
+ if ( !providerFileBased )
152
+ continue ;
153
+
146
154
mRows << item->row ();
147
155
}
148
156
@@ -261,31 +269,34 @@ void QgsHandleBadLayers::browseClicked()
261
269
}
262
270
else if ( mRows .size () > 1 )
263
271
{
264
- QStringList selectedFiles;
265
- QString enc;
266
272
QString title = tr ( " Select new directory of selected files" );
267
273
268
- QgisGui::openFilesRememberingFilter ( " missingDirectory" , tr ( " All files (*)" ), selectedFiles, enc, title );
269
- if ( selectedFiles.isEmpty () )
274
+ QSettings settings;
275
+ QString lastDir = settings.value ( " /UI/missingDirectory" , " " ).toString ();
276
+ QString selectedFolder = QFileDialog::getExistingDirectory ( this , title, lastDir );
277
+ if ( selectedFolder.isEmpty () )
270
278
{
271
279
return ;
272
280
}
273
281
274
- QFileInfo path ( selectedFiles[ 0 ] );
275
- if ( !path .exists () )
282
+ QDir dir ( selectedFolder );
283
+ if ( !dir .exists () )
276
284
{
277
285
return ;
278
286
}
279
287
280
288
foreach ( int row, mRows )
281
289
{
282
- QString type = mLayerList ->item ( row, 1 )->text ();
290
+ bool providerFileBased = mLayerList ->item ( row, 1 )->data ( Qt::UserRole + 0 ).toBool ();
291
+ if ( !providerFileBased )
292
+ continue ;
293
+
283
294
QString fn = filename ( row );
284
295
if ( fn.isEmpty () )
285
296
continue ;
286
297
287
298
QFileInfo fi ( fn );
288
- fi.setFile ( path. dir () , fi.fileName () );
299
+ fi.setFile ( dir, fi.fileName () );
289
300
if ( !fi.exists () )
290
301
continue ;
291
302
0 commit comments