25#include <QRegularExpressionMatch>
28#include "moc_qgsprocessingprovider.cpp"
30using namespace Qt::StringLiterals;
39 qDeleteAll( mAlgorithms );
75 QSet< QString > extensions;
77 for (
const QPair<QString, QString> &formatAndExt : std::as_const( formatAndExtensions ) )
79 if ( !extensions.contains( formatAndExt.second ) )
81 extensions.insert( formatAndExt.second );
82 res << formatAndExt.second;
96 QList<QPair<QString, QString>> res;
98 const thread_local QRegularExpression rx( u
"\\*\\.([a-zA-Z0-9]*)"_s );
102 const QString ext = format.filterString;
103 const QRegularExpressionMatch match = rx.match( ext );
104 if ( !match.hasMatch() )
107 const QString matched = match.captured( 1 );
108 res << QPair<QString, QString>( format.driverName, matched );
111 std::sort( res.begin(), res.end(), [](
const QPair<QString, QString> &a,
const QPair<QString, QString> &b ) ->
bool {
112 for ( const QString &tifExt : { u
"tif"_s, u
"tiff"_s } )
114 if ( a.second == tifExt )
116 if ( b.second == a.second )
118 if ( a.first ==
"GTiff"_L1 )
120 else if ( b.first ==
"GTiff"_L1 )
122 return a.first.toLower().localeAwareCompare( b.first.toLower() ) < 0;
126 else if ( b.second == tifExt )
130 if ( a.second ==
"gpkg"_L1 )
132 if ( b.second == a.second )
133 return a.first.toLower().localeAwareCompare( b.first.toLower() ) < 0;
136 else if ( b.second ==
"gpkg"_L1 )
139 return a.second.toLower().localeAwareCompare( b.second.toLower() ) < 0;
147 return QStringList();
157 qDeleteAll( mAlgorithms );
168 return mAlgorithms.values();
173 return mAlgorithms.value(
name );
181 if ( mAlgorithms.contains(
algorithm->name() ) )
189 algorithm->initAlgorithm( QVariantMap() );
211 if ( outputPath.isEmpty() )
219 error = tr(
"Missing parameter value %1" ).arg( parameter->
description() );
226 if ( outputPath.startsWith(
"memory:"_L1 ) )
230 error = tr(
"This algorithm only supports disk-based outputs" );
239 QMap<QString, QVariant> options;
240 bool useWriter =
false;
243 QgsProcessingUtils::parseDestinationString( outputPath, providerKey, uri, layerName, format, options, useWriter, extension );
245 if ( providerKey !=
"ogr"_L1 )
249 error = tr(
"This algorithm only supports disk-based outputs" );
257 error = tr(
"“.%1” files are not supported as outputs for this algorithm" ).arg( extension );
264 const QFileInfo fi( outputPath );
265 const QString extension = fi.suffix();
268 error = tr(
"“.%1” files are not supported as outputs for this algorithm" ).arg( extension );
275 const QFileInfo fi( outputPath );
276 const QString extension = fi.completeSuffix();
279 error = tr(
"“.%1” files are not supported as outputs for this algorithm" ).arg( extension );
286 const QFileInfo fi( outputPath );
287 const QString extension = fi.completeSuffix();
290 error = tr(
"“.%1” files are not supported as outputs for this algorithm" ).arg( extension );
306 if ( supportedExtensions.contains( userDefault, Qt::CaseInsensitive ) )
311 else if ( !supportedExtensions.empty() )
313 return supportedExtensions.at( 0 );
319 return hasGeometry ? u
"shp"_s : u
"dbf"_s;
328 for (
const QPair<QString, QString> &formatAndExt : std::as_const( formatAndExtensions ) )
330 if ( formatAndExt.first.compare( userDefault, Qt::CaseInsensitive ) == 0 )
337 if ( !formatAndExtensions.empty() )
339 return formatAndExtensions.at( 0 ).first;
352 if ( !extensions.isEmpty() )
353 return extensions[0];
363 if ( supportedExtensions.contains( userDefault, Qt::CaseInsensitive ) )
368 else if ( !supportedExtensions.empty() )
370 return supportedExtensions.at( 0 );
384 if ( supportedExtensions.contains( userDefault, Qt::CaseInsensitive ) )
389 else if ( !supportedExtensions.empty() )
391 return supportedExtensions.at( 0 );
QFlags< ProcessingProviderFlag > ProcessingProviderFlags
Flags indicating how and when an processing provider operates and should be exposed to users.
@ Optional
Parameter is optional.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
static QString iconPath(const QString &iconFile)
Returns path to the desired icon file.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true, const char *file=__builtin_FILE(), const char *function=__builtin_FUNCTION(), int line=__builtin_LINE(), Qgis::StringFormat format=Qgis::StringFormat::PlainText)
Adds a message to the log instance (and creates it if necessary).
Abstract base class for processing algorithms.
Contains information about the context in which a processing algorithm is executed.
Base class for all parameter definitions which represent file or layer destinations,...
QString description() const
Returns the description for the parameter.
virtual QString type() const =0
Unique parameter type name.
Qgis::ProcessingParameterFlags flags() const
Returns any flags associated with the parameter.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
static QString parameterAsOutputLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a output layer destination.
virtual QList< QPair< QString, QString > > supportedOutputRasterLayerFormatAndExtensions() const
Returns a list of (format, file extension) supported by this provider.
virtual QIcon icon() const
Returns an icon for the provider.
virtual QString defaultVectorFileExtension(bool hasGeometry=true) const
Returns the default file extension to use for vector outputs created by the provider.
virtual QString helpId() const
Returns the provider help id string, used for creating QgsHelp urls for algorithms belong to this pro...
virtual bool isSupportedOutputValue(const QVariant &outputValue, const QgsProcessingDestinationParameter *parameter, QgsProcessingContext &context, QString &error) const
Returns true if the specified outputValue is of a supported file format for the given destination par...
virtual QStringList supportedOutputTableExtensions() const
Returns a list of the table (geometry-less vector layers) file extensions supported by this provider.
~QgsProcessingProvider() override
const QgsProcessingAlgorithm * algorithm(const QString &name) const
Returns the matching algorithm by name, or nullptr if no matching algorithm is contained by this prov...
virtual Qgis::ProcessingProviderFlags flags() const
Returns the flags indicating how and when the provider operates and should be exposed to users.
virtual QString versionInfo() const
Returns a version information string for the provider, or an empty string if this is not applicable (...
virtual QStringList supportedOutputVectorLayerExtensions() const
Returns a list of the vector format file extensions supported by this provider.
virtual QString name() const =0
Returns the provider name, which is used to describe the provider within the GUI.
virtual QString defaultVectorTileFileExtension() const
Returns the default file extension to use for vector tile outputs created by the provider.
QStringList supportedOutputRasterLayerExtensions() const
Returns a list of the raster format file extensions supported by this provider.
virtual QStringList supportedOutputVectorTileLayerExtensions() const
Returns a list of the vector tile format file extensions supported by this provider.
QgsProcessingProvider(QObject *parent=nullptr)
Constructor for QgsProcessingProvider.
virtual bool isActive() const
Returns true if the provider is active and able to run algorithms.
virtual QStringList supportedOutputPointCloudLayerExtensions() const
Returns a list of the point cloud format file extensions supported by this provider.
QString defaultRasterFileExtension() const
Returns the default file extension to use for raster outputs created by the provider.
void algorithmsLoaded()
Emitted when the provider has loaded (or refreshed) its list of available algorithms.
virtual QString defaultRasterFileFormat() const
Returns the default file format to use for raster outputs created by the provider.
virtual QString svgIconPath() const
Returns a path to an SVG version of the provider's icon.
static QList< QPair< QString, QString > > supportedOutputRasterLayerFormatAndExtensionsDefault()
Returns a list of (format, file extension) supported by GDAL.
virtual void loadAlgorithms()=0
Loads all algorithms belonging to this provider.
void refreshAlgorithms()
Refreshes the algorithms available from the provider, causing it to re-populate with all associated a...
virtual QString longName() const
Returns the longer version of the provider name, which can include extra details such as version numb...
virtual bool supportsNonFileBasedOutput() const
Returns true if the provider supports non-file based outputs (such as memory layers or direct databas...
virtual QString defaultPointCloudFileExtension() const
Returns the default file extension to use for point cloud outputs created by the provider.
bool addAlgorithm(QgsProcessingAlgorithm *algorithm)
Adds an algorithm to the provider.
QList< const QgsProcessingAlgorithm * > algorithms() const
Returns a list of algorithms supplied by this provider.
static QString defaultVectorExtension()
Returns the default vector extension to use, in the absence of all other constraints (e....
static QString defaultRasterFormat()
Returns the default raster format to use, in the absence of all other constraints (e....
static QString defaultVectorTileExtension()
Returns the default vector tile extension to use, in the absence of all other constraints (e....
static QString defaultPointCloudExtension()
Returns the default point cloud extension to use, in the absence of all other constraints (e....
static QStringList extensionsForFormat(const QString &format)
Returns a list of known file extensions for the given GDAL driver format.
static QList< QgsRasterFileWriter::FilterFormatDetails > supportedFiltersAndFormats(RasterFormatOptions options=SortRecommended)
Returns a list or pairs, with format filter string as first element and GDAL format key as second ele...
static QStringList supportedFormatExtensions(VectorFormatOptions options=SortRecommended)
Returns a list of file extensions for supported formats, e.g "shp", "gpkg".