LCOV - code coverage report
Current view: top level - core/processing - qgsprocessingprovider.h (source / functions) Hit Total Coverage
Test: coverage.info.cleaned Lines: 0 6 0.0 %
Date: 2021-04-10 08:29:14 Functions: 0 0 -
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /***************************************************************************
       2                 :            :                          qgsprocessingprovider.h
       3                 :            :                          ------------------------
       4                 :            :     begin                : December 2016
       5                 :            :     copyright            : (C) 2016 by Nyall Dawson
       6                 :            :     email                : nyall dot dawson at gmail dot com
       7                 :            :  ***************************************************************************/
       8                 :            : 
       9                 :            : /***************************************************************************
      10                 :            :  *                                                                         *
      11                 :            :  *   This program is free software; you can redistribute it and/or modify  *
      12                 :            :  *   it under the terms of the GNU General Public License as published by  *
      13                 :            :  *   the Free Software Foundation; either version 2 of the License, or     *
      14                 :            :  *   (at your option) any later version.                                   *
      15                 :            :  *                                                                         *
      16                 :            :  ***************************************************************************/
      17                 :            : 
      18                 :            : #ifndef QGSPROCESSINGPROVIDER_H
      19                 :            : #define QGSPROCESSINGPROVIDER_H
      20                 :            : 
      21                 :            : #include "qgis_core.h"
      22                 :            : #include "qgis.h"
      23                 :            : #include "qgsprocessingalgorithm.h"
      24                 :            : #include <QIcon>
      25                 :            : 
      26                 :            : /**
      27                 :            :  * \class QgsProcessingProvider
      28                 :            :  * \ingroup core
      29                 :            :  * \brief Abstract base class for processing providers.
      30                 :            :  *
      31                 :            :  * An algorithm provider is a set of related algorithms, typically from the same external application or related
      32                 :            :  * to a common area of analysis.
      33                 :            :  * \since QGIS 3.0
      34                 :            :  */
      35                 :            : class CORE_EXPORT QgsProcessingProvider : public QObject
      36                 :            : {
      37                 :          0 :     Q_OBJECT
      38                 :            : 
      39                 :            :   public:
      40                 :            : 
      41                 :            :     /**
      42                 :            :      * Flags indicating how and when an provider operates and should be exposed to users
      43                 :            :      * \since QGIS 3.14
      44                 :            :      */
      45                 :            :     enum Flag
      46                 :            :     {
      47                 :            :       FlagDeemphasiseSearchResults = 1 << 1, //!< Algorithms should be de-emphasised in the search results when searching for algorithms. Use for low-priority providers or those with substantial known issues.
      48                 :            :     };
      49                 :            :     Q_DECLARE_FLAGS( Flags, Flag )
      50                 :            : 
      51                 :            :     /**
      52                 :            :      * Constructor for QgsProcessingProvider.
      53                 :            :      */
      54                 :            :     QgsProcessingProvider( QObject *parent SIP_TRANSFERTHIS = nullptr );
      55                 :            : 
      56                 :            :     ~QgsProcessingProvider() override;
      57                 :            : 
      58                 :            :     //! Providers cannot be copied
      59                 :            :     QgsProcessingProvider( const QgsProcessingProvider &other ) = delete;
      60                 :            :     //! Providers cannot be copied
      61                 :            :     QgsProcessingProvider &operator=( const QgsProcessingProvider &other ) = delete;
      62                 :            : 
      63                 :            :     /**
      64                 :            :      * Returns an icon for the provider.
      65                 :            :      * \see svgIconPath()
      66                 :            :      */
      67                 :            :     virtual QIcon icon() const;
      68                 :            : 
      69                 :            :     /**
      70                 :            :      * Returns a path to an SVG version of the provider's icon.
      71                 :            :      * \see icon()
      72                 :            :      */
      73                 :            :     virtual QString svgIconPath() const;
      74                 :            : 
      75                 :            :     /**
      76                 :            :      * Returns the flags indicating how and when the provider operates and should be exposed to users.
      77                 :            :      * Default is no flags.
      78                 :            :      * \since QGIS 3.14
      79                 :            :      */
      80                 :            :     virtual Flags flags() const;
      81                 :            : 
      82                 :            :     /**
      83                 :            :      * Returns the unique provider id, used for identifying the provider. This string
      84                 :            :      * should be a unique, short, character only string, eg "qgis" or "gdal". This
      85                 :            :      * string should not be localised.
      86                 :            :      * \see name()
      87                 :            :      * \see helpId()
      88                 :            :      */
      89                 :            :     virtual QString id() const = 0;
      90                 :            : 
      91                 :            :     /**
      92                 :            :      * Returns the provider help id string, used for creating QgsHelp urls for algorithms
      93                 :            :      * belong to this provider. By default, this returns an empty string, meaning that
      94                 :            :      * no QgsHelp url should be created for the provider's algorithms.
      95                 :            :      * \see id()
      96                 :            :      */
      97                 :            :     virtual QString helpId() const;
      98                 :            : 
      99                 :            :     /**
     100                 :            :      * Returns the provider name, which is used to describe the provider within the GUI.
     101                 :            :      * This string should be short (e.g. "Lastools") and localised.
     102                 :            :      * \see longName()
     103                 :            :      * \see id()
     104                 :            :      */
     105                 :            :     virtual QString name() const = 0;
     106                 :            : 
     107                 :            :     /**
     108                 :            :      * Returns the longer version of the provider name, which can include extra details
     109                 :            :      * such as version numbers. E.g. "Lastools LIDAR tools (version 2.2.1)".
     110                 :            :      * This string should be localised.
     111                 :            :      *
     112                 :            :      * The default implementation returns the same string as name().
     113                 :            :      *
     114                 :            :      * \see name()
     115                 :            :      * \see id()
     116                 :            :      */
     117                 :            :     virtual QString longName() const;
     118                 :            : 
     119                 :            :     /**
     120                 :            :      * Returns a version information string for the provider, or an empty string if this
     121                 :            :      * is not applicable (e.g. for inbuilt Processing providers).
     122                 :            :      *
     123                 :            :      * For plugin based providers, this should return the plugin's version identifier.
     124                 :            :      *
     125                 :            :      * \since QGIS 3.8
     126                 :            :      */
     127                 :            :     virtual QString versionInfo() const;
     128                 :            : 
     129                 :            :     /**
     130                 :            :      * Returns TRUE if the provider can be activated, or FALSE if it cannot be activated (e.g. due to
     131                 :            :      * missing external dependencies).
     132                 :            :      * \see isActive()
     133                 :            :      */
     134                 :          0 :     virtual bool canBeActivated() const { return true; }
     135                 :            : 
     136                 :            :     /**
     137                 :            :      * Returns an optional warning message to show users when running algorithms from this provider.
     138                 :            :      *
     139                 :            :      * This can be used to return a translated warning message which should be shown to users
     140                 :            :      * of this provider. It's intended for use in cases such as a provider which relies on a 3rd-party
     141                 :            :      * backend, where the version of the backend software is not officially supported, or for
     142                 :            :      * alerting users to providers in a "beta" or "untrustworthy" state.
     143                 :            :      *
     144                 :            :      * \since QGIS 3.10.1
     145                 :            :      */
     146                 :          0 :     virtual QString warningMessage() const { return QString(); }
     147                 :            : 
     148                 :            :     /**
     149                 :            :      * Returns TRUE if the provider is active and able to run algorithms.
     150                 :            :      */
     151                 :          0 :     virtual bool isActive() const { return true; }
     152                 :            : 
     153                 :            :     /**
     154                 :            :      * Returns a list of the raster format file extensions supported by this provider.
     155                 :            :      * \see supportedOutputVectorLayerExtensions()
     156                 :            :      */
     157                 :            :     virtual QStringList supportedOutputRasterLayerExtensions() const;
     158                 :            : 
     159                 :            :     /**
     160                 :            :      * Returns a list of the vector format file extensions supported by this provider.
     161                 :            :      * \see supportedOutputTableExtensions()
     162                 :            :      * \see defaultVectorFileExtension()
     163                 :            :      * \see supportedOutputRasterLayerExtensions()
     164                 :            :      * \see supportsNonFileBasedOutput()
     165                 :            :      */
     166                 :            :     virtual QStringList supportedOutputVectorLayerExtensions() const;
     167                 :            : 
     168                 :            :     /**
     169                 :            :      * Returns a list of the table (geometry-less vector layers) file extensions supported by this provider.
     170                 :            :      *
     171                 :            :      * By default this is the same as supportedOutputVectorLayerExtensions(). Providers which utilize different
     172                 :            :      * formats for geometry-less layers can override this method to return a different list of supported formats.
     173                 :            :      *
     174                 :            :      * \see supportedOutputVectorLayerExtensions()
     175                 :            :      * \see defaultVectorFileExtension()
     176                 :            :      * \see supportedOutputRasterLayerExtensions()
     177                 :            :      * \see supportsNonFileBasedOutput()
     178                 :            :      *
     179                 :            :      * \since QGIS 3.4.3
     180                 :            :      */
     181                 :            :     virtual QStringList supportedOutputTableExtensions() const;
     182                 :            : 
     183                 :            :     /**
     184                 :            :      * Returns TRUE if the specified \a outputValue is of a supported file format for the given destination \a parameter.
     185                 :            :      *
     186                 :            :      * If the output value is not supported, \a error will be set to a descriptive message explaining why.
     187                 :            :      *
     188                 :            :      * \since QGIS 3.6
     189                 :            :     */
     190                 :            :     virtual bool isSupportedOutputValue( const QVariant &outputValue, const QgsProcessingDestinationParameter *parameter, QgsProcessingContext &context, QString &error SIP_OUT ) const;
     191                 :            : 
     192                 :            :     /**
     193                 :            :      * Returns the default file extension to use for vector outputs created by the
     194                 :            :      * provider.
     195                 :            :      *
     196                 :            :      * If \a hasGeometry is TRUE then the output file format must have support for
     197                 :            :      * geometry. If \a hasGeometry is FALSE then non-spatial formats can be used.
     198                 :            :      *
     199                 :            :      * The default implementation returns the user's default Processing vector output format
     200                 :            :      * setting, if it's supported by the provider (see supportedOutputVectorLayerExtensions()).
     201                 :            :      * Otherwise the first reported supported vector format will be used.
     202                 :            :      *
     203                 :            :      * \see supportedOutputVectorLayerExtensions()
     204                 :            :      * \see defaultRasterFileExtension()
     205                 :            :      */
     206                 :            :     virtual QString defaultVectorFileExtension( bool hasGeometry = true ) const;
     207                 :            : 
     208                 :            :     /**
     209                 :            :      * Returns the default file extension to use for raster outputs created by the
     210                 :            :      * provider.
     211                 :            :      *
     212                 :            :      * The default implementation returns the user's default Processing raster output format
     213                 :            :      * setting, if it's supported by the provider (see supportedOutputRasterLayerExtensions()).
     214                 :            :      * Otherwise the first reported supported raster format will be used.
     215                 :            :      *
     216                 :            :      * \see supportedOutputRasterLayerExtensions()
     217                 :            :      * \see defaultVectorFileExtension()
     218                 :            :      */
     219                 :            :     virtual QString defaultRasterFileExtension() const;
     220                 :            : 
     221                 :            :     /**
     222                 :            :      * Returns TRUE if the provider supports non-file based outputs (such as memory layers
     223                 :            :      * or direct database outputs). If a provider returns FALSE for this method than it
     224                 :            :      * indicates that none of the outputs from any of the provider's algorithms have
     225                 :            :      * support for non-file based outputs. Returning TRUE indicates that the algorithm's
     226                 :            :      * parameters will each individually declare their non-file based support.
     227                 :            :      *
     228                 :            :      * The default behavior for providers is to support non-file based outputs, and most
     229                 :            :      * providers which rely solely on QGIS API (and which do not depend on third-party scripts
     230                 :            :      * or external dependencies) will automatically support this.
     231                 :            :      *
     232                 :            :      * \see supportedOutputVectorLayerExtensions()
     233                 :            :      */
     234                 :            :     virtual bool supportsNonFileBasedOutput() const;
     235                 :            : 
     236                 :            :     /**
     237                 :            :      * Loads the provider. This will be called when the plugin is being loaded, and any general
     238                 :            :      * setup actions should occur in an overridden version of this method.
     239                 :            :      * Subclasses should not individually load any algorithms in their load() implementations, as that must
     240                 :            :      * occur within the loadAlgorithms() method. Instead, subclasses should call refreshAlgorithms()
     241                 :            :      * from any overloaded load() method to trigger an initial load of the provider's algorithms.
     242                 :            :      * \returns TRUE if provider could be successfully loaded
     243                 :            :      * \see unload()
     244                 :            :      */
     245                 :          0 :     virtual bool load() { refreshAlgorithms(); return true; }
     246                 :            : 
     247                 :            :     /**
     248                 :            :      * Unloads the provider. Any tear-down steps required by the provider should be implemented here.
     249                 :            :      * \see load()
     250                 :            :      */
     251                 :          0 :     virtual void unload() {}
     252                 :            : 
     253                 :            :     /**
     254                 :            :      * Refreshes the algorithms available from the provider, causing it to re-populate with all associated algorithms.
     255                 :            :      */
     256                 :            :     void refreshAlgorithms();
     257                 :            : 
     258                 :            :     /**
     259                 :            :      * Returns a list of algorithms supplied by this provider.
     260                 :            :      * \see algorithm()
     261                 :            :      */
     262                 :            :     QList< const QgsProcessingAlgorithm * > algorithms() const;
     263                 :            : 
     264                 :            :     /**
     265                 :            :      * Returns the matching algorithm by \a name, or NULLPTR if no matching
     266                 :            :      * algorithm is contained by this provider.
     267                 :            :      * \see algorithms()
     268                 :            :      */
     269                 :            :     const QgsProcessingAlgorithm *algorithm( const QString &name ) const;
     270                 :            : 
     271                 :            :   signals:
     272                 :            : 
     273                 :            :     /**
     274                 :            :      * Emitted when the provider has loaded (or refreshed) its list of available
     275                 :            :      * algorithms.
     276                 :            :      * \see refreshAlgorithms()
     277                 :            :      */
     278                 :            :     void algorithmsLoaded();
     279                 :            : 
     280                 :            :   protected:
     281                 :            : 
     282                 :            :     /**
     283                 :            :      * Loads all algorithms belonging to this provider. Subclasses should implement this, calling
     284                 :            :      * addAlgorithm() to register all their associated algorithms.
     285                 :            :      */
     286                 :            :     virtual void loadAlgorithms() = 0;
     287                 :            : 
     288                 :            :     /**
     289                 :            :      * Adds an \a algorithm to the provider. Ownership of the algorithm is transferred to the provider.
     290                 :            :      */
     291                 :            :     bool addAlgorithm( QgsProcessingAlgorithm *algorithm SIP_TRANSFER );
     292                 :            : 
     293                 :            :   private:
     294                 :            : 
     295                 :            :     QMap< QString, const QgsProcessingAlgorithm * > mAlgorithms;
     296                 :            : 
     297                 :            : #ifdef SIP_RUN
     298                 :            :     QgsProcessingProvider( const QgsProcessingProvider &other );
     299                 :            : #endif
     300                 :            : };
     301                 :            : 
     302                 :            : Q_DECLARE_OPERATORS_FOR_FLAGS( QgsProcessingProvider::Flags )
     303                 :            : 
     304                 :            : #endif // QGSPROCESSINGPROVIDER_H
     305                 :            : 
     306                 :            : 

Generated by: LCOV version 1.14