Showing with 36 additions and 7 deletions.
  1. +12 −0 src/gui/qgsmapcanvas.cpp
  2. +4 −0 src/gui/qgsmapcanvas.h
  3. +20 −7 src/providers/postgres/qgspostgresprovider.cpp
12 changes: 12 additions & 0 deletions src/gui/qgsmapcanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,10 @@ void QgsMapCanvas::setMapTool( QgsMapTool* tool )
return;

if ( mMapTool )
{
disconnect( mMapTool, SIGNAL( destroyed() ), this, SLOT( mapToolDestroyed() ) );
mMapTool->deactivate();
}

if ( tool->isTransient() && mMapTool && !mMapTool->isTransient() )
{
Expand All @@ -1187,7 +1190,10 @@ void QgsMapCanvas::setMapTool( QgsMapTool* tool )
// set new map tool and activate it
mMapTool = tool;
if ( mMapTool )
{
connect( mMapTool, SIGNAL( destroyed() ), this, SLOT( mapToolDestroyed() ) );
mMapTool->activate();
}

emit mapToolSet( mMapTool );
} // setMapTool
Expand Down Expand Up @@ -1548,3 +1554,9 @@ void QgsMapCanvas::crsTransformEnabled( bool enabled )
else
disconnect( mMapRenderer, SIGNAL( destinationSrsChanged() ), this, SLOT( refresh() ) );
}

void QgsMapCanvas::mapToolDestroyed()
{
QgsDebugMsg( "maptool destroyed" );
mMapTool = 0;
}
4 changes: 4 additions & 0 deletions src/gui/qgsmapcanvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,10 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
//! called to write map canvas settings to project
void writeProject( QDomDocument & );

private slots:
//! called when current maptool is destroyed
void mapToolDestroyed();

signals:
/** Let the owner know how far we are with render operations */
void setProgress( int, int );
Expand Down
27 changes: 20 additions & 7 deletions src/providers/postgres/qgspostgresprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1096,9 +1096,22 @@ bool QgsPostgresProvider::loadFields()
}
}
}
else if ( fieldTypeName == "varchar" )
{
fieldType = QVariant::String;

QRegExp re( "character varying\\((\\d+)\\)" );
if ( re.exactMatch( formattedFieldType ) )
{
fieldSize = re.cap( 1 ).toInt();
}
else
{
fieldSize = -1;
}
}
else if ( fieldTypeName == "text" ||
fieldTypeName == "bpchar" ||
fieldTypeName == "varchar" ||
fieldTypeName == "bool" ||
fieldTypeName == "geometry" ||
fieldTypeName == "money" ||
Expand Down Expand Up @@ -1449,20 +1462,20 @@ bool QgsPostgresProvider::determinePrimaryKey()
{
QString name = res.PQgetvalue( i, 0 );

int j;
for ( j = 0; j < mAttributeFields.size() && mAttributeFields[j].name() != name; j++ )
;
int idx = mAttributeFields.key( name, -1 );

if ( j == mAttributeFields.size() )
if ( idx < 0 )
{
QgsDebugMsg( "Skipping " + name );
continue;
}

if ( isInt && mAttributeFields[j].type() != QVariant::Int && mAttributeFields[j].type() != QVariant::LongLong )
if ( isInt &&
mAttributeFields[idx].type() != QVariant::Int &&
mAttributeFields[idx].type() != QVariant::LongLong )
isInt = false;

mPrimaryKeyAttrs << j;
mPrimaryKeyAttrs << idx;
}

mPrimaryKeyType = ( mPrimaryKeyAttrs.size() == 1 && isInt ) ? pktInt : pktFidMap;
Expand Down