use a pointer otherwise Python is creating a copy

This commit is contained in:
Denis Rouzaud 2018-02-28 13:42:54 -04:00
parent 0ec7d54c9c
commit 4e2eb0eb9c
4 changed files with 12 additions and 5 deletions

View File

@ -210,6 +210,8 @@ class edit(object):
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 @@ class ReadWriteContextEnterCategory():
return True
# Inject the context manager into QgsReadWriteContext class as a member
QgsReadWriteContext.enterCategory = ReadWriteContextEnterCategory

View File

@ -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

View File

@ -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()

View File

@ -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