Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Mar 14, 2020
1 parent 8ebfc85 commit 3c11776
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
10 changes: 5 additions & 5 deletions src/gui/processing/qgsprocessingwidgetwrapperimpl.cpp
Expand Up @@ -4175,8 +4175,8 @@ void QgsProcessingDatabaseSchemaWidgetWrapper::setParentConnectionWrapperValue(
context = tmpContext.get();
}

QVariant value = parentWrapper->parameterValue();
const QString connection = QgsProcessingParameters::parameterAsConnectionName( parentWrapper->parameterDefinition(), value, *context );
const QVariant value = parentWrapper->parameterValue();
const QString connection = value.isValid() ? QgsProcessingParameters::parameterAsConnectionName( parentWrapper->parameterDefinition(), value, *context ) : QString();

if ( mSchemaComboBox )
mSchemaComboBox->setConnectionName( connection, dynamic_cast< const QgsProcessingParameterProviderConnection * >( parentWrapper->parameterDefinition() )->providerId() );
Expand Down Expand Up @@ -4433,9 +4433,9 @@ void QgsProcessingDatabaseTableWidgetWrapper::setParentConnectionWrapperValue( c
}

QVariant value = parentWrapper->parameterValue();
mConnection = QgsProcessingParameters::parameterAsConnectionName( parentWrapper->parameterDefinition(), value, *context );
mConnection = value.isValid() ? QgsProcessingParameters::parameterAsConnectionName( parentWrapper->parameterDefinition(), value, *context ) : QString();
mProvider = dynamic_cast< const QgsProcessingParameterProviderConnection * >( parentWrapper->parameterDefinition() )->providerId();
if ( mTableComboBox && !mSchema.isEmpty() && !mConnection.isEmpty() )
if ( mTableComboBox && !mSchema.isEmpty() )
{
mTableComboBox->setSchema( mSchema );
mTableComboBox->setConnectionName( mConnection, mProvider );
Expand All @@ -4461,7 +4461,7 @@ void QgsProcessingDatabaseTableWidgetWrapper::setParentSchemaWrapperValue( const
}

QVariant value = parentWrapper->parameterValue();
mSchema = QgsProcessingParameters::parameterAsSchema( parentWrapper->parameterDefinition(), value, *context );
mSchema = value.isValid() ? QgsProcessingParameters::parameterAsSchema( parentWrapper->parameterDefinition(), value, *context ) : QString();

if ( mTableComboBox && !mSchema.isEmpty() && !mConnection.isEmpty() )
{
Expand Down
14 changes: 11 additions & 3 deletions src/gui/qgsdatabaseschemacombobox.cpp
Expand Up @@ -121,9 +121,17 @@ void QgsDatabaseSchemaComboBox::setConnectionName( const QString &connection, co

const QString oldSchema = currentSchema();
QgsDatabaseSchemaModel *oldModel = mModel;
mModel = new QgsDatabaseSchemaModel( mProvider, connection, this );
mModel->setAllowEmptySchema( mAllowEmpty );
mSortModel->setSourceModel( mModel );
if ( !connection.isEmpty() && !mProvider.isEmpty() )
{
mModel = new QgsDatabaseSchemaModel( mProvider, connection, this );
mModel->setAllowEmptySchema( mAllowEmpty );
mSortModel->setSourceModel( mModel );
}
else
{
mModel = nullptr;
mSortModel->setSourceModel( nullptr );
}
if ( oldModel )
oldModel->deleteLater();

Expand Down
8 changes: 5 additions & 3 deletions tests/src/gui/testprocessinggui.cpp
Expand Up @@ -4766,7 +4766,7 @@ void TestProcessingGui::testDatabaseSchemaWrapper()

auto testWrapper = [&schemas]( QgsProcessingGui::WidgetType type )
{
QgsProcessingParameterProviderConnection connParam( QStringLiteral( "conn" ), QStringLiteral( "connection" ), QStringLiteral( "postgres" ), true );
QgsProcessingParameterProviderConnection connParam( QStringLiteral( "conn" ), QStringLiteral( "connection" ), QStringLiteral( "postgres" ), QVariant(), true );
TestLayerWrapper connWrapper( &connParam );

QgsProcessingParameterDatabaseSchema param( QStringLiteral( "schema" ), QStringLiteral( "schema" ), QStringLiteral( "conn" ), QVariant(), false );
Expand Down Expand Up @@ -4827,6 +4827,7 @@ void TestProcessingGui::testDatabaseSchemaWrapper()
// make sure things are ok if connection is changed back to nothing
connWrapper.setWidgetValue( QVariant(), context );
wrapper.setParentConnectionWrapperValue( &connWrapper );
QCOMPARE( static_cast< QgsDatabaseSchemaComboBox * >( wrapper.wrappedWidget() )->comboBox()->count(), 0 );

switch ( type )
{
Expand Down Expand Up @@ -4969,9 +4970,9 @@ void TestProcessingGui::testDatabaseTableWrapper()

auto testWrapper = [&tableNames]( QgsProcessingGui::WidgetType type )
{
QgsProcessingParameterProviderConnection connParam( QStringLiteral( "conn" ), QStringLiteral( "connection" ), QStringLiteral( "postgres" ), true );
QgsProcessingParameterProviderConnection connParam( QStringLiteral( "conn" ), QStringLiteral( "connection" ), QStringLiteral( "postgres" ), QVariant(), true );
TestLayerWrapper connWrapper( &connParam );
QgsProcessingParameterDatabaseSchema schemaParam( QStringLiteral( "schema" ), QStringLiteral( "schema" ), QStringLiteral( "connection" ), true );
QgsProcessingParameterDatabaseSchema schemaParam( QStringLiteral( "schema" ), QStringLiteral( "schema" ), QStringLiteral( "connection" ), QVariant(), true );
TestLayerWrapper schemaWrapper( &schemaParam );

QgsProcessingParameterDatabaseTable param( QStringLiteral( "table" ), QStringLiteral( "table" ), QStringLiteral( "conn" ), QStringLiteral( "schema" ), QVariant(), false );
Expand Down Expand Up @@ -5034,6 +5035,7 @@ void TestProcessingGui::testDatabaseTableWrapper()
// make sure things are ok if connection is changed back to nothing
connWrapper.setWidgetValue( QVariant(), context );
wrapper.setParentConnectionWrapperValue( &connWrapper );
QCOMPARE( static_cast< QgsDatabaseTableComboBox * >( wrapper.wrappedWidget() )->comboBox()->count(), 0 );

switch ( type )
{
Expand Down

0 comments on commit 3c11776

Please sign in to comment.