/************************************************************************ * This file has been generated automatically from * * * * src/core/qgspathresolver.h * * * * Do not edit manually ! Edit header and run scripts/sipify.pl again * ************************************************************************/ class QgsPathResolver { %Docstring Resolves relative paths into absolute paths and vice versa. Used for writing .. versionadded:: 3.0 %End %TypeHeaderCode #include "qgspathresolver.h" %End public: explicit QgsPathResolver( const QString &baseFileName = QString() ); %Docstring Initialize path resolver with a base filename. Null filename means no conversion between relative/absolute path %End QString writePath( const QString &filename ) const; %Docstring Prepare a filename to save it to the project file. Creates an absolute or relative path according to the project settings. Paths written to the project file should be prepared with this method. %End QString readPath( const QString &filename ) const; %Docstring Turn filename read from the project file to an absolute path %End static QString setPathPreprocessor( SIP_PYCALLABLE / AllowNone / ); %Docstring Sets a path pre-processor function, which allows for manipulation of paths and data sources prior to resolving them to file references or layer sources. The ``processor`` function must accept a single string argument (representing the original file path or data source), and return a processed version of this path. The path pre-processor function is called before any bad layer handler. .. note:: Setting a new ``processor`` replaces any existing processor. Example - replace an outdated folder path with a new one: .. code-block:: python def my_processor(path): return path.replace('c:/Users/ClintBarton/Documents/Projects', 'x:/Projects/') QgsPathResolver.setPathPreprocessor(my_processor) Example - replace a stored database host with a new one: .. code-block:: python def my_processor(path): return path.replace('host=10.1.1.115', 'host=10.1.1.116') QgsPathResolver.setPathPreprocessor(my_processor) Example - replace stored database credentials with new ones: .. code-block:: python def my_processor(path): path = path.replace("user='gis_team'", "user='team_awesome'") path = path.replace("password='cats'", "password='g7as!m*'") return path QgsPathResolver.setPathPreprocessor(my_processor) .. versionadded:: 3.10 %End %MethodCode PyObject *s = 0; Py_BEGIN_ALLOW_THREADS Py_XINCREF( a0 ); QString id = QgsPathResolver::setPathPreprocessor( [a0]( const QString &arg )->QString { QString res; SIP_BLOCK_THREADS PyObject *s = sipCallMethod( NULL, a0, "D", &arg, sipType_QString, NULL ); int state; int sipIsError = 0; QString *t1 = reinterpret_cast( sipConvertToType( s, sipType_QString, 0, SIP_NOT_NONE, &state, &sipIsError ) ); if ( sipIsError == 0 ) { res = QString( *t1 ); } sipReleaseType( t1, sipType_QString, state ); SIP_UNBLOCK_THREADS return res; } ); s = sipConvertFromNewType( new QString( id ), sipType_QString, 0 ); Py_END_ALLOW_THREADS return s; %End static void removePathPreprocessor( const QString &id ); %Docstring Removes the custom pre-processor function with matching ``id``. The ``id`` must correspond to a pre-processor previously added via a call to :py:func:`~QgsPathResolver.setPathPreprocessor`. An KeyError will be raised if no processor with the specified ``id`` exists. .. seealso:: :py:func:`setPathPreprocessor` .. versionadded:: 3.10 %End %MethodCode if ( !QgsPathResolver::removePathPreprocessor( *a0 ) ) { PyErr_SetString( PyExc_KeyError, QStringLiteral( "No processor with id %1 exists." ).arg( *a0 ).toUtf8().constData() ); sipIsErr = 1; } %End }; /************************************************************************ * This file has been generated automatically from * * * * src/core/qgspathresolver.h * * * * Do not edit manually ! Edit header and run scripts/sipify.pl again * ************************************************************************/