Skip to content

Commit

Permalink
add postgres layer: enforce selection of primary key for views (refs #…
Browse files Browse the repository at this point in the history
…11317)

(cherry picked from commit a54c2d0)
  • Loading branch information
jef-n committed Jun 30, 2015
1 parent 5bdaf44 commit 7d00947
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/providers/postgres/qgspgtablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );
Expand All @@ -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 );
Expand Down

0 comments on commit 7d00947

Please sign in to comment.