Skip to content

Commit

Permalink
Restore handle bad layers dialog original behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed Nov 5, 2018
1 parent 8493636 commit d46d765
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/app/qgshandlebadlayers.cpp
Expand Up @@ -26,6 +26,7 @@
#include "qgsproviderregistry.h"
#include "qgsmessagebar.h"
#include "qgssettings.h"
#include "qgslayertreeregistrybridge.h"

#include <QDomDocument>
#include <QDomElement>
Expand Down Expand Up @@ -347,13 +348,17 @@ void QgsHandleBadLayers::editAuthCfg()

void QgsHandleBadLayers::apply()
{
QgsProject::instance()->layerTreeRegistryBridge()->setEnabled( true );

QList<QgsMapLayer *> toRemove;
for ( const auto &l : QgsProject::instance()->mapLayers( ) )
{
if ( ! l->isValid() )
toRemove << l;
}

QgsProject::instance()->removeMapLayers( toRemove );

for ( int i = 0; i < mLayerList->rowCount(); i++ )
{
int idx = mLayerList->item( i, 0 )->data( Qt::UserRole ).toInt();
Expand All @@ -372,11 +377,15 @@ void QgsHandleBadLayers::apply()
item->setForeground( QBrush( Qt::red ) );
}
}
QgsProject::instance()->layerTreeRegistryBridge()->setEnabled( false );

if ( mLayerList->rowCount() == 0 )
accept();

}

void QgsHandleBadLayers::accept()
{
apply();

if ( mLayerList->rowCount() > 0 &&
QMessageBox::warning( this,
Expand All @@ -395,6 +404,9 @@ void QgsHandleBadLayers::accept()
if ( ! l->isValid() )
toRemove << l;
}
QgsProject::instance()->layerTreeRegistryBridge()->setEnabled( true );
QgsProject::instance()->removeMapLayers( toRemove );
QgsProject::instance()->layerTreeRegistryBridge()->setEnabled( false );
mLayerList->clear();

QDialog::accept();
Expand Down
Binary file modified tests/testdata/projects/bad_layers_test.gpkg
Binary file not shown.

0 comments on commit d46d765

Please sign in to comment.