Skip to content

Commit 62e09d9

Browse files
committedFeb 5, 2019
[processing] If model name starts with a digit, we need to remove that when generating a class name
1 parent 185855b commit 62e09d9

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed
 

‎src/core/processing/models/qgsprocessingmodelalgorithm.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,8 @@ QStringList QgsProcessingModelAlgorithm::asPythonCode( const QgsProcessing::Pyth
365365
QString n = name.toLower().trimmed();
366366
QRegularExpression rx( QStringLiteral( "[^\\sa-z_A-Z0-9]" ) );
367367
n.replace( rx, QString() );
368+
QRegularExpression rx2( QStringLiteral( "^\\d*" ) ); // name can't start in a digit
369+
n.replace( rx2, QString() );
368370
return QgsStringUtils::capitalize( n, QgsStringUtils::UpperCamelCase );
369371
};
370372

‎tests/src/analysis/testqgsprocessing.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6946,6 +6946,7 @@ void TestQgsProcessing::modelExecution()
69466946
QGSCOMPARENEAR( variables.value( "SOURCE_LAYER_maxx" ).value.toDouble(), -83.3333, 0.001 );
69476947
QGSCOMPARENEAR( variables.value( "SOURCE_LAYER_maxy" ).value.toDouble(), 46.8719, 0.001 );
69486948

6949+
model2.setName( QStringLiteral( "2my model" ) );
69496950
QStringList actualParts = model2.asPythonCode( QgsProcessing::PythonQgsProcessingAlgorithmSubclass, 2 );
69506951
QgsDebugMsg( actualParts.join( '\n' ) );
69516952
QStringList expectedParts = QStringLiteral( "from qgis.core import QgsProcessing\n"
@@ -6956,7 +6957,7 @@ void TestQgsProcessing::modelExecution()
69566957
"import processing\n"
69576958
"\n"
69586959
"\n"
6959-
"class Model(QgsProcessingAlgorithm):\n"
6960+
"class MyModel(QgsProcessingAlgorithm):\n"
69606961
"\n"
69616962
" def initAlgorithm(self, config=None):\n"
69626963
" self.addParameter(QgsProcessingParameterFeatureSource('SOURCE_LAYER', '', defaultValue=None))\n"
@@ -6994,10 +6995,10 @@ void TestQgsProcessing::modelExecution()
69946995
" return results\n"
69956996
"\n"
69966997
" def name(self):\n"
6997-
" return 'model'\n"
6998+
" return '2my model'\n"
69986999
"\n"
69997000
" def displayName(self):\n"
7000-
" return 'model'\n"
7001+
" return '2my model'\n"
70017002
"\n"
70027003
" def group(self):\n"
70037004
" return ''\n"
@@ -7006,7 +7007,7 @@ void TestQgsProcessing::modelExecution()
70067007
" return ''\n"
70077008
"\n"
70087009
" def createInstance(self):\n"
7009-
" return Model()\n" ).split( '\n' );
7010+
" return MyModel()\n" ).split( '\n' );
70107011
QCOMPARE( actualParts, expectedParts );
70117012
}
70127013

0 commit comments

Comments
 (0)
Please sign in to comment.