Skip to content
Permalink
Browse files

postgres provider:

- pre-select first integer column as primary key for views
- also consider oid type as integer column
  • Loading branch information
jef-n committed Feb 8, 2012
1 parent d181e26 commit d2b5ed92040448f9d4b22963e5869f4efdd2d9e9
Showing with 15 additions and 12 deletions.
  1. +11 −7 src/providers/postgres/qgspgtablemodel.cpp
  2. +4 −5 src/providers/postgres/qgspostgresprovider.cpp
@@ -91,16 +91,20 @@ void QgsPgTableModel::addTableEntry( QgsPostgresLayerProperty layerProperty )
sridItem->setEditable( false );

QString pkText, pkCol = "";
switch ( layerProperty.pkCols.size() )
if ( layerProperty.pkCols.size() == 0 )
{
case 0: pkText = ""; break;
case 1: pkText = layerProperty.pkCols[0]; pkCol = pkText; break;
default: pkText = tr( "Select..." ); break;
pkText = "";
}
else
{
pkCol = pkText = layerProperty.pkCols[0];
}

QStandardItem *pkItem = new QStandardItem( pkText );
if ( pkText == tr( "Select..." ) )
if ( layerProperty.pkCols.size() > 1 )
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 );
@@ -313,11 +317,11 @@ bool QgsPgTableModel::setData( const QModelIndex &idx, const QVariant &value, in

bool ok = geomType != QGis::UnknownGeometry;

if ( geomType != QGis::NoGeometry )
if ( ok && geomType != QGis::NoGeometry )
idx.sibling( idx.row(), dbtmSrid ).data().toInt( &ok );

QStringList pkCols = idx.sibling( idx.row(), dbtmPkCol ).data( Qt::UserRole + 1 ).toStringList();
if ( pkCols.size() > 0 )
if ( ok && pkCols.size() > 0 )
ok = pkCols.contains( idx.sibling( idx.row(), dbtmPkCol ).data().toString() );

for ( int i = 0; i < dbtmColumns; i++ )
@@ -1056,16 +1056,15 @@ bool QgsPostgresProvider::loadFields()
fieldSize = -1;
fieldPrec = 0;
}
else if ( fieldTypeName.startsWith( "int" ) ||
fieldTypeName == "serial" )
else if ( fieldTypeName == "int2" || fieldTypeName == "int4" ||
fieldTypeName == "oid" || fieldTypeName == "serial" )
{
fieldType = QVariant::Int;
fieldSize = -1;
fieldPrec = 0;
}
else if ( fieldTypeName == "real" ||
fieldTypeName == "double precision" ||
fieldTypeName.startsWith( "float" ) )
else if ( fieldTypeName == "real" || fieldTypeName == "double precision" ||
fieldTypeName == "float4" || fieldTypeName == "float8" )
{
fieldType = QVariant::Double;
fieldSize = -1;

0 comments on commit d2b5ed9

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