Skip to content
Permalink
Browse files
Move flags (hide from toolbox, etc) to QgsProcessingAlgorithm
  • Loading branch information
nyalldawson committed Apr 3, 2017
1 parent 6987d7b commit e506ceb1f8d1c8f8084602f097426fc8be280000
@@ -6,6 +6,15 @@ class QgsProcessingAlgorithm

public:

enum Flag
{
FlagHideFromToolbox,
FlagHideFromModeler,
FlagSupportsBatch,
FlagDeprecated,
};
typedef QFlags<QgsProcessingAlgorithm::Flag> Flags;

QgsProcessingAlgorithm();
virtual ~QgsProcessingAlgorithm();

@@ -15,6 +24,6 @@ class QgsProcessingAlgorithm
virtual QIcon icon() const;
virtual QString svgIconPath() const;
virtual QString group() const;

virtual Flags flags() const;
};

QFlags<QgsProcessingAlgorithm::Flag> operator|(QgsProcessingAlgorithm::Flag f1, QFlags<QgsProcessingAlgorithm::Flag> f2);
@@ -32,7 +32,8 @@
import time

from qgis.PyQt.QtGui import QIcon
from qgis.core import QgsRasterLayer
from qgis.core import (QgsProcessingAlgorithm,
QgsRasterLayer)

from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.parameters import ParameterMultipleInput
@@ -55,13 +56,12 @@ class nviz7(GeoAlgorithm):
GRASS_REGION_EXTENT_PARAMETER = 'GRASS_REGION_PARAMETER'
GRASS_REGION_CELLSIZE_PARAMETER = 'GRASS_REGION_CELLSIZE_PARAMETER'

def __init__(self):
GeoAlgorithm.__init__(self)
self.showInModeler = False

def icon(self):
return QIcon(os.path.join(pluginPath, 'images', 'grass.png'))

def flags(self):
return QgsProcessingAlgorithm.FlagHideFromModeler

def name(self):
return 'nviz7'

@@ -32,7 +32,8 @@
from qgis.PyQt.QtGui import QIcon

from qgis.core import (QgsStatisticalSummary,
QgsFeatureRequest)
QgsFeatureRequest,
QgsProcessingAlgorithm)

from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.parameters import ParameterTable
@@ -67,10 +68,9 @@ class BasicStatisticsNumbers(GeoAlgorithm):
NULLVALUES = 'NULLVALUES'
IQR = 'IQR'

def __init__(self):
GeoAlgorithm.__init__(self)
def flags(self):
# this algorithm is deprecated - use BasicStatistics instead
self.showInToolbox = False
return QgsProcessingAlgorithm.FlagDeprecated

def icon(self):
return QIcon(os.path.join(pluginPath, 'images', 'ftools', 'basic_statistics.png'))
@@ -31,7 +31,8 @@

from qgis.PyQt.QtGui import QIcon

