QGIS API Documentation  3.2.0-Bonn (bc43194)
qgsreadwritecontext.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsreadwritecontext.cpp
3  ---------------------
4  begin : May 2017
5  copyright : (C) 2017 by Martin Dobias
6  email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 #include "qgsreadwritecontext.h"
16 
18 {
19  // be sure that categories have been emptied
20  Q_ASSERT( mCategories.isEmpty() );
21 }
22 
24 {
25  return mPathResolver;
26 }
27 
29 {
30  mPathResolver = resolver;
31 }
32 
33 void QgsReadWriteContext::pushMessage( const QString &message, Qgis::MessageLevel level )
34 {
35  mMessages.append( ReadWriteMessage( message, level, mCategories ) );
36 }
37 
38 QgsReadWriteContextCategoryPopper QgsReadWriteContext::enterCategory( const QString &category, const QString &details )
39 {
40  QString message = category;
41  if ( !details.isEmpty() )
42  message.append( QString( " :: %1" ).arg( details ) );
43  mCategories.push_back( message );
44  return QgsReadWriteContextCategoryPopper( *this );
45 }
46 
47 void QgsReadWriteContext::leaveCategory()
48 {
49  if ( !mCategories.isEmpty() )
50  mCategories.pop_back();
51 }
52 
53 QList<QgsReadWriteContext::ReadWriteMessage > QgsReadWriteContext::takeMessages()
54 {
55  QList<QgsReadWriteContext::ReadWriteMessage > messages = mMessages;
56  mMessages.clear();
57  return messages;
58 }
void setPathResolver(const QgsPathResolver &resolver)
Sets up path resolver for conversion between relative and absolute paths.
MAYBE_UNUSED NODISCARD QgsReadWriteContextCategoryPopper enterCategory(const QString &category, const QString &details=QString())
Push a category to the stack.
Allows entering a context category and takes care of leaving this category on deletion of the class...
void pushMessage(const QString &message, Qgis::MessageLevel level=Qgis::Warning)
Append a message to the context.
MessageLevel
Level for messages This will be used both for message log and message bar in application.
Definition: qgis.h:78
friend class QgsReadWriteContextCategoryPopper
Struct for QgsReadWriteContext error or warning messages.
QList< QgsReadWriteContext::ReadWriteMessage > takeMessages()
Returns the stored messages and remove them.
const QgsPathResolver & pathResolver() const
Returns path resolver for conversion between relative and absolute paths.
Resolves relative paths into absolute paths and vice versa.