Skip to content

Commit b086e6e

Browse files
committedMay 24, 2021
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.
1 parent 2bed84d commit b086e6e

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed
 

‎python/core/auto_generated/qgsreadwritecontext.sip.in

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,14 @@ Returns path resolver for conversion between relative and absolute paths
6464
Sets up path resolver for conversion between relative and absolute paths
6565
%End
6666

67-
void pushMessage( const QString &message, Qgis::MessageLevel level = Qgis::Warning );
67+
void pushMessage( const QString &message, Qgis::MessageLevel level = Qgis::Warning ) const;
6868
%Docstring
6969
Append a message to the context
7070

7171
.. versionadded:: 3.2
7272
%End
7373

74-
QgsReadWriteContextCategoryPopper enterCategory( const QString &category, const QString &details = QString() ) /PyName=_enterCategory/;
74+
QgsReadWriteContextCategoryPopper enterCategory( const QString &category, const QString &details = QString() ) const /PyName=_enterCategory/;
7575
%Docstring
7676
Push a category to the stack
7777

@@ -148,7 +148,7 @@ This would happen when it gets out of scope.
148148
#include "qgsreadwritecontext.h"
149149
%End
150150
public:
151-
QgsReadWriteContextCategoryPopper( QgsReadWriteContext &context );
151+
QgsReadWriteContextCategoryPopper( const QgsReadWriteContext &context );
152152
%Docstring
153153
Creates a popper
154154
%End

‎src/core/qgsreadwritecontext.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ void QgsReadWriteContext::setPathResolver( const QgsPathResolver &resolver )
5454
mPathResolver = resolver;
5555
}
5656

57-
void QgsReadWriteContext::pushMessage( const QString &message, Qgis::MessageLevel level )
57+
void QgsReadWriteContext::pushMessage( const QString &message, Qgis::MessageLevel level ) const
5858
{
5959
mMessages.append( ReadWriteMessage( message, level, mCategories ) );
6060
}
6161

62-
QgsReadWriteContextCategoryPopper QgsReadWriteContext::enterCategory( const QString &category, const QString &details )
62+
QgsReadWriteContextCategoryPopper QgsReadWriteContext::enterCategory( const QString &category, const QString &details ) const
6363
{
6464
QString message = category;
6565
if ( !details.isEmpty() )
@@ -68,7 +68,7 @@ QgsReadWriteContextCategoryPopper QgsReadWriteContext::enterCategory( const QStr
6868
return QgsReadWriteContextCategoryPopper( *this );
6969
}
7070

71-
void QgsReadWriteContext::leaveCategory()
71+
void QgsReadWriteContext::leaveCategory() const
7272
{
7373
if ( !mCategories.isEmpty() )
7474
mCategories.pop_back();

‎src/core/qgsreadwritecontext.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class CORE_EXPORT QgsReadWriteContext
8080
* Append a message to the context
8181
* \since QGIS 3.2
8282
*/
83-
void pushMessage( const QString &message, Qgis::MessageLevel level = Qgis::Warning );
83+
void pushMessage( const QString &message, Qgis::MessageLevel level = Qgis::Warning ) const;
8484

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

9898
/**
9999
* Returns the stored messages and remove them
@@ -136,11 +136,11 @@ class CORE_EXPORT QgsReadWriteContext
136136
private:
137137

138138
//! Pop the last category
139-
void leaveCategory();
139+
void leaveCategory() const;
140140

141141
QgsPathResolver mPathResolver;
142-
QList<ReadWriteMessage> mMessages;
143-
QStringList mCategories = QStringList();
142+
mutable QList<ReadWriteMessage> mMessages;
143+
mutable QStringList mCategories = QStringList();
144144
QgsProjectTranslator *mProjectTranslator = nullptr;
145145
friend class QgsReadWriteContextCategoryPopper;
146146
QgsCoordinateTransformContext mCoordinateTransformContext = QgsCoordinateTransformContext();
@@ -159,14 +159,14 @@ class CORE_EXPORT QgsReadWriteContextCategoryPopper
159159
{
160160
public:
161161
//! Creates a popper
162-
QgsReadWriteContextCategoryPopper( QgsReadWriteContext &context ) : mContext( context ) {}
162+
QgsReadWriteContextCategoryPopper( const QgsReadWriteContext &context ) : mContext( context ) {}
163163
~QgsReadWriteContextCategoryPopper() {mContext.leaveCategory();}
164164
private:
165165
#ifdef SIP_RUN
166166
QgsReadWriteContextCategoryPopper &operator=( const QgsReadWriteContextCategoryPopper & );
167167
#endif
168168

169-
QgsReadWriteContext &mContext;
169+
const QgsReadWriteContext &mContext;
170170
};
171171

172172
#endif // QGSREADWRITECONTEXT_H

0 commit comments

Comments
 (0)
Please sign in to comment.