[bugfix] Do not crash when testing empty virtual layers

Fixes #17489

Require backporting
This commit is contained in:
Alessandro Pasotti 2017-11-20 08:55:08 +01:00
parent e9ce901adc
commit 4272f5d825

View File

@ -199,15 +199,20 @@ QgsVirtualLayerDefinition QgsVirtualLayerSourceSelect::getVirtualLayerDef()
void QgsVirtualLayerSourceSelect::onTestQuery()
{
QgsVirtualLayerDefinition def = getVirtualLayerDef();
std::unique_ptr<QgsVectorLayer> vl( new QgsVectorLayer( def.toString(), QStringLiteral( "test" ), QStringLiteral( "virtual" ) ) );
if ( vl->isValid() )
// 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::information( nullptr, tr( "Virtual layer test" ), tr( "No error" ) );
}
else
{
QMessageBox::critical( nullptr, tr( "Virtual layer test" ), vl->dataProvider()->error().summary() );
std::unique_ptr<QgsVectorLayer> vl( new QgsVectorLayer( def.toString(), QStringLiteral( "test" ), QStringLiteral( "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() );
}
}
}