QGIS API Documentation 4.1.0-Master (60fea48833c)
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 // clang-format off
73
117 static QString setPathPreprocessor( SIP_PYCALLABLE / AllowNone / );
118 % MethodCode
119 PyObject *s = 0;
120 QString id;
121 Py_XINCREF( a0 );
122 Py_BEGIN_ALLOW_THREADS
123 id = QgsPathResolver::setPathPreprocessor( [a0]( const QString &arg )->QString
124 {
125 QString res;
126 SIP_BLOCK_THREADS
127 PyObject *s = sipCallMethod( NULL, a0, "D", &arg, sipType_QString, NULL );
128 int state;
129 int sipIsError = 0;
130 QString *t1 = reinterpret_cast<QString *>( sipConvertToType( s, sipType_QString, 0, SIP_NOT_NONE, &state, &sipIsError ) );
131 if ( sipIsError == 0 )
132 {
133 res = QString( *t1 );
134 }
135 sipReleaseType( t1, sipType_QString, state );
136 SIP_UNBLOCK_THREADS
137 return res;
138 } );
139
140 Py_END_ALLOW_THREADS
141 s = sipConvertFromNewType( new QString( id ), sipType_QString, 0 );
142 return s;
143 % End
144// clang-format on
145#endif
146
147#ifndef SIP_RUN
148
159 static bool removePathPreprocessor( const QString &id );
160#else
161 // clang-format off
162
173 static void removePathPreprocessor( const QString &id );
174 % MethodCode
176 {
177 PyErr_SetString( PyExc_KeyError, u"No processor with id %1 exists."_s.arg( *a0 ).toUtf8().constData() );
178 sipIsErr = 1;
179 }
180 % End
181// clang-format on
182#endif
183
184
203#ifndef SIP_RUN
204 static QString setPathWriter( const std::function< QString( const QString &filename )> &writer );
205#else
206 // clang-format off
207
231 static QString setPathWriter( SIP_PYCALLABLE / AllowNone / );
232 % MethodCode
233 PyObject *s = 0;
234 QString id;
235 Py_XINCREF( a0 );
236 Py_BEGIN_ALLOW_THREADS
237 id = QgsPathResolver::setPathWriter( [a0]( const QString &arg )->QString
238 {
239 QString res;
240 SIP_BLOCK_THREADS
241 PyObject *s = sipCallMethod( NULL, a0, "D", &arg, sipType_QString, NULL );
242 int state;
243 int sipIsError = 0;
244 QString *t1 = reinterpret_cast<QString *>( sipConvertToType( s, sipType_QString, 0, SIP_NOT_NONE, &state, &sipIsError ) );
245 if ( sipIsError == 0 )
246 {
247 res = QString( *t1 );
248 }
249 sipReleaseType( t1, sipType_QString, state );
250 SIP_UNBLOCK_THREADS
251 return res;
252 } );
253
254 Py_END_ALLOW_THREADS
255 s = sipConvertFromNewType( new QString( id ), sipType_QString, 0 );
256 return s;
257 % End
258// clang-format on
259#endif
260
271#ifndef SIP_RUN
272 static bool removePathWriter( const QString &id );
273#else
274 // clang-format off
275
285 static void removePathWriter( const QString &id );
286 % MethodCode
288 {
289 PyErr_SetString( PyExc_KeyError, u"No writer with id %1 exists."_s.arg( *a0 ).toUtf8().constData() );
290 sipIsErr = 1;
291 }
292 % End
293// clang-format on
294#endif
295
296 private:
298 QString mBaseFileName;
300 QString mAttachmentDir;
301};
302
303#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...