QGIS API Documentation  3.8.0-Zanzibar (11aff65)
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  : mProjectTranslator( &mDefaultTranslator )
19 {
20 
21 }
22 
24 {
25  // be sure that categories have been emptied
26  Q_ASSERT( mCategories.isEmpty() );
27 }
28 
30 {
31  return mPathResolver;
32 }
33 
35 {
36  mPathResolver = resolver;
37 }
38 
39 void QgsReadWriteContext::pushMessage( const QString &message, Qgis::MessageLevel level )
40 {
41  mMessages.append( ReadWriteMessage( message, level, mCategories ) );
42 }
43 
44 QgsReadWriteContextCategoryPopper QgsReadWriteContext::enterCategory( const QString &category, const QString &details )
45 {
46  QString message = category;
47  if ( !details.isEmpty() )
48  message.append( QStringLiteral( " :: %1" ).arg( details ) );
49  mCategories.push_back( message );
50  return QgsReadWriteContextCategoryPopper( *this );
51 }
52 
53 void QgsReadWriteContext::leaveCategory()
54 {
55  if ( !mCategories.isEmpty() )
56  mCategories.pop_back();
57 }
58 
60 {
61  return mCoordinateTransformContext;
62 }
63 
65 {
66  mCoordinateTransformContext = transformContext;
67 }
68 
70 {
71  mProjectTranslator = projectTranslator;
72 }
73 
74 
75 QList<QgsReadWriteContext::ReadWriteMessage > QgsReadWriteContext::takeMessages()
76 {
77  QList<QgsReadWriteContext::ReadWriteMessage > messages = mMessages;
78  mMessages.clear();
79  return messages;
80 }
81 
82 QString QgsReadWriteContext::DefaultTranslator::translate( const QString &context, const QString &sourceText, const char *disambiguation, int n ) const
83 {
84  Q_UNUSED( context )
85  Q_UNUSED( disambiguation )
86  Q_UNUSED( n )
87  return sourceText;
88 }
void setPathResolver(const QgsPathResolver &resolver)
Sets up path resolver for conversion between relative and absolute paths.
void setProjectTranslator(QgsProjectTranslator *projectTranslator)
Sets the project translator.
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:66
friend class QgsReadWriteContextCategoryPopper
const QgsProjectTranslator * projectTranslator() const
Returns the project translator.
QgsReadWriteContext()
Constructor for QgsReadWriteContext.
QgsCoordinateTransformContext transformContext() const
Returns data provider coordinate transform context.
Struct for QgsReadWriteContext error or warning messages.
void setTransformContext(const QgsCoordinateTransformContext &transformContext)
Sets data coordinate transform context to transformContext.
QList< QgsReadWriteContext::ReadWriteMessage > takeMessages()
Returns the stored messages and remove them.
Contains information about the context in which a coordinate transform is executed.
Wherever an object of this class is available, the derived translate function can be called from...
const QgsPathResolver & pathResolver() const
Returns path resolver for conversion between relative and absolute paths.
Resolves relative paths into absolute paths and vice versa.