QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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, Qgis::MessageLevel level = Qgis::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 
60  private:
61  QString mMessage;
62  Qgis::MessageLevel mLevel;
63  QStringList mCategories;
64  };
65 
70 
72 
74  const QgsPathResolver &pathResolver() const;
75 
77  void setPathResolver( const QgsPathResolver &resolver );
78 
83  void pushMessage( const QString &message, Qgis::MessageLevel level = Qgis::Warning );
84 
96  MAYBE_UNUSED NODISCARD QgsReadWriteContextCategoryPopper enterCategory( const QString &category, const QString &details = QString() ) SIP_PYNAME( _enterCategory );
97 
102  QList<QgsReadWriteContext::ReadWriteMessage> takeMessages();
103 
108  const QgsProjectTranslator *projectTranslator( ) const { return mProjectTranslator; }
109 
116  void setProjectTranslator( QgsProjectTranslator *projectTranslator );
117 
125  QgsCoordinateTransformContext transformContext() const;
126 
134  void setTransformContext( const QgsCoordinateTransformContext &transformContext );
135 
136  private:
137 
139  void leaveCategory();
140 
141  QgsPathResolver mPathResolver;
142  QList<ReadWriteMessage> mMessages;
143  QStringList mCategories = QStringList();
144  QgsProjectTranslator *mProjectTranslator = nullptr;
146  QgsCoordinateTransformContext mCoordinateTransformContext = QgsCoordinateTransformContext();
147 };
148 
149 
159 {
160  public:
162  QgsReadWriteContextCategoryPopper( QgsReadWriteContext &context ) : mContext( context ) {}
163  ~QgsReadWriteContextCategoryPopper() {mContext.leaveCategory();}
164  private:
165 #ifdef SIP_RUN
167 #endif
168 
169  QgsReadWriteContext &mContext;
170 };
171 
172 #endif // QGSREADWRITECONTEXT_H
SIP_PYNAME
#define SIP_PYNAME(name)
Definition: qgis_sip.h:81
QgsReadWriteContext::ReadWriteMessage::message
QString message() const
Returns the message string.
Definition: qgsreadwritecontext.h:52
QgsCoordinateTransformContext
Contains information about the context in which a coordinate transform is executed.
Definition: qgscoordinatetransformcontext.h:58
QgsReadWriteContextCategoryPopper::~QgsReadWriteContextCategoryPopper
~QgsReadWriteContextCategoryPopper()
Definition: qgsreadwritecontext.h:163
QgsReadWriteContext::ReadWriteMessage::categories
QStringList categories() const
Returns the stack of categories of the message.
Definition: qgsreadwritecontext.h:58
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:35
qgscoordinatetransformcontext.h
Qgis::Warning
@ Warning
Definition: qgis.h:91
QgsReadWriteContext::ReadWriteMessage
Struct for QgsReadWriteContext error or warning messages.
Definition: qgsreadwritecontext.h:43
qgspathresolver.h
qgis.h
qgsprojecttranslator.h
QgsReadWriteContext::ReadWriteMessage::ReadWriteMessage
ReadWriteMessage(const QString &message, Qgis::MessageLevel level=Qgis::Warning, const QStringList &categories=QStringList())
Construct a container for QgsReadWriteContext error or warning messages.
Definition: qgsreadwritecontext.h:45
QgsReadWriteContextCategoryPopper
Allows entering a context category and takes care of leaving this category on deletion of the class.
Definition: qgsreadwritecontext.h:159
MAYBE_UNUSED
#define MAYBE_UNUSED
Definition: qgis.h:863
QgsReadWriteContext::ReadWriteMessage::level
Qgis::MessageLevel level() const
Returns the message level.
Definition: qgsreadwritecontext.h:55
QgsProjectTranslator
Wherever an object of this class is available, the derived translate function can be called from.
Definition: qgsprojecttranslator.h:31
Qgis::MessageLevel
MessageLevel
Level for messages This will be used both for message log and message bar in application.
Definition: qgis.h:89
QgsReadWriteContextCategoryPopper::QgsReadWriteContextCategoryPopper
QgsReadWriteContextCategoryPopper(QgsReadWriteContext &context)
Creates a popper.
Definition: qgsreadwritecontext.h:162
NODISCARD
#define NODISCARD
Definition: qgis.h:847
QgsPathResolver
Resolves relative paths into absolute paths and vice versa.
Definition: qgspathresolver.h:32