Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[bugfix] Do not crash when testing empty virtual layers
Fixes #17489

Backported from master
  • Loading branch information
elpaso committed Nov 20, 2017
1 parent 33e939c commit ac109e4
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/providers/virtual/qgsvirtuallayersourceselect.cpp
Expand Up @@ -229,15 +229,20 @@ QgsVirtualLayerDefinition QgsVirtualLayerSourceSelect::getVirtualLayerDef()
void QgsVirtualLayerSourceSelect::onTestQuery()
{
QgsVirtualLayerDefinition def = getVirtualLayerDef();

QScopedPointer<QgsVectorLayer> vl( new QgsVectorLayer( def.toString(), "test", "virtual" ) );
if ( vl->isValid() )
{
QMessageBox::information( nullptr, tr( "Virtual layer test" ), tr( "No error" ) );
}
else
// If the definition is empty just do nothing.
// TODO: a validation function that can enable/disable the test button
// according to the validity of the active layer definition
if ( ! def.toString().isEmpty() )
{
QMessageBox::critical( nullptr, tr( "Virtual layer test" ), vl->dataProvider()->error().summary() );
QScopedPointer<QgsVectorLayer> vl( new QgsVectorLayer( def.toString(), "test", "virtual" ) );
if ( vl->isValid() )
{
QMessageBox::information( nullptr, tr( "Virtual layer test" ), tr( "No error" ) );
}
else
{
QMessageBox::critical( nullptr, tr( "Virtual layer test" ), vl->dataProvider()->error().summary() );
}
}
}

Expand Down

0 comments on commit ac109e4

Please sign in to comment.