QGIS API Documentation  3.19.0-Master (e8efe81642)
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"
23 #include "qgsprojecttranslator.h"
25 
27 
34 class CORE_EXPORT QgsReadWriteContext
35 {
36  public:
37 
43  {
45  ReadWriteMessage( const QString &message = QString(), Qgis::MessageLevel level = Qgis::MessageLevel::Warning, const QStringList &categories = QStringList() )
46  : mMessage( message )
47  , mLevel( level )
48  , mCategories( categories )
49  {}
50 
52  QString message() const {return mMessage;}
53 
55  Qgis::MessageLevel level() const {return mLevel;}
56 
58  QStringList categories() const {return mCategories;}
59 
61  {
62  return mMessage == other.mMessage && mLevel == other.mLevel && mCategories == other.mCategories;
63  }
64 
66  {
67  return !( *this == other );
68  }
69 
70 #ifdef SIP_RUN
71  SIP_PYOBJECT __repr__();
72  % MethodCode
73  QString str = QStringLiteral( "<QgsReadWriteContext.ReadWriteMessage: %1>" ).arg( sipCpp->message() );
74  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
75  % End
76 #endif
77 
78  private:
79  QString mMessage;
80  Qgis::MessageLevel mLevel;
81  QStringList mCategories;
82  };
83 
88 
90 
92  const QgsPathResolver &pathResolver() const;
93 
95  void setPathResolver( const QgsPathResolver &resolver );
96 
101  void pushMessage( const QString &message, Qgis::MessageLevel level = Qgis::MessageLevel::Warning ) const;
102 
114  MAYBE_UNUSED NODISCARD QgsReadWriteContextCategoryPopper enterCategory( const QString &category, const QString &details = QString() ) const SIP_PYNAME( _enterCategory );
115 
120  QList<QgsReadWriteContext::ReadWriteMessage> takeMessages();
121 
126  const QgsProjectTranslator *projectTranslator( ) const { return mProjectTranslator; }
127 
134  void setProjectTranslator( QgsProjectTranslator *projectTranslator );
135 
143  QgsCoordinateTransformContext transformContext() const;
144 
152  void setTransformContext( const QgsCoordinateTransformContext &transformContext );
153 
154  private:
155 
157  void leaveCategory() const;
158 
159  QgsPathResolver mPathResolver;
160  mutable QList<ReadWriteMessage> mMessages;
161  mutable QStringList mCategories = QStringList();
162  QgsProjectTranslator *mProjectTranslator = nullptr;
164  QgsCoordinateTransformContext mCoordinateTransformContext = QgsCoordinateTransformContext();
165 };
166 
167 
177 {
178  public:
180  QgsReadWriteContextCategoryPopper( const QgsReadWriteContext &context ) : mContext( context ) {}
181  ~QgsReadWriteContextCategoryPopper() {mContext.leaveCategory();}
182  private:
183 #ifdef SIP_RUN
185 #endif
186 
187  const QgsReadWriteContext &mContext;
188 };
189 
190 #endif // QGSREADWRITECONTEXT_H
MessageLevel
Level for messages This will be used both for message log and message bar in application.
Definition: qgis.h:105
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:37
#define MAYBE_UNUSED
Definition: qgis.h:1146
#define NODISCARD
Definition: qgis.h:1130
#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.