QGIS API Documentation 3.36.0-Maidenhead (09951dc0acf)
Loading...
Searching...
No Matches
qgsreadwritecontext.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsreadwritecontext.h
3 ----------------------
4 begin : May 2017
5 copyright : (C) 2017 by Martin Dobias
6 email : wonder dot sk at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#ifndef QGSREADWRITECONTEXT_H
19#define QGSREADWRITECONTEXT_H
20
21#include "qgspathresolver.h"
22#include "qgis.h"
25
27
33class CORE_EXPORT QgsReadWriteContext
34{
35 public:
36
42 {
44 ReadWriteMessage( const QString &message = QString(), Qgis::MessageLevel level = Qgis::MessageLevel::Warning, const QStringList &categories = QStringList() )
45 : mMessage( message )
46 , mLevel( level )
47 , mCategories( categories )
48 {}
49
51 QString message() const {return mMessage;}
52
54 Qgis::MessageLevel level() const {return mLevel;}
55
57 QStringList categories() const {return mCategories;}
58
59 // TODO c++20 - replace with = default
60
62 {
63 return mMessage == other.mMessage && mLevel == other.mLevel && mCategories == other.mCategories;
64 }
65
67 {
68 return !( *this == other );
69 }
70
71#ifdef SIP_RUN
72 SIP_PYOBJECT __repr__();
73 % MethodCode
74 QString str = QStringLiteral( "<QgsReadWriteContext.ReadWriteMessage: %1>" ).arg( sipCpp->message() );
75 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
76 % End
77#endif
78
79 private:
80 QString mMessage;
81 Qgis::MessageLevel mLevel;
82 QStringList mCategories;
83 };
84
89
91
93 const QgsPathResolver &pathResolver() const;
94
96 void setPathResolver( const QgsPathResolver &resolver );
97
102 void pushMessage( const QString &message, Qgis::MessageLevel level = Qgis::MessageLevel::Warning ) const;
103
115 MAYBE_UNUSED NODISCARD QgsReadWriteContextCategoryPopper enterCategory( const QString &category, const QString &details = QString() ) const SIP_PYNAME( _enterCategory );
116
121 QList<QgsReadWriteContext::ReadWriteMessage> takeMessages();
122
127 const QgsProjectTranslator *projectTranslator( ) const { return mProjectTranslator; }
128
135 void setProjectTranslator( QgsProjectTranslator *projectTranslator );
136
144 QgsCoordinateTransformContext transformContext() const;
145
153 void setTransformContext( const QgsCoordinateTransformContext &transformContext );
154
155 private:
156
158 void leaveCategory() const;
159
160 QgsPathResolver mPathResolver;
161 mutable QList<ReadWriteMessage> mMessages;
162 mutable QStringList mCategories = QStringList();
163 QgsProjectTranslator *mProjectTranslator = nullptr;
165 QgsCoordinateTransformContext mCoordinateTransformContext = QgsCoordinateTransformContext();
166};
167
168
178{
179 public:
181 QgsReadWriteContextCategoryPopper( const QgsReadWriteContext &context ) : mContext( context ) {}
182 ~QgsReadWriteContextCategoryPopper() {mContext.leaveCategory();}
183 private:
184#ifdef SIP_RUN
186#endif
187
188 const QgsReadWriteContext &mContext;
189};
190
191#endif // QGSREADWRITECONTEXT_H
MessageLevel
Level for messages This will be used both for message log and message bar in application.
Definition qgis.h:99
@ Warning
Warning message.
Definition qgis.h:101
Contains information about the context in which a coordinate transform is executed.
Resolves relative paths into absolute paths and vice versa.
Wherever an object of this class is available, the derived translate function can be called from.
Allows entering a context category and takes care of leaving this category on deletion of the class.
QgsReadWriteContextCategoryPopper(const QgsReadWriteContext &context)
Creates a popper.
The class is used as a container of context for various read/write operations on other objects.
#define str(x)
Definition qgis.cpp:38
#define MAYBE_UNUSED
Definition qgis.h:5765
#define NODISCARD
Definition qgis.h:5749
#define SIP_PYNAME(name)
Definition qgis_sip.h:81
Struct for QgsReadWriteContext error or warning messages.
Qgis::MessageLevel level() const
Returns the message level.
ReadWriteMessage(const QString &message=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, const QStringList &categories=QStringList())
Construct a container for QgsReadWriteContext error or warning messages.
QString message() const
Returns the message string.
bool operator!=(const QgsReadWriteContext::ReadWriteMessage &other) const
bool operator==(const QgsReadWriteContext::ReadWriteMessage &other) const
QStringList categories() const
Returns the stack of categories of the message.