# -*- coding: utf-8 -*-

"""
/***************************************************************************
 QProto
                                 A QGIS plugin
 QProto algorithm
 Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/
                              -------------------
        begin                : 2018-04-19
        copyright            : (C) 2018 by Matteo Ghetta (Faunalia)
        email                : matteo.ghetta@faunalia.eu
        updated              : 2026 by Stefano Campus & Codex
        update email         : skampus@gmail.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.                                   *
 *                                                                         *
 ***************************************************************************/
"""

__author__ = 'Matteo Ghetta (Faunalia); 2026 update by Stefano Campus'
__date__ = '2018-04-19'
__copyright__ = '(C) 2018 by Matteo Ghetta (Faunalia); 2026 update by Stefano Campus'

__revision__ = '$Format:%H$'

from qgis.core import QgsProcessingProvider
from .qproto_algorithm import QProtoAlgorithm
from .qproto_postprocessing import Modello
from .qproto_source_affecting_index import SourceAffectingIndexAlgorithm
from qgis.PyQt.QtGui import QIcon
import os

pluginPath = os.path.dirname(__file__)

class QProtoProvider(QgsProcessingProvider):

    def __init__(self):
        super().__init__()
        self.algorithm_classes = [
            QProtoAlgorithm,
            Modello,
            SourceAffectingIndexAlgorithm
        ]

    def unload(self):
        pass

    def loadAlgorithms(self):
        # QGIS takes ownership of algorithm instances added to the provider.
        # Recreate them on every load instead of reusing wrappers that may
        # already have been deleted after registry/plugin refreshes.
        for algorithm_class in self.algorithm_classes:
            self.addAlgorithm(algorithm_class())

    def id(self):
        return 'QProto'

    def name(self):
        return self.tr('QPROTO')

    def longName(self):
        return self.name()

    def icon(self):
        return QIcon(os.path.join(pluginPath, "icon.svg"))
