Skip to content

Commit

Permalink
use a pointer otherwise Python is creating a copy
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Feb 28, 2018
1 parent 0ec7d54 commit 4e2eb0e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
3 changes: 3 additions & 0 deletions python/core/__init__.py
Expand Up @@ -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):
Expand All @@ -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


Expand Down
2 changes: 1 addition & 1 deletion python/core/qgsreadwritecontext.sip.in
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsreadwritecontext.cpp
Expand Up @@ -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()
Expand Down
10 changes: 7 additions & 3 deletions src/core/qgsreadwritecontext.h
Expand Up @@ -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.