3 Commits

Author SHA1 Message Date
Nyall Dawson
83a842d44f Ensure ownership of path preprocessor is transferred 2019-07-25 08:41:28 +10:00
Nyall Dawson
2237c6ae99 [API][FEATURE] Allow setting a custom path pre-processor for QgsPathResolver
QgsPathResolver::setPathPreprocessor allows setting a custom 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.

Example - replace an outdated folder path with a new one:

  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:

  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:

  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)
2019-07-25 08:41:28 +10:00
Denis Rouzaud
7df2593caf move auto generated sip file in dedicated folder 2018-05-14 10:23:37 -04:00