Skip to content
Permalink
Browse files
Add some extra tests. Use it when on Add button click
- the 'Unique Id' checkbox could be checked without given an id
- UNchecking that checkbox but leaving the id would still use the id
- you could use the Add button with an invalid query, now you run
the same tests when adding the layer as you would with the Test button
- check the fix for Unique Id Field (was never hit)
  • Loading branch information
rduivenvoorde authored and nyalldawson committed Sep 6, 2021
1 parent f0f5203 commit 5c35539c8dcab75698845482af0f9f49ec0d94ff
@@ -178,7 +178,7 @@ QgsVirtualLayerDefinition QgsVirtualLayerSourceSelect::getVirtualLayerDef()
{
def.setQuery( mQueryEdit->text() );
}
if ( ! mUIDField->text().isEmpty() )
if ( mUIDColumnNameChck->isChecked() && ! mUIDField->text().isEmpty() )
{
def.setUid( mUIDField->text() );
}
@@ -207,7 +207,7 @@ QgsVirtualLayerDefinition QgsVirtualLayerSourceSelect::getVirtualLayerDef()
return def;
}

void QgsVirtualLayerSourceSelect::testQuery()
bool QgsVirtualLayerSourceSelect::preFlight()
{
const QgsVirtualLayerDefinition def = getVirtualLayerDef();
// If the definition is empty just do nothing.
@@ -220,7 +220,11 @@ void QgsVirtualLayerSourceSelect::testQuery()
if ( vl->isValid() )
{
const QStringList fieldNames = vl->fields().names();
if ( !mUIDField->text().isEmpty() && !vl->fields().names().contains( mUIDField->text() ) )
if ( mUIDColumnNameChck->isChecked() && mUIDField->text().isEmpty() )
{
QMessageBox::warning( nullptr, tr( "Test Virtual Layer " ), tr( "Checkbox 'Unique identifier column' is checked, but no field given" ) );
}
else if ( mUIDColumnNameChck->isChecked() && !mUIDField->text().isEmpty() && !vl->fields().names().contains( mUIDField->text() ) )
{
QStringList bulletedFieldNames;
for ( const QString &fieldName : fieldNames )
@@ -230,13 +234,24 @@ void QgsVirtualLayerSourceSelect::testQuery()
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" ) );
{
return true;
}
}
else
{
QMessageBox::critical( nullptr, tr( "Test Virtual Layer" ), vl->dataProvider()->error().summary() );
}
}
return false;
}

void QgsVirtualLayerSourceSelect::testQuery()
{
if ( preFlight() )
{
QMessageBox::information( nullptr, tr( "Test Virtual Layer" ), tr( "No error" ) );
}
}

void QgsVirtualLayerSourceSelect::addLayer()
@@ -378,6 +393,11 @@ void QgsVirtualLayerSourceSelect::importLayer()

void QgsVirtualLayerSourceSelect::addButtonClicked()
{
if ( ! preFlight() )
{
return;
}

QString layerName = QStringLiteral( "virtual_layer" );
QString id;
bool replace = false;
@@ -64,6 +64,7 @@ class QgsVirtualLayerSourceSelect : public QgsAbstractDataSourceWidget, private
QgsEmbeddedLayerSelectDialog *mEmbeddedSelectionDialog = nullptr;
void addEmbeddedLayer( const QString &name, const QString &provider, const QString &encoding, const QString &source );
QgsLayerTreeView *mTreeView = nullptr;
bool preFlight();
};

#endif

0 comments on commit 5c35539

Please sign in to comment.