File: providermetadata.py

package info (click to toggle)
qgis 3.40.10%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,183,672 kB
  • sloc: cpp: 1,595,771; python: 372,544; 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: 161
file content (41 lines) | stat: -rw-r--r-- 1,890 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
"""
***************************************************************************
    providermetadata.py
    ---------------------
    Date                 : June 2019
    Copyright            : (C) 2019 by Martin Dobias
    Email                : wonder dot sk at gmail dot com
***************************************************************************
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU General Public License as published by  *
*   the Free Software Foundation; either version 2 of the License, or     *
*   (at your option) any later version.                                   *
*                                                                         *
***************************************************************************
"""

from qgis._core import QgsProviderMetadata


class PyProviderMetadata(QgsProviderMetadata):
    """wrapper around QgsProviderMetadata to keep the existing Python code running which registers
    data providers by passing a custom python createProvider() function to QgsProviderMetadata
    constructor. The proper new way of doing it is to subclass QgsProviderMetadata and implement
    its virtual functions.

    TODO: QGIS 4 - remove this wrapper (only subclassing of QgsProviderMetadata should be used)
    """

    # this is a workaround to keep references to metadata classes
    # so they are not removed when the variable gets out of scope
    _kept_refs = []

    def __init__(self, key, description, library_or_create_func=None):
        super().__init__(key, description)
        if callable(library_or_create_func):
            self.createProvider = library_or_create_func
            PyProviderMetadata._kept_refs.append(self)


PyProviderMetadata.__doc__ = QgsProviderMetadata.__doc__