Skip to content
Permalink
Browse files

add postgres layer: enforce selection of primary key for views (refs #…

…11317)

(cherry picked from commit a54c2d0)
  • Loading branch information
jef-n committed Jun 24, 2015
1 parent 5bdaf44 commit 7d0094732b2f1978c1205eb4248b3ead150d1e75
Showing with 8 additions and 7 deletions.
  1. +8 −7 src/providers/postgres/qgspgtablemodel.cpp
@@ -68,6 +68,10 @@ void QgsPgTableModel::addTableEntry( const QgsPostgresLayerProperty& layerProper
{
tip = tr( "Enter a SRID" );
}
else if ( layerProperty.pkCols.size() > 0 )
{
tip = tr( "Select a primary key" );
}

QStandardItem *schemaNameItem = new QStandardItem( layerProperty.schemaName );
QStandardItem *typeItem = new QStandardItem( iconForWkbType( wkbType ), wkbType == QGis::WKBUnknown ? tr( "Select..." ) : QgsPostgresConn::displayStringForWkbType( wkbType ) );
@@ -88,20 +92,17 @@ void QgsPgTableModel::addTableEntry( const QgsPostgresLayerProperty& layerProper
sridItem->setFlags( sridItem->flags() | Qt::ItemIsEditable );
}

QString pkCol = "";
QStandardItem *pkItem = new QStandardItem( "" );
if ( layerProperty.pkCols.size() > 0 )
{
pkCol = layerProperty.pkCols[0];
}

QStandardItem *pkItem = new QStandardItem( pkCol );
if ( layerProperty.pkCols.size() > 1 )
pkItem->setText( tr( "Select..." ) );
pkItem->setFlags( pkItem->flags() | Qt::ItemIsEditable );
}
else
pkItem->setFlags( pkItem->flags() & ~Qt::ItemIsEditable );

pkItem->setData( layerProperty.pkCols, Qt::UserRole + 1 );
pkItem->setData( pkCol, Qt::UserRole + 2 );
pkItem->setData( "", Qt::UserRole + 2 );

QStandardItem *selItem = new QStandardItem( "" );
selItem->setFlags( selItem->flags() | Qt::ItemIsUserCheckable );

0 comments on commit 7d00947

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