QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
qgspathresolver.h
Go to the documentation of this file.
1/***************************************************************************
2 qgspathresolver.h
3 --------------------------------------
4 Date : February 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
16#ifndef QGSPATHRESOLVER_H
17#define QGSPATHRESOLVER_H
18
19#include "qgis_core.h"
20
21#include <QString>
22#include <functional>
23#include <vector>
24
31class CORE_EXPORT QgsPathResolver
32{
33 public:
35 explicit QgsPathResolver( const QString &baseFileName = QString(), const QString &attachmentDir = QString() );
36
42 QString writePath( const QString &filename ) const;
43
45 QString readPath( const QString &filename ) const;
46
47#ifndef SIP_RUN
48
67 static QString setPathPreprocessor( const std::function< QString( const QString &filename )> &processor );
68#else
69
113 static QString setPathPreprocessor( SIP_PYCALLABLE / AllowNone / );
114 % MethodCode
115 PyObject *s = 0;
116 Py_BEGIN_ALLOW_THREADS
117 Py_XINCREF( a0 );
118 QString id = QgsPathResolver::setPathPreprocessor( [a0]( const QString &arg )->QString
119 {
120 QString res;
121 SIP_BLOCK_THREADS
122 PyObject *s = sipCallMethod( NULL, a0, "D", &arg, sipType_QString, NULL );
123 int state;
124 int sipIsError = 0;
125 QString *t1 = reinterpret_cast<QString *>( sipConvertToType( s, sipType_QString, 0, SIP_NOT_NONE, &state, &sipIsError ) );
126 if ( sipIsError == 0 )
127 {
128 res = QString( *t1 );
129 }
130 sipReleaseType( t1, sipType_QString, state );
131 SIP_UNBLOCK_THREADS
132 return res;
133 } );
134
135 s = sipConvertFromNewType( new QString( id ), sipType_QString, 0 );
136 Py_END_ALLOW_THREADS
137 return s;
138 % End
139#endif
140
141#ifndef SIP_RUN
142
153 static bool removePathPreprocessor( const QString &id );
154#else
155
166 static void removePathPreprocessor( const QString &id );
167 % MethodCode
169 {
170 PyErr_SetString( PyExc_KeyError, QStringLiteral( "No processor with id %1 exists." ).arg( *a0 ).toUtf8().constData() );
171 sipIsErr = 1;
172 }
173 % End
174#endif
175
176
177
196#ifndef SIP_RUN
197 static QString setPathWriter( const std::function< QString( const QString &filename )> &writer );
198#else
199
223 static QString setPathWriter( SIP_PYCALLABLE / AllowNone / );
224 % MethodCode
225 PyObject *s = 0;
226 Py_BEGIN_ALLOW_THREADS
227 Py_XINCREF( a0 );
228 QString id = QgsPathResolver::setPathWriter( [a0]( const QString &arg )->QString
229 {
230 QString res;
231 SIP_BLOCK_THREADS
232 PyObject *s = sipCallMethod( NULL, a0, "D", &arg, sipType_QString, NULL );
233 int state;
234 int sipIsError = 0;
235 QString *t1 = reinterpret_cast<QString *>( sipConvertToType( s, sipType_QString, 0, SIP_NOT_NONE, &state, &sipIsError ) );
236 if ( sipIsError == 0 )
237 {
238 res = QString( *t1 );
239 }
240 sipReleaseType( t1, sipType_QString, state );
241 SIP_UNBLOCK_THREADS
242 return res;
243 } );
244
245 s = sipConvertFromNewType( new QString( id ), sipType_QString, 0 );
246 Py_END_ALLOW_THREADS
247 return s;
248 % End
249#endif
250
261#ifndef SIP_RUN
262 static bool removePathWriter( const QString &id );
263#else
264
274 static void removePathWriter( const QString &id );
275 % MethodCode
277 {
278 PyErr_SetString( PyExc_KeyError, QStringLiteral( "No writer with id %1 exists." ).arg( *a0 ).toUtf8().constData() );
279 sipIsErr = 1;
280 }
281 % End
282#endif
283
284 private:
286 QString mBaseFileName;
288 QString mAttachmentDir;
289};
290
291#endif // QGSPATHRESOLVER_H
Resolves relative paths into absolute paths and vice versa.
static bool removePathPreprocessor(const QString &id)
Removes the custom pre-processor function with matching id.
static QString setPathPreprocessor(const std::function< QString(const QString &filename)> &processor)
Sets a path pre-processor function, which allows for manipulation of paths and data sources prior to ...
static bool removePathWriter(const QString &id)
Removes the custom writer function with matching id.
static QString setPathWriter(const std::function< QString(const QString &filename)> &writer)
Sets a path writer function, which allows for manipulation of paths and data sources prior to writing...