Skip to content
Permalink
Browse files
Port some processing dataobjects routines to c++
  • Loading branch information
nyalldawson committed Apr 5, 2017
1 parent d5f930a commit 8ffdb362cc94a818653fbe2b85c068f64073c6f2
@@ -277,6 +277,7 @@
%Include processing/qgsprocessingfeedback.sip
%Include processing/qgsprocessingprovider.sip
%Include processing/qgsprocessingregistry.sip
%Include processing/qgsprocessingutils.sip

%Include raster/qgsbilinearrasterresampler.sip
%Include raster/qgsbrightnesscontrastfilter.sip
@@ -0,0 +1,77 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/processing/qgsprocessingutils.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/







class QgsProcessingUtils
{
%Docstring
Utility functions for use with processing classes.
.. versionadded:: 3.0
%End

%TypeHeaderCode
#include "qgsprocessingutils.h"
%End

public:

static QList< QgsRasterLayer * > compatibleRasterLayers( QgsProject *project, bool sort = true );
%Docstring
Returns a list of raster layers from a project which are compatible with the processing
framework.

If the sort argument is true then the layers will be sorted by their QgsMapLayer.name()
value.
\see compatibleVectorLayers()
\see compatibleLayers()
%End

static QList< QgsVectorLayer * > compatibleVectorLayers( QgsProject *project,
const QList< QgsWkbTypes::GeometryType > &geometryTypes = QList< QgsWkbTypes::GeometryType >(),
bool sort = true );
%Docstring
Returns a list of vector layers from a project which are compatible with the processing
framework.

If the geometryTypes list is non-empty then the layers will be sorted so that only
layers with geometry types included in the list will be returned. Leaving the geometryTypes
list empty will cause all vector layers, regardless of their geometry type, to be returned.

If the sort argument is true then the layers will be sorted by their QgsMapLayer.name()
value.
\see compatibleRasterLayers()
\see compatibleLayers()
%End

static QList< QgsMapLayer * > compatibleLayers( QgsProject *project, bool sort = true );
%Docstring
Returns a list of map layers from a project which are compatible with the processing
framework.

If the sort argument is true then the layers will be sorted by their QgsMapLayer.name()
value.
\see compatibleRasterLayers()
\see compatibleVectorLayers()
%End

};



