QGIS API Documentation 3.99.0-Master (d270888f95f)
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
26using namespace Qt::StringLiterals;
27
34class CORE_EXPORT QgsPathResolver
35{
36 public:
38 explicit QgsPathResolver( const QString &baseFileName = QString(), const QString &attachmentDir = QString() );
39
45 QString writePath( const QString &filename ) const;
46
48 QString readPath( const QString &filename ) const;
49
50#ifndef SIP_RUN
51
70 static QString setPathPreprocessor( const std::function< QString( const QString &filename )> &processor );
71#else
72
116 static QString setPathPreprocessor( SIP_PYCALLABLE / AllowNone / );
117 % MethodCode
118 PyObject *s = 0;
119 QString id;
120 Py_XINCREF( a0 );
121 Py_BEGIN_ALLOW_THREADS
122 id = QgsPathResolver::setPathPreprocessor( [a0]( const QString &arg )->QString
123 {
124 QString res;
125 SIP_BLOCK_THREADS
126 PyObject *s = sipCallMethod( NULL, a0, "D", &arg, sipType_QString, NULL );
127 int state;
128 int sipIsError = 0;
129 QString *t1 = reinterpret_cast<QString *>( sipConvertToType( s, sipType_QString, 0, SIP_NOT_NONE, &state, &sipIsError ) );
130 if ( sipIsError == 0 )
131 {
132 res = QString( *t1 );
133 }
134 sipReleaseType( t1, sipType_QString, state );
135 SIP_UNBLOCK_THREADS
136 return res;
137 } );
138
139 Py_END_ALLOW_THREADS
140 s = sipConvertFromNewType( new QString( id ), sipType_QString, 0 );
141 return s;
142 % End
143#endif
144
145#ifndef SIP_RUN
146
157 static bool removePathPreprocessor( const QString &id );
158#else
159
170 static void removePathPreprocessor( const QString &id );
171 % MethodCode
173 {
174 PyErr_SetString( PyExc_KeyError, u"No processor with id %1 exists."_s.arg( *a0 ).toUtf8().constData() );
175 sipIsErr = 1;
176 }
177 % End
178#endif
179
180
181
200#ifndef SIP_RUN
201 static QString setPathWriter( const std::function< QString( const QString &filename )> &writer );
202#else
203
227 static QString setPathWriter( SIP_PYCALLABLE / AllowNone / );
228 % MethodCode
229 PyObject *s = 0;
230 QString id;
231 Py_XINCREF( a0 );
232 Py_BEGIN_ALLOW_THREADS
233 id = QgsPathResolver::setPathWriter( [a0]( const QString &arg )->QString
234 {
235 QString res;
236 SIP_BLOCK_THREADS
237 PyObject *s = sipCallMethod( NULL, a0, "D", &arg, sipType_QString, NULL );
238 int state;
239 int sipIsError = 0;
240 QString *t1 = reinterpret_cast<QString *>( sipConvertToType( s, sipType_QString, 0, SIP_NOT_NONE, &state, &sipIsError ) );
241 if ( sipIsError == 0 )
242 {
243 res = QString( *t1 );
244 }
245 sipReleaseType( t1, sipType_QString, state );
246 SIP_UNBLOCK_THREADS
247 return res;
248 } );
249
250 Py_END_ALLOW_THREADS
251 s = sipConvertFromNewType( new QString( id ), sipType_QString, 0 );
252 return s;
253 % End
254#endif
255
266#ifndef SIP_RUN
267 static bool removePathWriter( const QString &id );
268#else
269
279 static void removePathWriter( const QString &id );
280 % MethodCode
282 {
283 PyErr_SetString( PyExc_KeyError, u"No writer with id %1 exists."_s.arg( *a0 ).toUtf8().constData() );
284 sipIsErr = 1;
285 }
286 % End
287#endif
288
289 private:
291 QString mBaseFileName;
293 QString mAttachmentDir;
294};
295
296#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...