QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 class DefaultTranslator : public QgsProjectTranslator
19 {
20  // QgsProjectTranslator interface
21  public:
22  QString translate( const QString &context, const QString &sourceText, const char *disambiguation, int n ) const override
23  {
24  Q_UNUSED( context )
25  Q_UNUSED( disambiguation )
26  Q_UNUSED( n )
27  return sourceText;
28  }
29 };
30 
32 
33 Q_GLOBAL_STATIC( DefaultTranslator, sDefaultTranslator )
34 
36  : mProjectTranslator( sDefaultTranslator() )
37 {
38 
39 }
40 
42 {
43  // be sure that categories have been emptied
44  Q_ASSERT( mCategories.isEmpty() );
45 }
46 
48 {
49  return mPathResolver;
50 }
51 
53 {
54  mPathResolver = resolver;
55 }
56 
57 void QgsReadWriteContext::pushMessage( const QString &message, Qgis::MessageLevel level )
58 {
59  mMessages.append( ReadWriteMessage( message, level, mCategories ) );
60 }
61 
62 QgsReadWriteContextCategoryPopper QgsReadWriteContext::enterCategory( const QString &category, const QString &details )
63 {
64  QString message = category;
65  if ( !details.isEmpty() )
66  message.append( QStringLiteral( " :: %1" ).arg( details ) );
67  mCategories.push_back( message );
68  return QgsReadWriteContextCategoryPopper( *this );
69 }
70 
71 void QgsReadWriteContext::leaveCategory()
72 {
73  if ( !mCategories.isEmpty() )
74  mCategories.pop_back();
75 }
76 
78 {
79  return mCoordinateTransformContext;
80 }
81 
83 {
84  mCoordinateTransformContext = transformContext;
85 }
86 
88 {
89  mProjectTranslator = projectTranslator;
90 }
91 
92 
93 QList<QgsReadWriteContext::ReadWriteMessage > QgsReadWriteContext::takeMessages()
94 {
95  QList<QgsReadWriteContext::ReadWriteMessage > messages = mMessages;
96  mMessages.clear();
97  return messages;
98 }
QgsReadWriteContext::setPathResolver
void setPathResolver(const QgsPathResolver &resolver)
Sets up path resolver for conversion between relative and absolute paths.
Definition: qgsreadwritecontext.cpp:52
QgsCoordinateTransformContext
Definition: qgscoordinatetransformcontext.h:57
QgsReadWriteContext
Definition: qgsreadwritecontext.h:34
QgsReadWriteContext::setTransformContext
void setTransformContext(const QgsCoordinateTransformContext &transformContext)
Sets data coordinate transform context to transformContext.
Definition: qgsreadwritecontext.cpp:82
qgsreadwritecontext.h
QgsReadWriteContext::ReadWriteMessage
Struct for QgsReadWriteContext error or warning messages.
Definition: qgsreadwritecontext.h:42
QgsReadWriteContext::transformContext
QgsCoordinateTransformContext transformContext() const
Returns data provider coordinate transform context.
Definition: qgsreadwritecontext.cpp:77
QgsReadWriteContext::setProjectTranslator
void setProjectTranslator(QgsProjectTranslator *projectTranslator)
Sets the project translator.
Definition: qgsreadwritecontext.cpp:87
QgsReadWriteContext::enterCategory
MAYBE_UNUSED NODISCARD QgsReadWriteContextCategoryPopper enterCategory(const QString &category, const QString &details=QString())
Push a category to the stack.
Definition: qgsreadwritecontext.cpp:62
Q_GLOBAL_STATIC
Q_GLOBAL_STATIC(QReadWriteLock, sDefinitionCacheLock)
QgsReadWriteContext::pushMessage
void pushMessage(const QString &message, Qgis::MessageLevel level=Qgis::Warning)
Append a message to the context.
Definition: qgsreadwritecontext.cpp:57
QgsReadWriteContextCategoryPopper
Definition: qgsreadwritecontext.h:158
QgsReadWriteContext::projectTranslator
const QgsProjectTranslator * projectTranslator() const
Returns the project translator.
Definition: qgsreadwritecontext.h:108
QgsReadWriteContext::~QgsReadWriteContext
~QgsReadWriteContext()
Definition: qgsreadwritecontext.cpp:41
QgsReadWriteContext::QgsReadWriteContextCategoryPopper
friend class QgsReadWriteContextCategoryPopper
Definition: qgsreadwritecontext.h:145
QgsProjectTranslator
Definition: qgsprojecttranslator.h:30
Qgis::MessageLevel
MessageLevel
Level for messages This will be used both for message log and message bar in application.
Definition: qgis.h:101
QgsReadWriteContext::takeMessages
QList< QgsReadWriteContext::ReadWriteMessage > takeMessages()
Returns the stored messages and remove them.
Definition: qgsreadwritecontext.cpp:93
QgsPathResolver
Definition: qgspathresolver.h:31
QgsProjectTranslator::translate
virtual QString translate(const QString &context, const QString &sourceText, const char *disambiguation=nullptr, int n=-1) const =0
The derived translate() translates with QTranslator and qm file the sourceText.
QgsReadWriteContext::pathResolver
const QgsPathResolver & pathResolver() const
Returns path resolver for conversion between relative and absolute paths.
Definition: qgsreadwritecontext.cpp:47