/************************************************************************
* This file has been generated automatically from *
* *
* src/core/processing/qgsprocessingutils.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -31,7 +31,9 @@
from qgis.PyQt.QtCore import QUrl

from qgis.core import (QgsApplication,
QgsVectorFileWriter)
QgsVectorFileWriter,
QgsProcessingUtils,
QgsProject)

from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.algs.gdal.GdalAlgorithmDialog import GdalAlgorithmDialog
@@ -58,7 +60,7 @@ def getCustomParametersDialog(self):

def processAlgorithm(self, feedback):
commands = self.getConsoleCommands()
layers = dataobjects.getVectorLayers()
layers = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance())
supported = QgsVectorFileWriter.supportedFormatExtensions()
for i, c in enumerate(commands):
for layer in layers:
@@ -34,7 +34,9 @@
from processing.tools import dataobjects
from processing.algs.gdal.GdalUtils import GdalUtils
from qgis.core import (QgsApplication,
QgsRectangle)
QgsRectangle,
QgsProcessingUtils,
QgsProject)
from qgis.analysis import QgsRasterCalculator, QgsRasterCalculatorEntry
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
from processing.algs.qgis.ui.RasterCalculatorWidgets import LayersListWidgetWrapper, ExpressionWidgetWrapper
@@ -108,7 +110,7 @@ def processAlgorithm(self, feedback):
layers = [dataobjects.getObjectFromUri(f) for f in layersValue.split(";")]
layersDict = {os.path.basename(lyr.source().split(".")[0]): lyr for lyr in layers}

for lyr in dataobjects.getRasterLayers():
for lyr in QgsProcessingUtils.compatibleRasterLayers(QgsProject.instance()):
name = lyr.name()
if (name + "@") in expression:
layersDict[name] = lyr
@@ -35,7 +35,9 @@
from qgis.PyQt.QtGui import QCursor
from qgis.core import (QgsExpressionContextUtils,
QgsProcessingFeedback,
QgsSettings)
QgsSettings,
QgsProcessingUtils,
QgsProject)
from qgis.gui import QgsEncodingFileDialog

from processing.core.ProcessingConfig import ProcessingConfig
@@ -101,7 +103,7 @@ def manageGui(self):
self.mOutputFieldTypeComboBox.blockSignals(False)

self.cmbInputLayer.blockSignals(True)
layers = dataobjects.getVectorLayers()
layers = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance())
for layer in layers:
self.cmbInputLayer.addItem(layer.name())
self.cmbInputLayer.blockSignals(False)
@@ -35,7 +35,10 @@
from qgis.PyQt.QtWidgets import QComboBox, QHeaderView, QLineEdit, QSpacerItem, QMessageBox, QSpinBox, QStyledItemDelegate
from qgis.PyQt.QtCore import QItemSelectionModel, QAbstractTableModel, QModelIndex, QVariant, Qt, pyqtSlot

from qgis.core import QgsExpression, QgsProject, QgsApplication
from qgis.core import (QgsExpression,
QgsProject,
QgsApplication,
QgsProcessingUtils)
from qgis.gui import QgsFieldExpressionWidget

from processing.gui.wrappers import WidgetWrapper, DIALOG_STANDARD, DIALOG_MODELER
@@ -473,8 +476,7 @@ def on_model_rowsInserted(self, parent, start, end):
self.model.index(end, self.model.columnCount() - 1))

def updateLayerCombo(self):
layers = dataobjects.getTables()
layers.sort(key=lambda lay: lay.name())
layers = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance())
for layer in layers:
self.layerCombo.addItem(layer.name(), layer)

@@ -496,7 +498,7 @@ def postInitialize(self, wrappers):
if wrapper.param.name == self.param.parent:
wrapper.widgetValueHasChanged.connect(self.parentLayerChanged)
break
layers = dataobjects.getTables()
layers = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance())
if len(layers) > 0:
# as first item in combobox is already selected
self.widget.setLayer(layers[0])
@@ -1,3 +1,5 @@
from qgis.core import (QgsProcessingUtils,
QgsProject)
from processing.gui.wrappers import WidgetWrapper, DIALOG_STANDARD, DIALOG_BATCH
from processing.tools import dataobjects
from processing.tools.system import userFolder
@@ -170,7 +172,7 @@ def _panel(self, options):

def createWidget(self):
if self.dialogType == DIALOG_STANDARD:
layers = dataobjects.getRasterLayers(sorting=False)
layers = QgsProcessingUtils.compatibleRasterLayers(QgsProject.instance(), False)
options = {}
for lyr in layers:
for n in range(lyr.bandCount()):
@@ -185,7 +187,7 @@ def createWidget(self):
return self._panel(options)

def refresh(self):
layers = dataobjects.getRasterLayers()
layers = QgsProcessingUtils.compatibleRasterLayers(QgsProject.instance())
options = {}
for lyr in layers:
for n in range(lyr.bandCount()):
@@ -229,11 +231,11 @@ def value(self):
return self.param.setValue(self.widget.selectedoptions)
else:
if self.param.datatype == dataobjects.TYPE_RASTER:
options = dataobjects.getRasterLayers(sorting=False)
options = QgsProcessingUtils.compatibleRasterLayers(QgsProject.instance(), False)
elif self.param.datatype == dataobjects.TYPE_VECTOR_ANY:
options = dataobjects.getVectorLayers(sorting=False)
options = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), [], False)
else:
options = dataobjects.getVectorLayers([self.param.datatype], sorting=False)
options = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), [self.param.datatype], False)
return [options[i] for i in self.widget.selectedoptions]
elif self.dialogType == DIALOG_BATCH:
return self.widget.getText()
@@ -35,7 +35,9 @@
from qgis.core import (QgsApplication,
QgsProcessingFeedback,
QgsSettings,
QgsProcessingAlgorithm)
QgsProcessingAlgorithm,
QgsProject,
QgsProcessingUtils)

from builtins import str
from builtins import object
@@ -339,7 +341,7 @@ def resolveOutputs(self):
raise GeoAlgorithmExecutionException(str(e))

def setOutputCRS(self):
layers = dataobjects.getAllLayers()
layers = QgsProcessingUtils.compatibleLayers(QgsProject.instance())
for param in self.parameters:
if isinstance(param, (ParameterRaster, ParameterVector, ParameterMultipleInput)):
if param.value:
@@ -365,7 +367,7 @@ def setOutputCRS(self):
pass

def resolveDataObjects(self):
layers = dataobjects.getAllLayers()
layers = QgsProcessingUtils.compatibleLayers(QgsProject.instance())
for param in self.parameters:
if isinstance(param, (ParameterRaster, ParameterVector, ParameterTable,
ParameterMultipleInput)):
@@ -319,7 +319,7 @@ def __init__(self, name='', description='', hidden=False, base_input=None, datat
def hasGeometry(self):
if self.base_layer is None:
return True
return dataobjects.canUseVectorLayer(self.base_layer, [-1])
return self.base_layer.hasGeometryType()

def getSupportedOutputVectorLayerExtensions(self):
exts = QgsVectorFileWriter.supportedFormatExtensions()
@@ -36,6 +36,7 @@
from copy import deepcopy
import numbers

from qgis.core import QgsProcessingUtils
from qgis.utils import iface
from qgis.PyQt.QtCore import QCoreApplication
from qgis.core import (QgsRasterLayer, QgsVectorLayer, QgsMapLayer, QgsCoordinateReferenceSystem,
@@ -90,7 +91,7 @@ def _expressionContext():


def _resolveLayers(value):
layers = dataobjects.getAllLayers()
layers = QgsProcessingUtils.compatibleLayers(QgsProject.instance())
if value:
inputlayers = value.split(';')
for i, inputlayer in enumerate(inputlayers):
@@ -727,7 +728,7 @@ def getAsString(self, value):
return str(value.dataProvider().dataSourceUri())
else:
s = str(value)
layers = dataobjects.getRasterLayers()
layers = QgsProcessingUtils.compatibleRasterLayers(QgsProject.instance())
for layer in layers:
if layer.name() == s:
return str(layer.dataProvider().dataSourceUri())
@@ -740,7 +741,10 @@ def getAsString(self, value):
return str(value.source())
else:
s = str(value)
layers = dataobjects.getVectorLayers([self.datatype])
if self.datatype != dataobjects.TYPE_VECTOR_ANY:
layers = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), [self.datatype], False)
else:
layers = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), [], False)
for layer in layers:
if layer.name() == s:
return str(layer.source())
@@ -1317,7 +1321,7 @@ def setValue(self, obj):
return True
else:
self.value = str(obj)
layers = dataobjects.getTables()
layers = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance())
for layer in layers:
if layer.name() == self.value or layer.source() == self.value:
source = str(layer.source())
@@ -30,7 +30,8 @@
from qgis.PyQt.QtWidgets import QMessageBox, QApplication, QPushButton, QWidget, QVBoxLayout, QSizePolicy
from qgis.PyQt.QtGui import QCursor, QColor, QPalette

from qgis.core import QgsProject
from qgis.core import (QgsProject,
QgsProcessingUtils)
from qgis.gui import QgsMessageBar
from qgis.utils import iface

@@ -113,7 +114,7 @@ def checkExtentCRS(self):
unmatchingCRS = False
hasExtent = False
projectCRS = iface.mapCanvas().mapSettings().destinationCrs()
layers = dataobjects.getAllLayers()
layers = QgsProcessingUtils.compatibleLayers(QgsProject.instance())
for param in self.alg.parameters:
if isinstance(param, (ParameterRaster, ParameterVector, ParameterMultipleInput)):
if param.value:
@@ -33,7 +33,10 @@
from qgis.PyQt.QtWidgets import QWidget, QHBoxLayout, QMenu, QPushButton, QLineEdit, QSizePolicy, QAction, QFileDialog
from qgis.PyQt.QtGui import QCursor

from qgis.core import QgsMapLayer, QgsSettings
from qgis.core import (QgsMapLayer,
QgsSettings,
QgsProject,
QgsProcessingUtils)

from processing.gui.MultipleInputDialog import MultipleInputDialog

@@ -99,15 +102,18 @@ def showLayerSelectionDialog(self):
if (isinstance(self.param, ParameterRaster) or
(isinstance(self.param, ParameterMultipleInput) and
self.param.datatype == dataobjects.TYPE_RASTER)):
layers = dataobjects.getRasterLayers()
layers = QgsProcessingUtils.compatibleRasterLayers(QgsProject.instance())
elif isinstance(self.param, ParameterTable):
layers = dataobjects.getTables()
layers = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance())
else:
if isinstance(self.param, ParameterVector):
datatype = self.param.datatype
else:
datatype = [self.param.datatype]
layers = dataobjects.getVectorLayers(datatype)
if datatype != dataobjects.TYPE_VECTOR_ANY:
layers = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), [datatype])
else:
layers = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance())

dlg = MultipleInputDialog([layer.name() for layer in layers])
dlg.exec_()
@@ -34,7 +34,8 @@

from qgis.gui import QgsMessageBar
from qgis.utils import iface

from qgis.core import (QgsProcessingUtils,
QgsProject)
from processing.gui.RectangleMapTool import RectangleMapTool
from processing.core.ProcessingConfig import ProcessingConfig
from processing.tools import dataobjects
@@ -108,7 +109,7 @@ def useLayerExtent(self):
extentsDict[CANVAS_KEY] = {"extent": iface.mapCanvas().extent(),
"authid": iface.mapCanvas().mapSettings().destinationCrs().authid()}
extents = [CANVAS_KEY]
layers = dataobjects.getAllLayers()
layers = QgsProcessingUtils.compatibleLayers(QgsProject.instance())
for layer in layers:
authid = layer.crs().authid()
if ProcessingConfig.getSetting(ProcessingConfig.SHOW_CRS_DEF) \
Loading

0 comments on commit 8ffdb36

Please sign in to comment.