33
33
#include < QPushButton>
34
34
#include < QToolButton>
35
35
#include < QMessageBox>
36
+ #include < QDialogButtonBox>
36
37
#include < QUrl>
37
38
38
39
void QgsHandleBadLayersHandler::handleBadLayers ( const QList<QDomNode> &layers )
39
40
{
40
41
QApplication::setOverrideCursor ( Qt::ArrowCursor );
41
42
QgsHandleBadLayers *dialog = new QgsHandleBadLayers ( layers );
42
43
44
+ dialog->buttonBox ->button ( QDialogButtonBox::Ignore )->setToolTip ( tr ( " Import all bad layers unmodified (you can fix them later)." ) );
45
+ dialog->buttonBox ->button ( QDialogButtonBox::Apply )->setToolTip ( tr ( " Apply fixes to bad layers (remaining bad layers will be removed from the project)." ) );
46
+ dialog->buttonBox ->button ( QDialogButtonBox::Discard )->setToolTip ( tr ( " Remove all bad layers from the project" ) );
47
+
43
48
if ( dialog->layerCount () < layers.size () )
44
49
QgisApp::instance ()->messageBar ()->pushMessage (
45
50
tr ( " Handle bad layers" ),
@@ -72,6 +77,8 @@ QgsHandleBadLayers::QgsHandleBadLayers( const QList<QDomNode> &layers )
72
77
connect ( mLayerList , &QTableWidget::itemSelectionChanged, this , &QgsHandleBadLayers::selectionChanged );
73
78
connect ( mBrowseButton , &QAbstractButton::clicked, this , &QgsHandleBadLayers::browseClicked );
74
79
connect ( buttonBox->button ( QDialogButtonBox::Apply ), &QAbstractButton::clicked, this , &QgsHandleBadLayers::apply );
80
+ connect ( buttonBox->button ( QDialogButtonBox::Ignore ), &QPushButton::clicked, this , &QgsHandleBadLayers::reject );
81
+ connect ( buttonBox->button ( QDialogButtonBox::Discard ), &QPushButton::clicked, this , &QgsHandleBadLayers::accept );
75
82
76
83
mLayerList ->clear ();
77
84
mLayerList ->setSortingEnabled ( true );
@@ -340,6 +347,13 @@ void QgsHandleBadLayers::editAuthCfg()
340
347
341
348
void QgsHandleBadLayers::apply ()
342
349
{
350
+ QList<QgsMapLayer *> toRemove;
351
+ for ( const auto &l : QgsProject::instance ()->mapLayers ( ) )
352
+ {
353
+ if ( ! l->isValid () )
354
+ toRemove << l;
355
+ }
356
+ QgsProject::instance ()->removeMapLayers ( toRemove );
343
357
for ( int i = 0 ; i < mLayerList ->rowCount (); i++ )
344
358
{
345
359
int idx = mLayerList ->item ( i, 0 )->data ( Qt::UserRole ).toInt ();
@@ -364,7 +378,6 @@ void QgsHandleBadLayers::accept()
364
378
{
365
379
apply ();
366
380
367
- /*
368
381
if ( mLayerList ->rowCount () > 0 &&
369
382
QMessageBox::warning ( this ,
370
383
tr ( " Unhandled layer will be lost." ),
@@ -376,29 +389,15 @@ void QgsHandleBadLayers::accept()
376
389
{
377
390
return ;
378
391
}
379
- */
380
-
381
- QDialog::accept ();
382
- }
383
-
384
- void QgsHandleBadLayers::reject ()
385
- {
386
-
387
- /*
388
- if ( mLayerList->rowCount() > 0 &&
389
- QMessageBox::warning( this,
390
- tr( "Unhandled layer will be lost." ),
391
- tr( "There are still %n unhandled layer(s), that will be lost if you closed now.",
392
- "unhandled layers",
393
- mLayerList->rowCount() ),
394
- QMessageBox::Ok | QMessageBox::Cancel,
395
- QMessageBox::Cancel ) == QMessageBox::Cancel )
392
+ QList<QgsMapLayer *> toRemove;
393
+ for ( const auto &l : QgsProject::instance ()->mapLayers ( ) )
396
394
{
397
- return;
395
+ if ( ! l->isValid () )
396
+ toRemove << l;
398
397
}
399
- */
398
+ mLayerList -> clear ();
400
399
401
- QDialog::reject ();
400
+ QDialog::accept ();
402
401
}
403
402
404
403
int QgsHandleBadLayers::layerCount ()
0 commit comments