Skip to content

Commit

Permalink
[virtual layers] warn if unique identifier is not a valid field name
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn authored and nyalldawson committed Nov 19, 2020
1 parent 6797118 commit 11b577e
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/providers/virtual/qgsvirtuallayersourceselect.cpp
Expand Up @@ -218,7 +218,18 @@ void QgsVirtualLayerSourceSelect::testQuery()
std::unique_ptr<QgsVectorLayer> vl( new QgsVectorLayer( def.toString(), QStringLiteral( "test" ), QStringLiteral( "virtual" ), options ) );
if ( vl->isValid() )
{
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( QStringLiteral( "<li>%1" ).arg( fieldName ) );
}
QMessageBox::warning( nullptr, tr( "Virtual layer test " ), 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( "Virtual layer test" ), tr( "No error" ) );
}
else
{
Expand Down

0 comments on commit 11b577e

Please sign in to comment.