Skip to content

Commit 4e2eb0e

Browse files
committedFeb 28, 2018
use a pointer otherwise Python is creating a copy
1 parent 0ec7d54 commit 4e2eb0e

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed
 

‎python/core/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ def __exit__(self, ex_type, ex_value, traceback):
210210
self.layer.rollBack()
211211
return False
212212

213+
# Python class to mimic QgsReadWriteContextCategoryPopper C++ class
214+
213215

214216
class ReadWriteContextEnterCategory():
215217
def __init__(self, context, category_name, details=None):
@@ -227,6 +229,7 @@ def __exit__(self, ex_type, ex_value, traceback):
227229
return True
228230

229231

232+
# Inject the context manager into QgsReadWriteContext class as a member
230233
QgsReadWriteContext.enterCategory = ReadWriteContextEnterCategory
231234

232235

‎python/core/qgsreadwritecontext.sip.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ This would happen when it gets out of scope.
116116
#include "qgsreadwritecontext.h"
117117
%End
118118
public:
119-
QgsReadWriteContextCategoryPopper( QgsReadWriteContext &context );
119+
QgsReadWriteContextCategoryPopper( QgsReadWriteContext *context );
120120
%Docstring
121121
Creates a popper
122122
%End

‎src/core/qgsreadwritecontext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ QgsReadWriteContextCategoryPopper QgsReadWriteContext::enterCategory( const QStr
4141
if ( !details.isEmpty() )
4242
message.append( QString( " :: %1" ).arg( details ) );
4343
mCategories.push_back( message );
44-
return QgsReadWriteContextCategoryPopper( *this );
44+
return QgsReadWriteContextCategoryPopper( this );
4545
}
4646

4747
void QgsReadWriteContext::leaveCategory()

‎src/core/qgsreadwritecontext.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,14 @@ class CORE_EXPORT QgsReadWriteContextCategoryPopper
122122
{
123123
public:
124124
//! Creates a popper
125-
QgsReadWriteContextCategoryPopper( QgsReadWriteContext &context ) : mContext( context ) {}
126-
~QgsReadWriteContextCategoryPopper() {mContext.leaveCategory();}
125+
QgsReadWriteContextCategoryPopper( QgsReadWriteContext *context ) : mContext( context ) {}
126+
~QgsReadWriteContextCategoryPopper()
127+
{
128+
if ( mContext )
129+
mContext->leaveCategory();
130+
}
127131
private:
128-
QgsReadWriteContext mContext;
132+
QgsReadWriteContext *mContext;
129133
};
130134

131135
#endif // QGSREADWRITECONTEXT_H

0 commit comments

Comments
 (0)
Please sign in to comment.