Skip to content

Commit ad544a2

Browse files
committedApr 18, 2019
Initial check pk unicity
1 parent c0c19f0 commit ad544a2

File tree

4 files changed

+12
-1
lines changed

4 files changed

+12
-1
lines changed
 

‎src/core/qgsvectorlayer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1572,7 +1572,7 @@ QString QgsVectorLayer::loadDefaultStyle( bool &resultFlag )
15721572

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

15771577
// primary key unicity is tested at construction time, so it has to be set
15781578
// before initializing postgres provider

‎src/providers/postgres/qgspgtablemodel.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ QgsPgTableModel::QgsPgTableModel()
3535
headerLabels << tr( "SRID" );
3636
headerLabels << tr( "Feature id" );
3737
headerLabels << tr( "Select at id" );
38+
headerLabels << tr( "Check pk unicity" );
3839
headerLabels << tr( "Sql" );
3940
setHorizontalHeaderLabels( headerLabels );
4041
}
@@ -122,6 +123,11 @@ void QgsPgTableModel::addTableEntry( const QgsPostgresLayerProperty &layerProper
122123
selItem->setCheckState( Qt::Checked );
123124
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)." ) );
124125

126+
QStandardItem *checkPkUnicityItem = new QStandardItem( QString() );
127+
checkPkUnicityItem->setFlags( checkPkUnicityItem->flags() | Qt::ItemIsUserCheckable );
128+
checkPkUnicityItem->setCheckState( Qt::Unchecked );
129+
checkPkUnicityItem->setToolTip( tr( "Enable check for primary key unicity when loading the features. This may slow down loading for large tables." ) );
130+
125131
QStandardItem *sqlItem = new QStandardItem( layerProperty.sql );
126132

127133
QList<QStandardItem *> childItemList;
@@ -135,6 +141,7 @@ void QgsPgTableModel::addTableEntry( const QgsPostgresLayerProperty &layerProper
135141
childItemList << sridItem;
136142
childItemList << pkItem;
137143
childItemList << selItem;
144+
childItemList << checkPkUnicityItem;
138145
childItemList << sqlItem;
139146

140147
const auto constChildItemList = childItemList;
@@ -375,6 +382,7 @@ QString QgsPgTableModel::layerURI( const QModelIndex &index, const QString &conn
375382

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

379387
QgsDataSourceUri uri( connInfo );
380388

@@ -392,6 +400,7 @@ QString QgsPgTableModel::layerURI( const QModelIndex &index, const QString &conn
392400
uri.setWkbType( wkbType );
393401
uri.setSrid( srid );
394402
uri.disableSelectAtId( !selectAtId );
403+
uri.setParam( QStringLiteral( "checkPrimaryKeyUnicity" ), QString( checkPkUnicity ) );
395404

396405
QgsDebugMsg( QStringLiteral( "returning uri %1" ).arg( uri.uri( false ) ) );
397406
return uri.uri( false );

‎src/providers/postgres/qgspgtablemodel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class QgsPgTableModel : public QStandardItemModel
5353
DbtmSrid,
5454
DbtmPkCol,
5555
DbtmSelectAtId,
56+
DbtmCheckPkUnicity,
5657
DbtmSql,
5758
DbtmColumns
5859
};

‎src/providers/postgres/qgspostgresconn.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ struct QgsPostgresLayerProperty
8282
bool isView = false;
8383
bool isMaterializedView = false;
8484
QString tableComment;
85+
bool checkPkUnicity = false;
8586

8687

8788
// TODO: rename this !

0 commit comments

Comments
 (0)
Please sign in to comment.