from qgis.core import (QgsStringStatisticalSummary,
from qgis.core import (QgsProcessingAlgorithm,
QgsStringStatisticalSummary,
QgsFeatureRequest)

from processing.core.GeoAlgorithm import GeoAlgorithm
@@ -60,10 +61,9 @@ class BasicStatisticsStrings(GeoAlgorithm):
MIN_VALUE = 'MIN_VALUE'
MAX_VALUE = 'MAX_VALUE'

def __init__(self):
GeoAlgorithm.__init__(self)
def flags(self):
# this algorithm is deprecated - use BasicStatistics instead
self.showInToolbox = False
return QgsProcessingAlgorithm.FlagDeprecated

def icon(self):
return QIcon(os.path.join(pluginPath, 'images', 'ftools', 'basic_statistics.png'))
@@ -29,7 +29,10 @@

from qgis.PyQt.QtGui import QIcon

from qgis.core import QgsGeometry, QgsFeature, QgsWkbTypes
from qgis.core import (QgsProcessingAlgorithm,
QgsGeometry,
QgsFeature,
QgsWkbTypes)

from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
@@ -45,10 +48,9 @@ class PolygonCentroids(GeoAlgorithm):
INPUT_LAYER = 'INPUT_LAYER'
OUTPUT_LAYER = 'OUTPUT_LAYER'

def __init__(self):
GeoAlgorithm.__init__(self)
def flags(self):
# this algorithm is deprecated - use Centroids instead
self.showInToolbox = False
return QgsProcessingAlgorithm.FlagDeprecated

def icon(self):
return QIcon(os.path.join(pluginPath, 'images', 'ftools', 'centroids.png'))
@@ -27,7 +27,8 @@

__revision__ = '$Format:%H$'

from qgis.core import (QgsApplication,
from qgis.core import (QgsProcessingAlgorithm,
QgsApplication,
QgsFeatureRequest,
QgsFeature,
QgsGeometry,
@@ -47,10 +48,9 @@ class SplitLinesWithLines(GeoAlgorithm):

OUTPUT = 'OUTPUT'

def __init__(self):
GeoAlgorithm.__init__(self)
def flags(self):
# this algorithm is deprecated - use SplitWithLines instead
self.showInToolbox = False
return QgsProcessingAlgorithm.FlagDeprecated

def icon(self):
return QgsApplication.getThemeIcon("/providerQgis.svg")
@@ -31,7 +31,14 @@
from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtCore import QVariant

from qgis.core import QgsRectangle, QgsFields, QgsField, QgsFeature, QgsGeometry, QgsPoint, QgsWkbTypes
from qgis.core import (QgsProcessingAlgorithm,
QgsRectangle,
QgsFields,
QgsField,
QgsFeature,
QgsGeometry,
QgsPoint,
QgsWkbTypes)
from qgis.utils import iface

from processing.core.GeoAlgorithm import GeoAlgorithm
@@ -50,10 +57,9 @@ class VectorGridLines(GeoAlgorithm):
STEP_Y = 'STEP_Y'
OUTPUT = 'OUTPUT'

def __init__(self):
GeoAlgorithm.__init__(self)
def flags(self):
# this algorithm is deprecated - use GridLine instead
self.showInToolbox = False
return QgsProcessingAlgorithm.FlagDeprecated

def icon(self):
return QIcon(os.path.join(pluginPath, 'images', 'ftools', 'vector_grid.png'))
@@ -31,7 +31,14 @@
from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtCore import QVariant

from qgis.core import QgsRectangle, QgsFields, QgsField, QgsFeature, QgsGeometry, QgsPoint, QgsWkbTypes
from qgis.core import (QgsProcessingAlgorithm,
QgsRectangle,
QgsFields,
QgsField,
QgsFeature,
QgsGeometry,
QgsPoint,
QgsWkbTypes)
from qgis.utils import iface

from processing.core.GeoAlgorithm import GeoAlgorithm
@@ -50,10 +57,9 @@ class VectorGridPolygons(GeoAlgorithm):
STEP_Y = 'STEP_Y'
OUTPUT = 'OUTPUT'

def __init__(self):
GeoAlgorithm.__init__(self)
def flags(self):
# this algorithm is deprecated - use GridPolygon instead
self.showInToolbox = False
return QgsProcessingAlgorithm.FlagDeprecated

def icon(self):
return QIcon(os.path.join(pluginPath, 'images', 'ftools', 'vector_grid.png'))
@@ -65,14 +65,6 @@ def __init__(self):
# loading output layers
self.crs = None

# Change any of the following if your algorithm should not
# appear in the toolbox or modeler
self.showInToolbox = True
self.showInModeler = True

# False if it should not be run a a batch process
self.canRunInBatchMode = True

# To be set by the provider when it loads the algorithm
self.provider = None

@@ -33,7 +33,8 @@
from qgis.PyQt.QtCore import Qt, QCoreApplication
from qgis.PyQt.QtWidgets import QMenu, QAction, QTreeWidgetItem, QLabel, QMessageBox
from qgis.utils import iface
from qgis.core import QgsApplication
from qgis.core import (QgsApplication,
QgsProcessingAlgorithm)

from processing.gui.Postprocessing import handleAlgorithmResults
from processing.core.Processing import Processing
@@ -193,7 +194,7 @@ def showPopupMenu(self, point):
executeAction = QAction(self.tr('Execute'), self.algorithmTree)
executeAction.triggered.connect(self.executeAlgorithm)
popupmenu.addAction(executeAction)
if alg.canRunInBatchMode:
if alg.flags() & QgsProcessingAlgorithm.FlagSupportsBatch:
executeBatchAction = QAction(
self.tr('Execute as batch process'),
self.algorithmTree)
@@ -398,7 +399,7 @@ def populate(self):

# Add algorithms
for alg in algs:
if not alg.showInToolbox:
if alg.flags() & QgsProcessingAlgorithm.FlagHideFromToolbox:
continue
if alg.group() in groups:
groupItem = groups[alg.group()]
@@ -36,7 +36,9 @@
from qgis.PyQt.QtGui import QIcon, QImage, QPainter, QKeySequence
from qgis.PyQt.QtSvg import QSvgGenerator
from qgis.PyQt.QtPrintSupport import QPrinter
from qgis.core import QgsApplication, QgsSettings
from qgis.core import (QgsApplication,
QgsProcessingAlgorithm,
QgsSettings)
from qgis.gui import QgsMessageBar
from processing.core.ProcessingConfig import ProcessingConfig
from processing.core.ProcessingLog import ProcessingLog
@@ -613,7 +615,7 @@ def fillAlgorithmTreeUsingProviders(self):

# Add algorithms
for alg in algs:
if not alg.showInModeler:
if alg.flags() & QgsProcessingAlgorithm.FlagHideFromModeler:
continue
if alg.commandLineName() == self.alg.commandLineName():
continue
@@ -27,6 +27,7 @@


import os
from qgis.core import (QgsProcessingAlgorithm)
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.alglist import algList
import json
@@ -44,6 +45,9 @@ def __init__(self, descriptionFile):
def group(self):
return self._group

def flags(self):
return QgsProcessingAlgorithm.FlagHideFromModeler

def getCopy(self):
newone = PreconfiguredAlgorithm(self.descriptionFile)
newone.outputs = []
@@ -58,8 +62,6 @@ def commandLineName(self):
def defineCharacteristics(self):
self.name = self.description["name"]
self._group = self.description["group"]
self.canRunInBatchMode = False
self.showInModeler = False

def execute(self, feedback):
self.alg = algList.getAlgorithm(self.description["algname"]).getCopy()
@@ -31,6 +31,7 @@
import json
from qgis.core import (QgsExpressionContextUtils,
QgsExpressionContext,
QgsProcessingAlgorithm,
QgsProject,
QgsApplication)

@@ -59,6 +60,7 @@ def __init__(self, descriptionFile, script=None):
self._name = ''
self._display_name = ''
self._group = ''
self._flags = 0

self.script = script
self.allowEdit = True
@@ -86,6 +88,9 @@ def displayName(self):
def group(self):
return self._group

def flags(self):
return self._flags

def svgIconPath(self):
return QgsApplication.iconPath("processingScript.svg")

@@ -107,8 +112,7 @@ def defineCharacteristicsFromFile(self):
self.script += line
line = lines.readline()
if self._group == self.tr('[Test scripts]', 'ScriptAlgorithm'):
self.showInModeler = False
self.showInToolbox = False
self._flags = QgsProcessingAlgorithm.FlagHideFromToolbox | QgsProcessingAlgorithm.FlagHideFromModeler

def defineCharacteristicsFromScript(self):
lines = self.script.split('\n')
@@ -139,7 +143,7 @@ def processParameterLine(self, line):
line = line.replace('#', '')

if line == "nomodeler":
self.showInModeler = False
self._flags = self._flags | QgsProcessingAlgorithm.FlagHideFromModeler
return
if line == "nocrswarning":
self.noCRSWarning = True
@@ -27,3 +27,8 @@ QString QgsProcessingAlgorithm::svgIconPath() const
{
return QgsApplication::iconPath( "processingAlgorithm.svg" );
}

QgsProcessingAlgorithm::Flags QgsProcessingAlgorithm::flags() const
{
return FlagSupportsBatch;
}
@@ -33,6 +33,16 @@ class CORE_EXPORT QgsProcessingAlgorithm
{
public:

//! Flags indicating how and when an algorithm operates and should be exposed to users
enum Flag
{
FlagHideFromToolbox = 1 << 1, //!< Algorithm should be hidden from the toolbox
FlagHideFromModeler = 1 << 2, //!< Algorithm should be hidden from the modeler
FlagSupportsBatch = 1 << 3, //!< Algorithm supports batch mode
FlagDeprecated = FlagHideFromToolbox | FlagHideFromModeler, //!< Algorithm is deprecated
};
Q_DECLARE_FLAGS( Flags, Flag )

/**
* Constructor for QgsProcessingAlgorithm.
*/
@@ -82,7 +92,13 @@ class CORE_EXPORT QgsProcessingAlgorithm
*/
virtual QString group() const { return QString(); }

/**
* Returns the flags indicating how and when the algorithm operates and should be exposed to users.
*/
virtual Flags flags() const;

};
Q_DECLARE_OPERATORS_FOR_FLAGS( QgsProcessingAlgorithm::Flags )

#endif // QGSPROCESSINGALGORITHM_H

0 comments on commit e506ceb

Please sign in to comment.