Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Initial check pk unicity
  • Loading branch information
elpaso committed Apr 18, 2019
1 parent 1e3b83e commit f3e5867
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/qgsvectorlayer.cpp
Expand Up @@ -1559,7 +1559,7 @@ QString QgsVectorLayer::loadDefaultStyle( bool &resultFlag )

bool QgsVectorLayer::setDataProvider( QString const &provider, const QgsDataProvider::ProviderOptions &options )
{
mProviderKey = provider; // XXX is this necessary? Usually already set
mProviderKey = provider;

// primary key unicity is tested at construction time, so it has to be set
// before initializing postgres provider
Expand Down
9 changes: 9 additions & 0 deletions src/providers/postgres/qgspgtablemodel.cpp
Expand Up @@ -35,6 +35,7 @@ QgsPgTableModel::QgsPgTableModel()
headerLabels << tr( "SRID" );
headerLabels << tr( "Feature id" );
headerLabels << tr( "Select at id" );
headerLabels << tr( "Check pk unicity" );
headerLabels << tr( "Sql" );
setHorizontalHeaderLabels( headerLabels );
}
Expand Down Expand Up @@ -122,6 +123,11 @@ void QgsPgTableModel::addTableEntry( const QgsPostgresLayerProperty &layerProper
selItem->setCheckState( Qt::Checked );
selItem->setToolTip( tr( "Disable 'Fast Access to Features at ID' capability to force keeping the attribute table in memory (e.g. in case of expensive views)." ) );

QStandardItem *checkPkUnicityItem = new QStandardItem( QString() );
checkPkUnicityItem->setFlags( checkPkUnicityItem->flags() | Qt::ItemIsUserCheckable );
checkPkUnicityItem->setCheckState( Qt::Unchecked );
checkPkUnicityItem->setToolTip( tr( "Enable check for primary key unicity when loading the features. This may slow down loading for large tables." ) );

QStandardItem *sqlItem = new QStandardItem( layerProperty.sql );

QList<QStandardItem *> childItemList;
Expand All @@ -135,6 +141,7 @@ void QgsPgTableModel::addTableEntry( const QgsPostgresLayerProperty &layerProper
childItemList << sridItem;
childItemList << pkItem;
childItemList << selItem;
childItemList << checkPkUnicityItem;
childItemList << sqlItem;

Q_FOREACH ( QStandardItem *item, childItemList )
Expand Down Expand Up @@ -374,6 +381,7 @@ QString QgsPgTableModel::layerURI( const QModelIndex &index, const QString &conn

bool selectAtId = itemFromIndex( index.sibling( index.row(), DbtmSelectAtId ) )->checkState() == Qt::Checked;
QString sql = index.sibling( index.row(), DbtmSql ).data( Qt::DisplayRole ).toString();
bool checkPkUnicity = itemFromIndex( index.sibling( index.row(), DbtmCheckPkUnicity ) )->checkState() == Qt::Checked;

QgsDataSourceUri uri( connInfo );

Expand All @@ -390,6 +398,7 @@ QString QgsPgTableModel::layerURI( const QModelIndex &index, const QString &conn
uri.setWkbType( wkbType );
uri.setSrid( srid );
uri.disableSelectAtId( !selectAtId );
uri.setParam( QStringLiteral( "checkPrimaryKeyUnicity" ), QString( checkPkUnicity ) );

QgsDebugMsg( QStringLiteral( "returning uri %1" ).arg( uri.uri( false ) ) );
return uri.uri( false );
Expand Down
1 change: 1 addition & 0 deletions src/providers/postgres/qgspgtablemodel.h
Expand Up @@ -53,6 +53,7 @@ class QgsPgTableModel : public QStandardItemModel
DbtmSrid,
DbtmPkCol,
DbtmSelectAtId,
DbtmCheckPkUnicity,
DbtmSql,
DbtmColumns
};
Expand Down
1 change: 1 addition & 0 deletions src/providers/postgres/qgspostgresconn.h
Expand Up @@ -82,6 +82,7 @@ struct QgsPostgresLayerProperty
bool isView = false;
bool isMaterializedView = false;
QString tableComment;
bool checkPkUnicity = false;


// TODO: rename this !
Expand Down

0 comments on commit f3e5867

Please sign in to comment.