Skip to content
Permalink
Browse files
Add flag for select at id in the result dlg
  • Loading branch information
elpaso committed Jul 6, 2021
1 parent 5ba105f commit aa6c1bd5edea826943847a1bfc9ca9c3503f2899
@@ -124,10 +124,11 @@ Returns the number of fetched rows.
struct SqlVectorLayerOptions
{
QString sql; //! The SQL expression that defines the SQL (query) layer
QString filter; //! Additional subset string (provider-side filter), not all data providers support this feature: check support with SqlLayerFilters capability
QString filter; //! Additional subset string (provider-side filter), not all data providers support this feature: check support with SqlLayerDefinitionCapability::Filters capability
QString layerName; //! Optional name for the new layer
QStringList primaryKeyColumns; //! List of primary key column names
QString geometryColumn; //! Name of the geometry column
bool disableSelectAtId; //! If SelectAtId is disabled (default is false), not all data providers support this feature: check support with SqlLayerDefinitionCapability::SelectAtId capability
};

struct TableProperty
@@ -349,7 +350,8 @@ This information is calculated from the geometry columns types.
{
Filters,
GeometryColumn,
PrimaryKeys
PrimaryKeys,
SelectAtId
};

typedef QFlags<QgsAbstractDatabaseProviderConnection::SqlLayerDefinitionCapability> SqlLayerDefinitionCapabilities;
@@ -377,6 +377,12 @@ void QgsGeoPackageProviderConnection::setDefaultCapabilities()
GeometryColumnCapability::SinglePart,
GeometryColumnCapability::Curves
};
mSqlLayerDefinitionCapabilities =
{
SqlLayerDefinitionCapability::Filters,
SqlLayerDefinitionCapability::PrimaryKeys,
SqlLayerDefinitionCapability::GeometryColumn,
};
}

QgsAbstractDatabaseProviderConnection::QueryResult QgsGeoPackageProviderConnection::executeGdalSqlPrivate( const QString &sql, QgsFeedback *feedback ) const
@@ -206,10 +206,11 @@ class CORE_EXPORT QgsAbstractDatabaseProviderConnection : public QgsAbstractProv
struct CORE_EXPORT SqlVectorLayerOptions
{
QString sql; //! The SQL expression that defines the SQL (query) layer
QString filter; //! Additional subset string (provider-side filter), not all data providers support this feature: check support with SqlLayerFilters capability
QString filter; //! Additional subset string (provider-side filter), not all data providers support this feature: check support with SqlLayerDefinitionCapability::Filters capability
QString layerName; //! Optional name for the new layer
QStringList primaryKeyColumns; //! List of primary key column names
QString geometryColumn; //! Name of the geometry column
bool disableSelectAtId; //! If SelectAtId is disabled (default is false), not all data providers support this feature: check support with SqlLayerDefinitionCapability::SelectAtId capability
};

/**
@@ -487,9 +488,10 @@ class CORE_EXPORT QgsAbstractDatabaseProviderConnection : public QgsAbstractProv
*/
enum SqlLayerDefinitionCapability
{
Filters = 1 << 1, //! SQL layer definition support filters
GeometryColumn = 1 << 2, //! SQL layer definition support geometry colum
PrimaryKeys = 1 << 3 //! SQL layer definition support primary keys
Filters = 1 << 1, //! SQL layer definition supports filters
GeometryColumn = 1 << 2, //! SQL layer definition supports geometry colum
PrimaryKeys = 1 << 3, //! SQL layer definition supports primary keys
SelectAtId = 1 << 4 //! SQL layer definition supports disabling select at id
};

Q_ENUM( SqlLayerDefinitionCapability )
@@ -86,6 +86,10 @@ QgsQueryResultWidget::QgsQueryResultWidget( QWidget *parent, QgsAbstractDatabase
mFilterLabel->setVisible( showFilterConfig );
mFilterToolButton->setVisible( showFilterConfig );
mFilterLineEdit->setVisible( showFilterConfig );

const bool showDisableSelectAtId{ connection &&connection->sqlLayerDefinitionCapabilities().testFlag( QgsAbstractDatabaseProviderConnection::SqlLayerDefinitionCapability::SelectAtId ) };
mAvoidSelectingAsFeatureIdCheckBox->setVisible( showDisableSelectAtId );

}
} );

@@ -291,6 +295,7 @@ void QgsQueryResultWidget::syncSqlOptions()
mSqlVectorLayerOptions.primaryKeyColumns = mPkColumnsComboBox->checkedItems();
mSqlVectorLayerOptions.geometryColumn = mGeometryColumnComboBox->currentText();
mSqlVectorLayerOptions.layerName = mLayerNameLineEdit->text();
mSqlVectorLayerOptions.disableSelectAtId = mAvoidSelectingAsFeatureIdCheckBox->isChecked();
}

QgsAbstractDatabaseProviderConnection::SqlVectorLayerOptions QgsQueryResultWidget::sqlVectorLayerOptions() const
@@ -99,6 +99,13 @@ void QgsMssqlProviderConnection::setDefaultCapabilities()
GeometryColumnCapability::M,
GeometryColumnCapability::Curves
};
mSqlLayerDefinitionCapabilities =
{
SqlLayerDefinitionCapability::Filters,
SqlLayerDefinitionCapability::PrimaryKeys,
SqlLayerDefinitionCapability::GeometryColumn,
SqlLayerDefinitionCapability::SelectAtId,
};
}

void QgsMssqlProviderConnection::dropTablePrivate( const QString &schema, const QString &name ) const
@@ -121,6 +121,12 @@ void QgsOracleProviderConnection::setDefaultCapabilities()
GeometryColumnCapability::SinglePart,
GeometryColumnCapability::Curves
};
mSqlLayerDefinitionCapabilities =
{
SqlLayerDefinitionCapability::Filters,
SqlLayerDefinitionCapability::GeometryColumn,
SqlLayerDefinitionCapability::PrimaryKeys,
};
}

void QgsOracleProviderConnection::store( const QString &name ) const
@@ -85,9 +85,10 @@ void QgsPostgresProviderConnection::setDefaultCapabilities()
};
mSqlLayerDefinitionCapabilities =
{
Filters,
PrimaryKeys,
GeometryColumn
SqlLayerDefinitionCapability::Filters,
SqlLayerDefinitionCapability::PrimaryKeys,
SqlLayerDefinitionCapability::GeometryColumn,
SqlLayerDefinitionCapability::SelectAtId,
};
}

@@ -762,6 +763,7 @@ QgsVectorLayer *QgsPostgresProviderConnection::createSqlVectorLayer( const SqlVe
QgsDataSourceUri tUri( uri( ) );

tUri.setSql( options.filter );
tUri.disableSelectAtId( options.disableSelectAtId );

if ( ! options.primaryKeyColumns.isEmpty() )
{

0 comments on commit aa6c1bd

Please sign in to comment.