Skip to content
Permalink
Browse files

[virtual layers] warn if unique identifier is not a valid field name

  • Loading branch information
github-actions authored and nyalldawson committed Nov 19, 2020
1 parent 2bd49ff commit 71616999b3a06084a7cc32186c045ae5a514b3ad
Showing with 16 additions and 1 deletion.
  1. +16 −1 src/providers/virtual/qgsvirtuallayersourceselect.cpp
@@ -218,11 +218,26 @@ void QgsVirtualLayerSourceSelect::testQuery()
std::unique_ptr<QgsVectorLayer> vl( new QgsVectorLayer( def.toString(), QStringLiteral( "test" ), QStringLiteral( "virtual" ), options ) );
if ( vl->isValid() )
{
<<<<<<< HEAD
QMessageBox::information( nullptr, tr( "Virtual layer test" ), tr( "No error" ) );
=======
const QStringList fieldNames = vl->fields().names();
if ( !mUIDField->text().isEmpty() && !vl->fields().names().contains( mUIDField->text() ) )
{
QStringList bulletedFieldNames;
for ( const QString &fieldName : fieldNames )
{
bulletedFieldNames.append( QLatin1String( "<li>" ) + fieldName + QLatin1String( "</li>" ) );
}
QMessageBox::warning( nullptr, tr( "Test Virtual Layer " ), tr( "The unique identifier field <b>%1</b> was not found in list of fields:<ul>%2</ul>" ).arg( mUIDField->text(), bulletedFieldNames.join( ' ' ) ) );
}
else
QMessageBox::information( nullptr, tr( "Test Virtual Layer" ), tr( "No error" ) );
>>>>>>> f3f052247b (Beautiful HTML)
}
else
{
QMessageBox::critical( nullptr, tr( "Virtual layer test" ), vl->dataProvider()->error().summary() );
QMessageBox::critical( nullptr, tr( "Test Virtual Layer" ), vl->dataProvider()->error().summary() );
}
}
}

0 comments on commit 7161699

Please sign in to comment.
You can’t perform that action at this time.