QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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 "qgis.h"
23#include "qgspathresolver.h"
25
26#include <QString>
27
28using namespace Qt::StringLiterals;
29
31
37class CORE_EXPORT QgsReadWriteContext
38{
39 public:
45 {
47 ReadWriteMessage( const QString &message = QString(), Qgis::MessageLevel level = Qgis::MessageLevel::Warning, const QStringList &categories = QStringList() )
48 : mMessage( message )
49 , mLevel( level )
50 , mCategories( categories )
51 {}
52
54 QString message() const { return mMessage; }
55
57 Qgis::MessageLevel level() const { return mLevel; }
58
60 QStringList categories() const { return mCategories; }
61
62 // TODO c++20 - replace with = default
63
64 bool operator==( const QgsReadWriteContext::ReadWriteMessage &other ) const { return mMessage == other.mMessage && mLevel == other.mLevel && mCategories == other.mCategories; }
65
66 bool operator!=( const QgsReadWriteContext::ReadWriteMessage &other ) const { return !( *this == other ); }
67
68#ifdef SIP_RUN
69 // clang-format off
70 SIP_PYOBJECT __repr__();
71 % MethodCode
72 QString str = u"<QgsReadWriteContext.ReadWriteMessage: %1>"_s.arg( sipCpp->message() );
73 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
74 % End
75// clang-format on
76#endif
77
78 // clang-format off
79 private:
80 // clang-format on
81 QString mMessage;
82 Qgis::MessageLevel mLevel;
83 QStringList mCategories;
84 };
85
90
92
94 const QgsPathResolver &pathResolver() const;
95
97 void setPathResolver( const QgsPathResolver &resolver );
98
103 void pushMessage( const QString &message, Qgis::MessageLevel level = Qgis::MessageLevel::Warning ) const;
104
116 [[maybe_unused]] [[nodiscard]] QgsReadWriteContextCategoryPopper enterCategory( const QString &category, const QString &details = QString() ) const SIP_PYNAME( _enterCategory );
117
118
123 QList<QgsReadWriteContext::ReadWriteMessage> takeMessages();
124
129 const QgsProjectTranslator *projectTranslator() const { return mProjectTranslator; }
130
137 void setProjectTranslator( QgsProjectTranslator *projectTranslator );
138
146 QgsCoordinateTransformContext transformContext() const;
147
155 void setTransformContext( const QgsCoordinateTransformContext &transformContext );
156
161 const QString currentLayerId() const { return mCurrentLayerId; }
162
169 void setCurrentLayerId( const QString &layerId ) { mCurrentLayerId = layerId; }
170
171 private:
173 void leaveCategory() const;
174
175 QgsPathResolver mPathResolver;
176 mutable QList<ReadWriteMessage> mMessages;
177 mutable QStringList mCategories = QStringList();
178 QgsProjectTranslator *mProjectTranslator = nullptr;
180 QgsCoordinateTransformContext mCoordinateTransformContext = QgsCoordinateTransformContext();
181 QString mCurrentLayerId;
182};
183
184
195{
196 public:
199 : mContext( context )
200 {}
201 ~QgsReadWriteContextCategoryPopper() { mContext.leaveCategory(); }
202
203 private:
204#ifdef SIP_RUN
206#endif
207
208 const QgsReadWriteContext &mContext;
209};
210
211#endif // QGSREADWRITECONTEXT_H
MessageLevel
Level for messages This will be used both for message log and message bar in application.
Definition qgis.h:160
@ Warning
Warning message.
Definition qgis.h:162
Contains information about the context in which a coordinate transform is executed.
Resolves relative paths into absolute paths and vice versa.
An interface for objects which can translate project strings.
Allows entering a context category and takes care of leaving this category on deletion of the class.
QgsReadWriteContextCategoryPopper(const QgsReadWriteContext &context)
Creates a popper.
A container for the context for various read/write operations on objects.
const QgsProjectTranslator * projectTranslator() const
Returns the project translator.
void setCurrentLayerId(const QString &layerId)
Sets the current layer id.
QgsReadWriteContext()
Constructor for QgsReadWriteContext.
const QString currentLayerId() const
Returns the currently used layer id as string.
friend class QgsReadWriteContextCategoryPopper
#define SIP_PYNAME(name)
Definition qgis_sip.h:88
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.