mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-09 00:08:52 -04:00
[processing] Always use the same method to launder names
Ultimately avoids forced removal of _ characters in model parameter names
This commit is contained in:
parent
4905a55748
commit
dd89f3779a
@ -580,6 +580,15 @@ run through the designer.
|
|||||||
%Docstring
|
%Docstring
|
||||||
Given a child algorithm ID and output name, attempts to match it to a parameter definition from the overall model.
|
Given a child algorithm ID and output name, attempts to match it to a parameter definition from the overall model.
|
||||||
|
|
||||||
|
.. versionadded:: 3.26
|
||||||
|
%End
|
||||||
|
|
||||||
|
static QString safeName( const QString &name, bool capitalize = false );
|
||||||
|
%Docstring
|
||||||
|
Makes a name "safe", by replacing any non-alphanumeric characters with underscores.
|
||||||
|
|
||||||
|
If ``capitalize`` is ``True`` then the string will be converted to a camel case string.
|
||||||
|
|
||||||
.. versionadded:: 3.26
|
.. versionadded:: 3.26
|
||||||
%End
|
%End
|
||||||
|
|
||||||
|
@ -42,6 +42,7 @@ from qgis.core import (Qgis,
|
|||||||
QgsProcessing,
|
QgsProcessing,
|
||||||
QgsProject,
|
QgsProject,
|
||||||
QgsProcessingModelParameter,
|
QgsProcessingModelParameter,
|
||||||
|
QgsProcessingModelAlgorithm,
|
||||||
QgsSettings,
|
QgsSettings,
|
||||||
QgsProcessingContext,
|
QgsProcessingContext,
|
||||||
QgsFileUtils
|
QgsFileUtils
|
||||||
@ -272,9 +273,7 @@ class ModelerDialog(QgsModelDesignerDialog):
|
|||||||
Automatically generates and sets a new parameter's name, based on the parameter's
|
Automatically generates and sets a new parameter's name, based on the parameter's
|
||||||
description and ensuring that it is unique for the model.
|
description and ensuring that it is unique for the model.
|
||||||
"""
|
"""
|
||||||
validChars = \
|
safeName = QgsProcessingModelAlgorithm.safeName(parameter.description())
|
||||||
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
|
|
||||||
safeName = ''.join(c for c in parameter.description() if c in validChars)
|
|
||||||
name = safeName.lower()
|
name = safeName.lower()
|
||||||
i = 2
|
i = 2
|
||||||
while self.model().parameterDefinition(name):
|
while self.model().parameterDefinition(name):
|
||||||
|
@ -25,6 +25,7 @@ from qgis.PyQt.QtCore import QCoreApplication
|
|||||||
|
|
||||||
from qgis.core import (QgsProcessingParameterDefinition,
|
from qgis.core import (QgsProcessingParameterDefinition,
|
||||||
QgsProcessingModelOutput,
|
QgsProcessingModelOutput,
|
||||||
|
QgsProcessingModelAlgorithm,
|
||||||
QgsProject,
|
QgsProject,
|
||||||
Qgis)
|
Qgis)
|
||||||
from qgis.gui import (
|
from qgis.gui import (
|
||||||
@ -119,9 +120,7 @@ class ModelerInputGraphicItem(QgsModelParameterGraphicItem):
|
|||||||
comment = dlg.comments()
|
comment = dlg.comments()
|
||||||
comment_color = dlg.commentColor()
|
comment_color = dlg.commentColor()
|
||||||
|
|
||||||
validChars = \
|
safeName = QgsProcessingModelAlgorithm.safeName(new_param.description())
|
||||||
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
|
|
||||||
safeName = ''.join(c for c in new_param.description() if c in validChars)
|
|
||||||
new_param.setName(safeName.lower())
|
new_param.setName(safeName.lower())
|
||||||
|
|
||||||
if new_param is not None:
|
if new_param is not None:
|
||||||
|
@ -51,7 +51,8 @@ from qgis.core import (QgsApplication,
|
|||||||
QgsProcessingParameterFileDestination,
|
QgsProcessingParameterFileDestination,
|
||||||
QgsProcessingParameterFolderDestination,
|
QgsProcessingParameterFolderDestination,
|
||||||
QgsProcessingParameterRasterDestination,
|
QgsProcessingParameterRasterDestination,
|
||||||
QgsProcessingParameterVectorDestination)
|
QgsProcessingParameterVectorDestination,
|
||||||
|
QgsProcessingModelAlgorithm)
|
||||||
|
|
||||||
from processing.core import parameters
|
from processing.core import parameters
|
||||||
from processing.modeler.exceptions import UndefinedParameterException
|
from processing.modeler.exceptions import UndefinedParameterException
|
||||||
@ -198,9 +199,7 @@ class ModelerParameterDefinitionDialog(QDialog):
|
|||||||
self.tr('Invalid parameter name'))
|
self.tr('Invalid parameter name'))
|
||||||
return
|
return
|
||||||
|
|
||||||
validChars = \
|
safeName = QgsProcessingModelAlgorithm.safeName(description)
|
||||||
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
|
|
||||||
safeName = ''.join(c for c in description if c in validChars)
|
|
||||||
name = safeName.lower()
|
name = safeName.lower()
|
||||||
|
|
||||||
# Destination parameter
|
# Destination parameter
|
||||||
|
@ -531,6 +531,15 @@ class CORE_EXPORT QgsProcessingModelAlgorithm : public QgsProcessingAlgorithm
|
|||||||
*/
|
*/
|
||||||
const QgsProcessingParameterDefinition *modelParameterFromChildIdAndOutputName( const QString &childId, const QString &childOutputName ) const;
|
const QgsProcessingParameterDefinition *modelParameterFromChildIdAndOutputName( const QString &childId, const QString &childOutputName ) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Makes a name "safe", by replacing any non-alphanumeric characters with underscores.
|
||||||
|
*
|
||||||
|
* If \a capitalize is TRUE then the string will be converted to a camel case string.
|
||||||
|
*
|
||||||
|
* \since QGIS 3.26
|
||||||
|
*/
|
||||||
|
static QString safeName( const QString &name, bool capitalize = false );
|
||||||
|
|
||||||
#ifndef SIP_RUN
|
#ifndef SIP_RUN
|
||||||
|
|
||||||
//! Internal model versions
|
//! Internal model versions
|
||||||
@ -577,8 +586,6 @@ class CORE_EXPORT QgsProcessingModelAlgorithm : public QgsProcessingAlgorithm
|
|||||||
|
|
||||||
QStringList mParameterOrder;
|
QStringList mParameterOrder;
|
||||||
|
|
||||||
static QString safeName( const QString &name, bool capitalize );
|
|
||||||
|
|
||||||
void dependsOnChildAlgorithmsRecursive( const QString &childId, QSet<QString> &depends ) const;
|
void dependsOnChildAlgorithmsRecursive( const QString &childId, QSet<QString> &depends ) const;
|
||||||
void dependentChildAlgorithmsRecursive( const QString &childId, QSet<QString> &depends, const QString &branch ) const;
|
void dependentChildAlgorithmsRecursive( const QString &childId, QSet<QString> &depends, const QString &branch ) const;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user