Skip to content
Permalink
Browse files

Initial check pk unicity

  • Loading branch information
elpaso committed Apr 18, 2019
1 parent c0c19f0 commit ad544a29ba86dc8e9b98a85b217a6cfc83e17c37
@@ -1572,7 +1572,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
@@ -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 );
}
@@ -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;
@@ -135,6 +141,7 @@ void QgsPgTableModel::addTableEntry( const QgsPostgresLayerProperty &layerProper
childItemList << sridItem;
childItemList << pkItem;
childItemList << selItem;
childItemList << checkPkUnicityItem;
childItemList << sqlItem;

const auto constChildItemList = childItemList;
@@ -375,6 +382,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 );

@@ -392,6 +400,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 );
@@ -53,6 +53,7 @@ class QgsPgTableModel : public QStandardItemModel
DbtmSrid,
DbtmPkCol,
DbtmSelectAtId,
DbtmCheckPkUnicity,
DbtmSql,
DbtmColumns
};
@@ -82,6 +82,7 @@ struct QgsPostgresLayerProperty
bool isView = false;
bool isMaterializedView = false;
QString tableComment;
bool checkPkUnicity = false;


// TODO: rename this !

0 comments on commit ad544a2

Please sign in to comment.
You can’t perform that action at this time.