QGIS API Documentation 3.99.0-Master (26c88405ac0)
Loading...
Searching...
No Matches
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 <functional>
20#include <vector>
21
22#include "qgis_core.h"
23
24#include <QString>
25
32class CORE_EXPORT QgsPathResolver
33{
34 public:
36 explicit QgsPathResolver( const QString &baseFileName = QString(), const QString &attachmentDir = QString() );
37
43 QString writePath( const QString &filename ) const;
44
46 QString readPath( const QString &filename ) const;
47
48#ifndef SIP_RUN
49
68 static QString setPathPreprocessor( const std::function< QString( const QString &filename )> &processor );
69#else
70
114 static QString setPathPreprocessor( SIP_PYCALLABLE / AllowNone / );
115 % MethodCode
116 PyObject *s = 0;
117 QString id;
118 Py_XINCREF( a0 );
119 Py_BEGIN_ALLOW_THREADS
120 id = QgsPathResolver::setPathPreprocessor( [a0]( const QString &arg )->QString
121 {
122 QString res;
123 SIP_BLOCK_THREADS
124 PyObject *s = sipCallMethod( NULL, a0, "D", &arg, sipType_QString, NULL );
125 int state;
126 int sipIsError = 0;
127 QString *t1 = reinterpret_cast<QString *>( sipConvertToType( s, sipType_QString, 0, SIP_NOT_NONE, &state, &sipIsError ) );
128 if ( sipIsError == 0 )
129 {
130 res = QString( *t1 );
131 }
132 sipReleaseType( t1, sipType_QString, state );
133 SIP_UNBLOCK_THREADS
134 return res;
135 } );
136
137 Py_END_ALLOW_THREADS
138 s = sipConvertFromNewType( new QString( id ), sipType_QString, 0 );
139 return s;
140 % End
141#endif
142
143#ifndef SIP_RUN
144
155 static bool removePathPreprocessor( const QString &id );
156#else
157
168 static void removePathPreprocessor( const QString &id );
169 % MethodCode
171 {
172 PyErr_SetString( PyExc_KeyError, QStringLiteral( "No processor with id %1 exists." ).arg( *a0 ).toUtf8().constData() );
173 sipIsErr = 1;
174 }
175 % End
176#endif
177
178
179
198#ifndef SIP_RUN
199 static QString setPathWriter( const std::function< QString( const QString &filename )> &writer );
200#else
201
225 static QString setPathWriter( SIP_PYCALLABLE / AllowNone / );
226 % MethodCode
227 PyObject *s = 0;
228 QString id;
229 Py_XINCREF( a0 );
230 Py_BEGIN_ALLOW_THREADS
231 id = QgsPathResolver::setPathWriter( [a0]( const QString &arg )->QString
232 {
233 QString res;
234 SIP_BLOCK_THREADS
235 PyObject *s = sipCallMethod( NULL, a0, "D", &arg, sipType_QString, NULL );
236 int state;
237 int sipIsError = 0;
238 QString *t1 = reinterpret_cast<QString *>( sipConvertToType( s, sipType_QString, 0, SIP_NOT_NONE, &state, &sipIsError ) );
239 if ( sipIsError == 0 )
240 {
241 res = QString( *t1 );
242 }
243 sipReleaseType( t1, sipType_QString, state );
244 SIP_UNBLOCK_THREADS
245 return res;
246 } );
247
248 Py_END_ALLOW_THREADS
249 s = sipConvertFromNewType( new QString( id ), sipType_QString, 0 );
250 return s;
251 % End
252#endif
253
264#ifndef SIP_RUN
265 static bool removePathWriter( const QString &id );
266#else
267
277 static void removePathWriter( const QString &id );
278 % MethodCode
280 {
281 PyErr_SetString( PyExc_KeyError, QStringLiteral( "No writer with id %1 exists." ).arg( *a0 ).toUtf8().constData() );
282 sipIsErr = 1;
283 }
284 % End
285#endif
286
287 private:
289 QString mBaseFileName;
291 QString mAttachmentDir;
292};
293
294#endif // QGSPATHRESOLVER_H
QString writePath(const QString &filename) const
Prepare a filename to save it to the project file.
QgsPathResolver(const QString &baseFileName=QString(), const QString &attachmentDir=QString())
Initialize path resolver with a base filename. Null filename means no conversion between relative/abs...
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 ...
QString readPath(const QString &filename) const
Turn filename read from the project file to an absolute path.
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...