Skip to content

Commit 7364406

Browse files
author
Hugo Mercier
authoredJan 18, 2019
Merge pull request #8899 from mhugo/release-3_4
3.4 backports
2 parents d3c04c2 + f99a911 commit 7364406

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed
 

‎src/app/vertextool/qgsvertextool.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -980,15 +980,17 @@ void QgsVertexTool::keyPressEvent( QKeyEvent *e )
980980

981981
QgsGeometry QgsVertexTool::cachedGeometry( const QgsVectorLayer *layer, QgsFeatureId fid )
982982
{
983-
if ( !mCache.contains( layer ) )
983+
const bool layerWasNotInCache = !mCache.contains( layer );
984+
// insert if it was not in cache
985+
QHash<QgsFeatureId, QgsGeometry>& layerCache = mCache[layer];
986+
if ( layerWasNotInCache )
984987
{
985988
connect( layer, &QgsVectorLayer::geometryChanged, this, &QgsVertexTool::onCachedGeometryChanged );
986989
connect( layer, &QgsVectorLayer::featureDeleted, this, &QgsVertexTool::onCachedGeometryDeleted );
987990
connect( layer, &QgsVectorLayer::willBeDeleted, this, &QgsVertexTool::clearGeometryCache );
988991
connect( layer, &QgsVectorLayer::dataChanged, this, &QgsVertexTool::clearGeometryCache );
989992
}
990993

991-
QHash<QgsFeatureId, QgsGeometry> &layerCache = mCache[layer];
992994
if ( !layerCache.contains( fid ) )
993995
{
994996
QgsFeature f;
@@ -1008,6 +1010,10 @@ void QgsVertexTool::clearGeometryCache()
10081010
{
10091011
const QgsVectorLayer *layer = qobject_cast<const QgsVectorLayer *>( sender() );
10101012
mCache.remove( layer );
1013+
disconnect( layer, &QgsVectorLayer::geometryChanged, this, &QgsVertexTool::onCachedGeometryChanged );
1014+
disconnect( layer, &QgsVectorLayer::featureDeleted, this, &QgsVertexTool::onCachedGeometryDeleted );
1015+
disconnect( layer, &QgsVectorLayer::willBeDeleted, this, &QgsVertexTool::clearGeometryCache );
1016+
disconnect( layer, &QgsVectorLayer::dataChanged, this, &QgsVertexTool::clearGeometryCache );
10111017
}
10121018

10131019
void QgsVertexTool::onCachedGeometryChanged( QgsFeatureId fid, const QgsGeometry &geom )

‎src/providers/postgres/qgspostgresconn.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,8 @@ PGresult *QgsPostgresConn::PQexec( const QString &query, bool logError ) const
11041104

11051105
bool QgsPostgresConn::openCursor( const QString &cursorName, const QString &sql )
11061106
{
1107+
QMutexLocker locker( &mLock ); // to protect access to mOpenCursors
1108+
11071109
if ( mOpenCursors++ == 0 && !mTransaction )
11081110
{
11091111
QgsDebugMsgLevel( QStringLiteral( "Starting read-only transaction: %1" ).arg( mPostgresqlVersion ), 4 );
@@ -1119,6 +1121,8 @@ bool QgsPostgresConn::openCursor( const QString &cursorName, const QString &sql
11191121

11201122
bool QgsPostgresConn::closeCursor( const QString &cursorName )
11211123
{
1124+
QMutexLocker locker( &mLock ); // to protect access to mOpenCursors
1125+
11221126
if ( !PQexecNR( QStringLiteral( "CLOSE %1" ).arg( cursorName ) ) )
11231127
return false;
11241128

@@ -1133,6 +1137,7 @@ bool QgsPostgresConn::closeCursor( const QString &cursorName )
11331137

11341138
QString QgsPostgresConn::uniqueCursorName()
11351139
{
1140+
QMutexLocker locker( &mLock ); // to protect access to mNextCursorId
11361141
return QStringLiteral( "qgis_%1" ).arg( ++mNextCursorId );
11371142
}
11381143

0 commit comments

Comments
 (0)
Please sign in to comment.