QGIS API Documentation  3.37.0-Master (a5b4d9743e8)
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 
30 class CORE_EXPORT QgsPathResolver
31 {
32  public:
34  explicit QgsPathResolver( const QString &baseFileName = QString(), const QString &attachmentDir = QString() );
35 
41  QString writePath( const QString &filename ) const;
42 
44  QString readPath( const QString &filename ) const;
45 
46 #ifndef SIP_RUN
47 
66  static QString setPathPreprocessor( const std::function< QString( const QString &filename )> &processor );
67 #else
68 
112  static QString setPathPreprocessor( SIP_PYCALLABLE / AllowNone / );
113  % MethodCode
114  PyObject *s = 0;
115  QString id;
116  Py_XINCREF( a0 );
117  Py_BEGIN_ALLOW_THREADS
118  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  Py_END_ALLOW_THREADS
136  s = sipConvertFromNewType( new QString( id ), sipType_QString, 0 );
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  QString id;
227  Py_XINCREF( a0 );
228  Py_BEGIN_ALLOW_THREADS
229  id = QgsPathResolver::setPathWriter( [a0]( const QString &arg )->QString
230  {
231  QString res;
232  SIP_BLOCK_THREADS
233  PyObject *s = sipCallMethod( NULL, a0, "D", &arg, sipType_QString, NULL );
234  int state;
235  int sipIsError = 0;
236  QString *t1 = reinterpret_cast<QString *>( sipConvertToType( s, sipType_QString, 0, SIP_NOT_NONE, &state, &sipIsError ) );
237  if ( sipIsError == 0 )
238  {
239  res = QString( *t1 );
240  }
241  sipReleaseType( t1, sipType_QString, state );
242  SIP_UNBLOCK_THREADS
243  return res;
244  } );
245 
246  Py_END_ALLOW_THREADS
247  s = sipConvertFromNewType( new QString( id ), sipType_QString, 0 );
248  return s;
249  % End
250 #endif
251 
262 #ifndef SIP_RUN
263  static bool removePathWriter( const QString &id );
264 #else
265 
275  static void removePathWriter( const QString &id );
276  % MethodCode
277  if ( !QgsPathResolver::removePathWriter( *a0 ) )
278  {
279  PyErr_SetString( PyExc_KeyError, QStringLiteral( "No writer with id %1 exists." ).arg( *a0 ).toUtf8().constData() );
280  sipIsErr = 1;
281  }
282  % End
283 #endif
284 
285  private:
287  QString mBaseFileName;
289  QString mAttachmentDir;
290 };
291 
292 #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...