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
github-actions[bot] authored and nyalldawson committed Nov 19, 2020
1 parent 2bd49ff commit 7161699
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/providers/virtual/qgsvirtuallayersourceselect.cpp
Expand Up @@ -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() );
}
}
}
Expand Down

0 comments on commit 7161699

Please sign in to comment.