QGIS API Documentation 3.99.0-Master (d270888f95f)
Loading...
Searching...
No Matches
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
17#include <QString>
18
19using namespace Qt::StringLiterals;
20
22class DefaultTranslator : public QgsProjectTranslator
23{
24 // QgsProjectTranslator interface
25 public:
26 QString translate( const QString &context, const QString &sourceText, const char *disambiguation, int n ) const override
27 {
28 Q_UNUSED( context )
29 Q_UNUSED( disambiguation )
30 Q_UNUSED( n )
31 return sourceText;
32 }
33};
34
36
37Q_GLOBAL_STATIC( DefaultTranslator, sDefaultTranslator )
38
40 : mProjectTranslator( sDefaultTranslator() )
41{
42
43}
44
46{
47 // be sure that categories have been emptied
48 Q_ASSERT( mCategories.isEmpty() );
49}
50
52{
53 return mPathResolver;
54}
55
57{
58 mPathResolver = resolver;
59}
60
61void QgsReadWriteContext::pushMessage( const QString &message, Qgis::MessageLevel level ) const
62{
63 mMessages.append( ReadWriteMessage( message, level, mCategories ) );
64}
65
66QgsReadWriteContextCategoryPopper QgsReadWriteContext::enterCategory( const QString &category, const QString &details ) const
67{
68 QString message = category;
69 if ( !details.isEmpty() )
70 message.append( u" :: %1"_s.arg( details ) );
71 mCategories.push_back( message );
73}
74
75void QgsReadWriteContext::leaveCategory() const
76{
77 if ( !mCategories.isEmpty() )
78 mCategories.pop_back();
79}
80
82{
83 return mCoordinateTransformContext;
84}
85
90
92{
93 mProjectTranslator = projectTranslator;
94 if ( !mProjectTranslator )
95 mProjectTranslator = sDefaultTranslator();
96}
97
98QList<QgsReadWriteContext::ReadWriteMessage > QgsReadWriteContext::takeMessages()
99{
100 QList<QgsReadWriteContext::ReadWriteMessage > messages = mMessages;
101 mMessages.clear();
102 return messages;
103}
MessageLevel
Level for messages This will be used both for message log and message bar in application.
Definition qgis.h:159
Contains information about the context in which a coordinate transform is executed.
Resolves relative paths into absolute paths and vice versa.
An interface for objects which can translate project strings.
virtual QString translate(const QString &context, const QString &sourceText, const char *disambiguation=nullptr, int n=-1) const =0
Translates a string using the Qt QTranslator mechanism.
QgsReadWriteContextCategoryPopper enterCategory(const QString &category, const QString &details=QString()) const
Push a category to the stack.
const QgsProjectTranslator * projectTranslator() const
Returns the project translator.
QgsReadWriteContext()
Constructor for QgsReadWriteContext.
void setTransformContext(const QgsCoordinateTransformContext &transformContext)
Sets data coordinate transform context to transformContext.
QgsCoordinateTransformContext transformContext() const
Returns data provider coordinate transform context.
QList< QgsReadWriteContext::ReadWriteMessage > takeMessages()
Returns the stored messages and remove them.
friend class QgsReadWriteContextCategoryPopper
void pushMessage(const QString &message, Qgis::MessageLevel level=Qgis::MessageLevel::Warning) const
Append a message to the context.
const QgsPathResolver & pathResolver() const
Returns path resolver for conversion between relative and absolute paths.
void setProjectTranslator(QgsProjectTranslator *projectTranslator)
Sets the project translator.
void setPathResolver(const QgsPathResolver &resolver)
Sets up path resolver for conversion between relative and absolute paths.
Q_GLOBAL_STATIC(QReadWriteLock, sDefinitionCacheLock)
Struct for QgsReadWriteContext error or warning messages.