Skip to content
Permalink
Browse files
Always return const algorithms, since algorithms should not be modified
  • Loading branch information
nyalldawson committed Apr 7, 2017
1 parent 5a6f11d commit 69c31a2d710df0fc6670d81706a4ee5e5bfbfbc0
@@ -123,15 +123,15 @@ class QgsProcessingProvider : QObject
Refreshes the algorithms available from the provider, causing it to re-populate with all associated algorithms.
%End

QList< QgsProcessingAlgorithm * > algorithms() const;
QList< const QgsProcessingAlgorithm * > algorithms() const;
%Docstring
Returns a list of algorithms supplied by this provider.
\see algorithm()
%End

QgsProcessingAlgorithm *algorithm( const QString &name ) const;
const QgsProcessingAlgorithm *algorithm( const QString &name ) const;
%Docstring
Returns the matching algorithm by name, or a nullptr if no matching
Returns the matching algorithm by name, or a None if no matching
algorithm is contained by this provider.
\see algorithms()
%End
@@ -46,7 +46,7 @@ class QgsProcessingRegistry : QObject
and the provider's parent will be set to the registry.
Returns false if the provider could not be added (eg if a provider with a duplicate ID already exists
in the registry).
Adding a provider to the registry automatically triggers the providers QgsProcessingProvider::load()
Adding a provider to the registry automatically triggers the providers QgsProcessingProvider.load()
method to populate the provider with algorithms.
\see removeProvider()
%End
@@ -70,15 +70,15 @@ class QgsProcessingRegistry : QObject
Returns a matching provider by provider ID.
%End

QList< QgsProcessingAlgorithm * > algorithms() const;
QList< const QgsProcessingAlgorithm *> algorithms() const;
%Docstring
Returns a list of all available algorithms from registered providers.
\see algorithmById()
%End

QgsProcessingAlgorithm *algorithmById( const QString &id ) const;
const QgsProcessingAlgorithm *algorithmById( const QString &id ) const;
%Docstring
Finds an algorithm by its ID. If no matching algorithm is found, a nullptr
Finds an algorithm by its ID. If no matching algorithm is found, a None
is returned.
\see algorithms()
%End
@@ -44,21 +44,15 @@ void QgsProcessingProvider::refreshAlgorithms()
qDeleteAll( mAlgorithms );
mAlgorithms.clear();
loadAlgorithms();

QMap< QString, QgsProcessingAlgorithm * >::const_iterator it = mAlgorithms.constBegin();
for ( ; it != mAlgorithms.constEnd(); ++it )
{
it.value()->setProvider( this );
}
emit algorithmsLoaded();
}

QList<QgsProcessingAlgorithm *> QgsProcessingProvider::algorithms() const
QList<const QgsProcessingAlgorithm *> QgsProcessingProvider::algorithms() const
{
return mAlgorithms.values();
}

QgsProcessingAlgorithm *QgsProcessingProvider::algorithm( const QString &name ) const
const QgsProcessingAlgorithm *QgsProcessingProvider::algorithm( const QString &name ) const
{
return mAlgorithms.value( name );
}
@@ -71,6 +65,7 @@ bool QgsProcessingProvider::addAlgorithm( QgsProcessingAlgorithm *algorithm )
if ( mAlgorithms.contains( algorithm->name() ) )
return false;

algorithm->setProvider( this );
mAlgorithms.insert( algorithm->name(), algorithm );
return true;
}
@@ -143,14 +143,14 @@ class CORE_EXPORT QgsProcessingProvider : public QObject
* Returns a list of algorithms supplied by this provider.
* \see algorithm()
*/
QList< QgsProcessingAlgorithm * > algorithms() const;
QList< const QgsProcessingAlgorithm * > algorithms() const;

/**
* Returns the matching algorithm by \a name, or a nullptr if no matching
* algorithm is contained by this provider.
* \see algorithms()
*/
QgsProcessingAlgorithm *algorithm( const QString &name ) const;
const QgsProcessingAlgorithm *algorithm( const QString &name ) const;

signals:

@@ -176,7 +176,7 @@ class CORE_EXPORT QgsProcessingProvider : public QObject

private:

QMap< QString, QgsProcessingAlgorithm * > mAlgorithms;
QMap< QString, const QgsProcessingAlgorithm * > mAlgorithms;

#ifdef SIP_RUN
QgsProcessingProvider( const QgsProcessingProvider &other );
@@ -75,9 +75,9 @@ QgsProcessingProvider *QgsProcessingRegistry::providerById( const QString &id )
return mProviders.value( id, nullptr );
}

QList< QgsProcessingAlgorithm * > QgsProcessingRegistry::algorithms() const
QList< const QgsProcessingAlgorithm * > QgsProcessingRegistry::algorithms() const
{
QList< QgsProcessingAlgorithm * > algs;
QList< const QgsProcessingAlgorithm * > algs;
QMap<QString, QgsProcessingProvider *>::const_iterator it = mProviders.constBegin();
for ( ; it != mProviders.constEnd(); ++it )
{
@@ -86,12 +86,12 @@ QList< QgsProcessingAlgorithm * > QgsProcessingRegistry::algorithms() const
return algs;
}

QgsProcessingAlgorithm *QgsProcessingRegistry::algorithmById( const QString &id ) const
const QgsProcessingAlgorithm *QgsProcessingRegistry::algorithmById( const QString &id ) const
{
QMap<QString, QgsProcessingProvider *>::const_iterator it = mProviders.constBegin();
for ( ; it != mProviders.constEnd(); ++it )
{
Q_FOREACH ( QgsProcessingAlgorithm *alg, it.value()->algorithms() )
Q_FOREACH ( const QgsProcessingAlgorithm *alg, it.value()->algorithms() )
if ( alg->id() == id )
return alg;
}
@@ -90,14 +90,14 @@ class CORE_EXPORT QgsProcessingRegistry : public QObject
* Returns a list of all available algorithms from registered providers.
* \see algorithmById()
*/
QList< QgsProcessingAlgorithm * > algorithms() const;
QList< const QgsProcessingAlgorithm *> algorithms() const;

/**
* Finds an algorithm by its ID. If no matching algorithm is found, a nullptr
* is returned.
* \see algorithms()
*/
QgsProcessingAlgorithm *algorithmById( const QString &id ) const;
const QgsProcessingAlgorithm *algorithmById( const QString &id ) const;

signals:

0 comments on commit 69c31a2

Please sign in to comment.