99
1010
1111
12+
1213class QgsReadWriteContext
1314{
1415%Docstring
@@ -22,11 +23,37 @@ The class is used as a container of context for various read/write operations on
2223%End
2324 public:
2425
26+ struct ReadWriteMessage
27+ {
28+ ReadWriteMessage( const QString &message, Qgis::MessageLevel level = Qgis::Warning, const QStringList &categories = QStringList() );
29+ %Docstring
30+ Construct a container for QgsReadWriteContext error or warning messages
31+ %End
32+
33+ QString message() const;
34+ %Docstring
35+ Return the message string
36+ %End
37+
38+ Qgis::MessageLevel level() const;
39+ %Docstring
40+ Return the message level
41+ %End
42+
43+ QStringList categories() const;
44+ %Docstring
45+ Return the stack of categories of the message
46+ %End
47+
48+ };
49+
2550 QgsReadWriteContext();
2651%Docstring
2752Constructor for QgsReadWriteContext.
2853%End
2954
55+ ~QgsReadWriteContext();
56+
3057 const QgsPathResolver &pathResolver() const;
3158%Docstring
3259Returns path resolver for conversion between relative and absolute paths
@@ -37,6 +64,63 @@ Returns path resolver for conversion between relative and absolute paths
3764Sets up path resolver for conversion between relative and absolute paths
3865%End
3966
67+ void pushMessage( const QString &message, Qgis::MessageLevel level = Qgis::Warning );
68+ %Docstring
69+ Append a message to the context
70+
71+ .. versionadded:: 3.2
72+ %End
73+
74+ QgsReadWriteContextCategoryPopper enterCategory( const QString &category, const QString &details = QString() ) /PyName=_enterCategory/;
75+ %Docstring
76+ Push a category to the stack
77+
78+ .. note::
79+
80+ The return value should always be used so category can be automatically left.
81+
82+ .. note::
83+
84+ It is not aimed at being used in Python. Instead use the context manager.
85+ .. code-block:: python
86+
87+ context = QgsReadWriteContext()
88+ with QgsReadWriteContext.enterCategory(context, category, details):
89+ # do something
90+
91+ .. versionadded:: 3.2
92+ %End
93+
94+ QList<QgsReadWriteContext::ReadWriteMessage> takeMessages();
95+ %Docstring
96+ Return the stored messages and remove them
97+
98+ .. versionadded:: 3.2
99+ %End
100+
101+
102+ };
103+
104+
105+ class QgsReadWriteContextCategoryPopper
106+ {
107+ %Docstring
108+ QgsReadWriteContextCategoryPopper allows entering a context category
109+ and takes care of leaving this category on deletion of the class.
110+ This would happen when it gets out of scope.
111+
112+ .. versionadded:: 3.2
113+ %End
114+
115+ %TypeHeaderCode
116+ #include "qgsreadwritecontext.h"
117+ %End
118+ public:
119+ QgsReadWriteContextCategoryPopper( QgsReadWriteContext *context );
120+ %Docstring
121+ Creates a popper
122+ %End
123+ ~QgsReadWriteContextCategoryPopper();
40124};
41125
42126/************************************************************************
0 commit comments