QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 
31 class CORE_EXPORT QgsPathResolver
32 {
33  public:
35  explicit QgsPathResolver( const QString &baseFileName = 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 
112  static QString setPathPreprocessor( SIP_PYCALLABLE / AllowNone / );
113  % MethodCode
114  PyObject *s = 0;
115  Py_BEGIN_ALLOW_THREADS
116  Py_XINCREF( a0 );
117  QString id = QgsPathResolver::setPathPreprocessor( [a0]( const QString &arg )->QString
118  {
119  QString res;
120  SIP_BLOCK_THREADS
121  PyObject *s = sipCallMethod( NULL, a0, "D", &arg, sipType_QString, NULL );
122  int state;
123  int sipIsError = 0;
124  QString *t1 = reinterpret_cast<QString *>( sipConvertToType( s, sipType_QString, 0, SIP_NOT_NONE, &state, &sipIsError ) );
125  if ( sipIsError == 0 )
126  {
127  res = QString( *t1 );
128  }
129  sipReleaseType( t1, sipType_QString, state );
130  SIP_UNBLOCK_THREADS
131  return res;
132  } );
133 
134  s = sipConvertFromNewType( new QString( id ), sipType_QString, 0 );
135  Py_END_ALLOW_THREADS
136  return s;
137  % End
138 #endif
139 
140 #ifndef SIP_RUN
141 
152  static bool removePathPreprocessor( const QString &id );
153 #else
154 
164  static void removePathPreprocessor( const QString &id );
165  % MethodCode
167  {
168  PyErr_SetString( PyExc_KeyError, QStringLiteral( "No processor with id %1 exists." ).arg( *a0 ).toUtf8().constData() );
169  sipIsErr = 1;
170  }
171  % End
172 #endif
173 
174  private:
176  QString mBaseFileName;
177 };
178 
179 #endif // QGSPATHRESOLVER_H
QgsPathResolver::removePathPreprocessor
static bool removePathPreprocessor(const QString &id)
Removes the custom pre-processor function with matching id.
Definition: qgspathresolver.cpp:177
QgsPathResolver::setPathPreprocessor
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 ...
Definition: qgspathresolver.cpp:170
QgsPathResolver
Definition: qgspathresolver.h:31