Skip to content
Permalink
Browse files
Move format handling flags to QgsAlgorithmProvider
  • Loading branch information
nyalldawson committed Apr 3, 2017
1 parent 6e8a696 commit d2a242aa9506534faf66d7a7e9089105dcf0aeb8
@@ -66,6 +66,35 @@ class QgsProcessingProvider
missing external dependencies).
%End

virtual QStringList supportedOutputRasterLayerExtensions() const;
%Docstring
Returns a list of the raster format file extensions supported by this provider.
\see supportedOutputVectorLayerExtensions()
\see supportedOutputTableExtensions()
%End

virtual QStringList supportedOutputVectorLayerExtensions() const;
%Docstring
Returns a list of the vector format file extensions supported by this provider.
\see supportedOutputRasterLayerExtensions()
\see supportedOutputTableExtensions()
\see supportsNonFileBasedOutput()
%End

virtual QStringList supportedOutputTableExtensions() const;
%Docstring
Returns a list of the table format file extensions supported by this provider.
\see supportedOutputRasterLayerExtensions()
\see supportedOutputVectorLayerExtensions()
%End

virtual bool supportsNonFileBasedOutput() const;
%Docstring
Returns true if the provider supports non-file based outputs (such as memory layers
or direct database outputs).
\see supportedOutputVectorLayerExtensions()
%End

private:
QgsProcessingProvider( const QgsProcessingProvider &other );
};
@@ -147,5 +147,5 @@ def createAlgsList(self):
OffsetCurve(), Ogr2OgrTableToPostGisList(), OgrSql(),
]

def getSupportedOutputRasterLayerExtensions(self):
def supportedOutputRasterLayerExtensions(self):
return GdalUtils.getSupportedRasterExtensions()
@@ -110,11 +110,8 @@ def icon(self):
def svgIconPath(self):
return QgsApplication.iconPath("providerGrass.svg")

def getSupportedOutputVectorLayerExtensions(self):
def supportedOutputVectorLayerExtensions(self):
return ['shp']

def getSupportedOutputRasterLayerExtensions(self):
return ['tif']

def canBeActivated(self):
return not bool(Grass7Utils.checkGrass7IsInstalled())
@@ -53,7 +53,7 @@ def processOutputs(alg):
else:
angles = ['']

ext = alg.provider.getSupportedOutputRasterLayerExtensions()[0]
ext = alg.provider.supportedOutputRasterLayerExtensions()[0]
for method in methodList:
out = alg.getOutputValue(u'output')
for angle in angles:
@@ -110,10 +110,10 @@ def name(self):
def id(self):
return 'saga'

def getSupportedOutputVectorLayerExtensions(self):
def supportedOutputVectorLayerExtensions(self):
return ['shp']

def getSupportedOutputRasterLayerExtensions(self):
def supportedOutputRasterLayerExtensions(self):
return ['sdat']

def getSupportedOutputTableLayerExtensions(self):
@@ -88,18 +88,6 @@ def unload(self):
name = 'ACTIVATE_' + self.id().upper().replace(' ', '_')
ProcessingConfig.removeSetting(name)

def getSupportedOutputRasterLayerExtensions(self):
return ['tif']

def getSupportedOutputVectorLayerExtensions(self):
return QgsVectorFileWriter.supportedFormatExtensions()

def getSupportedOutputTableExtensions(self):
return ['csv']

def supportsNonFileBasedOutput(self):
return False

def tr(self, string, context=''):
if context == '':
context = self.__class__.__name__
@@ -233,11 +233,11 @@ def getCompatibleFileName(self, alg):
"""

ext = self.value[self.value.rfind('.') + 1:]
if ext in alg.provider.getSupportedOutputRasterLayerExtensions():
if ext in alg.provider.supportedOutputRasterLayerExtensions():
return self.value
else:
if self.compatible is None:
supported = alg.provider.getSupportedOutputRasterLayerExtensions()
supported = alg.provider.supportedOutputRasterLayerExtensions()
default = ProcessingConfig.getSetting(ProcessingConfig.DEFAULT_OUTPUT_RASTER_LAYER_EXT, True)
ext = default if default in supported else supported[0]
self.compatible = getTempFilenameInTempFolder(self.name + '.' + ext)
@@ -275,12 +275,12 @@ def getCompatibleFileName(self, alg):
"""

