File: qgspathresolver.sip.in

package info (click to toggle)
qgis 3.40.11%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,183,800 kB
  • sloc: cpp: 1,595,841; python: 372,637; xml: 23,474; sh: 3,761; perl: 3,664; ansic: 2,257; sql: 2,137; yacc: 1,068; lex: 577; javascript: 540; lisp: 411; makefile: 154
file content (221 lines) | stat: -rw-r--r-- 6,983 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/************************************************************************
 * This file has been generated automatically from                      *
 *                                                                      *
 * src/core/qgspathresolver.h                                           *
 *                                                                      *
 * Do not edit manually ! Edit header and run scripts/sipify.py again   *
 ************************************************************************/




class QgsPathResolver
{
%Docstring(signature="appended")
Resolves relative paths into absolute paths and vice versa. Used for
writing
%End

%TypeHeaderCode
#include "qgspathresolver.h"
%End
  public:
    explicit QgsPathResolver( const QString &baseFileName = QString(), const QString &attachmentDir = 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.

If multiple preprocessors are set, they will be called in sequence based
on the order in which they were originally set.

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;
    QString id;
    Py_XINCREF( a0 );
    Py_BEGIN_ALLOW_THREADS
    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<QString *>( 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;
    } );

    Py_END_ALLOW_THREADS
    s = sipConvertFromNewType( new QString( id ), sipType_QString, 0 );
    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`.

:raises KeyError: 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




    static QString setPathWriter( SIP_PYCALLABLE / AllowNone / );
%Docstring
Sets a path writer function, which allows for manipulation of paths and
data sources prior to writing them to the project file.

The ``writer`` 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 writer function is called before any bad layer handler.

If multiple writers are set, they will be called in sequence based on
the order in which they were originally set.

Example - replace path with a variable:

.. code-block:: python

       def my_processor(path):
          return path.replace('c:/Users/ClintBarton/Documents/Projects', '$projectdir$')

       QgsPathResolver.setPathWriter(my_processor)

.. versionadded:: 3.22
%End
%MethodCode
    PyObject *s = 0;
    QString id;
    Py_XINCREF( a0 );
    Py_BEGIN_ALLOW_THREADS
    id = QgsPathResolver::setPathWriter( [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<QString *>( 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;
    } );

    Py_END_ALLOW_THREADS
    s = sipConvertFromNewType( new QString( id ), sipType_QString, 0 );
    return s;
%End


    static void removePathWriter( const QString &id );
%Docstring
Removes the custom writer function with matching ``id``.

The ``id`` must correspond to a writer previously added via a call to
:py:func:`~QgsPathResolver.setPathWriter`. An KeyError will be raised if
no processor with the specified ``id`` exists.

.. seealso:: :py:func:`setPathWriter`

.. versionadded:: 3.22
%End
%MethodCode
    if ( !QgsPathResolver::removePathWriter( *a0 ) )
    {
      PyErr_SetString( PyExc_KeyError, QStringLiteral( "No writer 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.py again   *
 ************************************************************************/