Skip to content
Permalink
Browse files

use a pointer otherwise Python is creating a copy

  • Loading branch information
3nids committed Feb 28, 2018
1 parent 0ec7d54 commit 4e2eb0eb9c85c7443c8c82fea4dba5a3768db9a2
@@ -210,6 +210,8 @@ def __exit__(self, ex_type, ex_value, traceback):
self.layer.rollBack()
return False

# Python class to mimic QgsReadWriteContextCategoryPopper C++ class


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


# Inject the context manager into QgsReadWriteContext class as a member
QgsReadWriteContext.enterCategory = ReadWriteContextEnterCategory


@@ -116,7 +116,7 @@ This would happen when it gets out of scope.
#include "qgsreadwritecontext.h"
%End
public:
QgsReadWriteContextCategoryPopper( QgsReadWriteContext &context );
QgsReadWriteContextCategoryPopper( QgsReadWriteContext *context );
%Docstring
Creates a popper
%End
@@ -41,7 +41,7 @@ QgsReadWriteContextCategoryPopper QgsReadWriteContext::enterCategory( const QStr
if ( !details.isEmpty() )
message.append( QString( " :: %1" ).arg( details ) );
mCategories.push_back( message );
return QgsReadWriteContextCategoryPopper( *this );
return QgsReadWriteContextCategoryPopper( this );
}

void QgsReadWriteContext::leaveCategory()
@@ -122,10 +122,14 @@ class CORE_EXPORT QgsReadWriteContextCategoryPopper
{
public:
//! Creates a popper
QgsReadWriteContextCategoryPopper( QgsReadWriteContext &context ) : mContext( context ) {}
~QgsReadWriteContextCategoryPopper() {mContext.leaveCategory();}
QgsReadWriteContextCategoryPopper( QgsReadWriteContext *context ) : mContext( context ) {}
~QgsReadWriteContextCategoryPopper()
{
if ( mContext )
mContext->leaveCategory();
}
private:
QgsReadWriteContext mContext;
QgsReadWriteContext *mContext;
};

#endif // QGSREADWRITECONTEXT_H

0 comments on commit 4e2eb0e

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