QGIS API Documentation  3.2.0-Bonn (bc43194)
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 
25 
32 class CORE_EXPORT QgsReadWriteContext
33 {
34  public:
35 
41  {
43  ReadWriteMessage( const QString &message, Qgis::MessageLevel level = Qgis::Warning, const QStringList &categories = QStringList() )
44  : mMessage( message )
45  , mLevel( level )
46  , mCategories( categories )
47  {}
48 
50  QString message() const {return mMessage;}
51 
53  Qgis::MessageLevel level() const {return mLevel;}
54 
56  QStringList categories() const {return mCategories;}
57 
58  private:
59  QString mMessage;
60  Qgis::MessageLevel mLevel;
61  QStringList mCategories;
62  };
63 
67  QgsReadWriteContext() = default;
68 
70 
72  const QgsPathResolver &pathResolver() const;
73 
75  void setPathResolver( const QgsPathResolver &resolver );
76 
81  void pushMessage( const QString &message, Qgis::MessageLevel level = Qgis::Warning );
82 
94  MAYBE_UNUSED NODISCARD QgsReadWriteContextCategoryPopper enterCategory( const QString &category, const QString &details = QString() ) SIP_PYNAME( _enterCategory );
95 
100  QList<QgsReadWriteContext::ReadWriteMessage> takeMessages();
101 
102 
103  private:
105  void leaveCategory();
106 
107  QgsPathResolver mPathResolver;
108  QList<ReadWriteMessage> mMessages;
109  QStringList mCategories = QStringList();
110 
112 };
113 
114 
124 {
125  public:
127  QgsReadWriteContextCategoryPopper( QgsReadWriteContext &context ) : mContext( context ) {}
128  ~QgsReadWriteContextCategoryPopper() {mContext.leaveCategory();}
129  private:
130  QgsReadWriteContext &mContext;
131 };
132 
133 #endif // QGSREADWRITECONTEXT_H
The class is used as a container of context for various read/write operations on other objects...
QString message() const
Returns the message string.
#define NODISCARD
Definition: qgis.h:589
QStringList categories() const
Returns the stack of categories of the message.
ReadWriteMessage(const QString &message, Qgis::MessageLevel level=Qgis::Warning, const QStringList &categories=QStringList())
Construct a container for QgsReadWriteContext error or warning messages.
Allows entering a context category and takes care of leaving this category on deletion of the class...
MessageLevel
Level for messages This will be used both for message log and message bar in application.
Definition: qgis.h:78
Struct for QgsReadWriteContext error or warning messages.
QgsReadWriteContextCategoryPopper(QgsReadWriteContext &context)
Creates a popper.
Qgis::MessageLevel level() const
Returns the message level.
#define MAYBE_UNUSED
Definition: qgis.h:605
Resolves relative paths into absolute paths and vice versa.
#define SIP_PYNAME(name)
Definition: qgis_sip.h:74