ext = self.value[self.value.rfind('.') + 1:]
if ext in alg.provider.getSupportedOutputTableExtensions():
if ext in alg.provider.supportedOutputTableExtensions():
return self.value
else:
if self.compatible is None:
self.compatible = getTempFilenameInTempFolder(
self.name + '.' + alg.provider.getSupportedOutputTableExtensions()[0])
self.name + '.' + alg.provider.supportedOutputTableExtensions()[0])
return self.compatible

def getTableWriter(self, fields):
@@ -350,12 +350,12 @@ def getCompatibleFileName(self, alg):
generate the output result.
"""
ext = self.value[self.value.rfind('.') + 1:]
if ext in alg.provider.getSupportedOutputVectorLayerExtensions():
if ext in alg.provider.supportedOutputVectorLayerExtensions():
return self.value
else:
if self.compatible is None:
default = self.getDefaultFileExtension()
supported = alg.provider.getSupportedOutputVectorLayerExtensions()
supported = alg.provider.supportedOutputVectorLayerExtensions()
ext = default if default in supported else supported[0]
self.compatible = getTempFilenameInTempFolder(self.name + '.' + ext)
return self.compatible
@@ -76,11 +76,6 @@ def getSupportedOutputRasterLayerExtensions():
return allexts


def getSupportedOutputTableExtensions():
exts = ['csv']
return exts


def getRasterLayers(sorting=True):
layers = QgsProject.instance().layerTreeRoot().findLayers()
raster = [lay.layer() for lay in layers if lay.layer() is not None and canUseRasterLayer(lay.layer())]
@@ -17,6 +17,7 @@

#include "qgsprocessingprovider.h"
#include "qgsapplication.h"
#include "qgsvectorfilewriter.h"

QIcon QgsProcessingProvider::icon() const
{
@@ -27,3 +28,8 @@ QString QgsProcessingProvider::svgIconPath() const
{
return QgsApplication::iconPath( "processingAlgorithm.svg" );
}

QStringList QgsProcessingProvider::supportedOutputVectorLayerExtensions() const
{
return QgsVectorFileWriter::supportedFormatExtensions();
}
@@ -79,6 +79,35 @@ class CORE_EXPORT QgsProcessingProvider
*/
virtual bool canBeActivated() const { return true; }

/**
* Returns a list of the raster format file extensions supported by this provider.
* \see supportedOutputVectorLayerExtensions()
* \see supportedOutputTableExtensions()
*/
virtual QStringList supportedOutputRasterLayerExtensions() const { return QStringList() << QStringLiteral( "tif" ); }

/**
* Returns a list of the vector format file extensions supported by this provider.
* \see supportedOutputRasterLayerExtensions()
* \see supportedOutputTableExtensions()
* \see supportsNonFileBasedOutput()
*/
virtual QStringList supportedOutputVectorLayerExtensions() const;

/**
* Returns a list of the table format file extensions supported by this provider.
* \see supportedOutputRasterLayerExtensions()
* \see supportedOutputVectorLayerExtensions()
*/
virtual QStringList supportedOutputTableExtensions() const { return QStringList() << QStringLiteral( "csv" ); }

/**
* Returns true if the provider supports non-file based outputs (such as memory layers
* or direct database outputs).
* \see supportedOutputVectorLayerExtensions()
*/
virtual bool supportsNonFileBasedOutput() const { return false; }

private:

#ifdef SIP_RUN
@@ -16,6 +16,7 @@
***************************************************************************/

#include "qgsprocessingregistry.h"
#include "qgsvectorfilewriter.h"

QgsProcessingRegistry::QgsProcessingRegistry( QObject *parent SIP_TRANSFERTHIS )
: QObject( parent )
@@ -67,3 +68,4 @@ QgsProcessingProvider *QgsProcessingRegistry::providerById( const QString &id )
{
return mProviders.value( id, nullptr );
}

0 comments on commit d2a242a

Please sign in to comment.