Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Mark QgsReadWriteContext::pushMessage as const, mutable
Avoids the need to remove const from all the QgsReadWriteContext
references used throughout QGIS XML loading just to be able to
push warning messages to the context.
  • Loading branch information
nyalldawson committed May 24, 2021
1 parent 2bed84d commit b086e6e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions python/core/auto_generated/qgsreadwritecontext.sip.in
Expand Up @@ -64,14 +64,14 @@ Returns path resolver for conversion between relative and absolute paths
Sets up path resolver for conversion between relative and absolute paths
%End

void pushMessage( const QString &message, Qgis::MessageLevel level = Qgis::Warning );
void pushMessage( const QString &message, Qgis::MessageLevel level = Qgis::Warning ) const;
%Docstring
Append a message to the context

.. versionadded:: 3.2
%End

QgsReadWriteContextCategoryPopper enterCategory( const QString &category, const QString &details = QString() ) /PyName=_enterCategory/;
QgsReadWriteContextCategoryPopper enterCategory( const QString &category, const QString &details = QString() ) const /PyName=_enterCategory/;
%Docstring
Push a category to the stack

Expand Down Expand Up @@ -148,7 +148,7 @@ This would happen when it gets out of scope.
#include "qgsreadwritecontext.h"
%End
public:
QgsReadWriteContextCategoryPopper( QgsReadWriteContext &context );
QgsReadWriteContextCategoryPopper( const QgsReadWriteContext &context );
%Docstring
Creates a popper
%End
Expand Down
6 changes: 3 additions & 3 deletions src/core/qgsreadwritecontext.cpp
Expand Up @@ -54,12 +54,12 @@ void QgsReadWriteContext::setPathResolver( const QgsPathResolver &resolver )
mPathResolver = resolver;
}

void QgsReadWriteContext::pushMessage( const QString &message, Qgis::MessageLevel level )
void QgsReadWriteContext::pushMessage( const QString &message, Qgis::MessageLevel level ) const
{
mMessages.append( ReadWriteMessage( message, level, mCategories ) );
}

QgsReadWriteContextCategoryPopper QgsReadWriteContext::enterCategory( const QString &category, const QString &details )
QgsReadWriteContextCategoryPopper QgsReadWriteContext::enterCategory( const QString &category, const QString &details ) const
{
QString message = category;
if ( !details.isEmpty() )
Expand All @@ -68,7 +68,7 @@ QgsReadWriteContextCategoryPopper QgsReadWriteContext::enterCategory( const QStr
return QgsReadWriteContextCategoryPopper( *this );
}

void QgsReadWriteContext::leaveCategory()
void QgsReadWriteContext::leaveCategory() const
{
if ( !mCategories.isEmpty() )
mCategories.pop_back();
Expand Down
14 changes: 7 additions & 7 deletions src/core/qgsreadwritecontext.h
Expand Up @@ -80,7 +80,7 @@ class CORE_EXPORT QgsReadWriteContext
* Append a message to the context
* \since QGIS 3.2
*/
void pushMessage( const QString &message, Qgis::MessageLevel level = Qgis::Warning );
void pushMessage( const QString &message, Qgis::MessageLevel level = Qgis::Warning ) const;

/**
* Push a category to the stack
Expand All @@ -93,7 +93,7 @@ class CORE_EXPORT QgsReadWriteContext
* \endcode
* \since QGIS 3.2
*/
MAYBE_UNUSED NODISCARD QgsReadWriteContextCategoryPopper enterCategory( const QString &category, const QString &details = QString() ) SIP_PYNAME( _enterCategory );
MAYBE_UNUSED NODISCARD QgsReadWriteContextCategoryPopper enterCategory( const QString &category, const QString &details = QString() ) const SIP_PYNAME( _enterCategory );

/**
* Returns the stored messages and remove them
Expand Down Expand Up @@ -136,11 +136,11 @@ class CORE_EXPORT QgsReadWriteContext
private:

//! Pop the last category
void leaveCategory();
void leaveCategory() const;

QgsPathResolver mPathResolver;
QList<ReadWriteMessage> mMessages;
QStringList mCategories = QStringList();
mutable QList<ReadWriteMessage> mMessages;
mutable QStringList mCategories = QStringList();
QgsProjectTranslator *mProjectTranslator = nullptr;
friend class QgsReadWriteContextCategoryPopper;
QgsCoordinateTransformContext mCoordinateTransformContext = QgsCoordinateTransformContext();
Expand All @@ -159,14 +159,14 @@ class CORE_EXPORT QgsReadWriteContextCategoryPopper
{
public:
//! Creates a popper
QgsReadWriteContextCategoryPopper( QgsReadWriteContext &context ) : mContext( context ) {}
QgsReadWriteContextCategoryPopper( const QgsReadWriteContext &context ) : mContext( context ) {}
~QgsReadWriteContextCategoryPopper() {mContext.leaveCategory();}
private:
#ifdef SIP_RUN
QgsReadWriteContextCategoryPopper &operator=( const QgsReadWriteContextCategoryPopper & );
#endif

QgsReadWriteContext &mContext;
const QgsReadWriteContext &mContext;
};

#endif // QGSREADWRITECONTEXT_H

0 comments on commit b086e6e

Please sign in to comment.