Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
use upper camel case for the class name
  • Loading branch information
Gustry authored and nyalldawson committed Feb 2, 2019
1 parent 599b0c8 commit 57695bd
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions python/core/auto_generated/qgsstringutils.sip.in
Expand Up @@ -175,6 +175,7 @@ Utility functions for working with strings.
AllLowercase,
ForceFirstLetterToCapital,
TitleCase,
UpperCamelCase,
};

static QString capitalize( const QString &string, Capitalization capitalization );
Expand Down
6 changes: 3 additions & 3 deletions src/core/processing/models/qgsprocessingmodelalgorithm.cpp
Expand Up @@ -381,12 +381,12 @@ QStringList QgsProcessingModelAlgorithm::asPythonCode( const QgsProcessing::Pyth
auto safeName = []( const QString & name )->QString
{
QString n = name.toLower().trimmed();
QRegularExpression rx( QStringLiteral( "[^a-z_A-Z0-9]" ) );
QRegularExpression rx( QStringLiteral( "[^\\sa-z_A-Z0-9]" ) );
n.replace( rx, QString() );
return n;
return QgsStringUtils::capitalize( n, QgsStringUtils::UpperCamelCase );
};

const QString algorithmClassName = QgsStringUtils::capitalize( safeName( name() ), QgsStringUtils::ForceFirstLetterToCapital );
const QString algorithmClassName = safeName( name() );
lines << QStringLiteral( "class %1(QgsProcessingAlgorithm):" ).arg( algorithmClassName );
lines << QString();

Expand Down
5 changes: 5 additions & 0 deletions src/core/qgsstringutils.cpp
Expand Up @@ -96,6 +96,11 @@ QString QgsStringUtils::capitalize( const QString &string, QgsStringUtils::Capit
}
return result;
}

case UpperCamelCase:
QString result = QgsStringUtils::capitalize( string.toLower(), QgsStringUtils::ForceFirstLetterToCapital ).simplified();
result.remove( ' ' );
return result;
}
// no warnings
return string;
Expand Down
1 change: 1 addition & 0 deletions src/core/qgsstringutils.h
Expand Up @@ -189,6 +189,7 @@ class CORE_EXPORT QgsStringUtils
AllLowercase = QFont::AllLowercase, //!< Convert all characters to lowercase
ForceFirstLetterToCapital = QFont::Capitalize, //!< Convert just the first letter of each word to uppercase, leave the rest untouched
TitleCase = QFont::Capitalize + 1000, //!< Simple title case conversion - does not fully grammatically parse the text and uses simple rules only. Note that this method does not convert any characters to lowercase, it only uppercases required letters. Callers must ensure that input strings are already lowercased.
UpperCamelCase = QFont::Capitalize + 1001, //!< Convert the string to upper camel case. Note that this method does not unaccent characters.
};

/**
Expand Down
10 changes: 10 additions & 0 deletions tests/src/core/testqgsstringutils.cpp
Expand Up @@ -36,6 +36,7 @@ class TestQgsStringUtils : public QObject
void insertLinks();
void titleCase_data();
void titleCase();
void camelCase();
void ampersandEncode_data();
void ampersandEncode();
void wordWrap_data();
Expand Down Expand Up @@ -188,6 +189,15 @@ void TestQgsStringUtils::titleCase()
QCOMPARE( QgsStringUtils::capitalize( input, QgsStringUtils::TitleCase ), expected );
}

void TestQgsStringUtils::camelCase()
{
QCOMPARE( QgsStringUtils::capitalize( QString(), QgsStringUtils::UpperCamelCase ), QString() );
QCOMPARE( QgsStringUtils::capitalize( QString( " abc def" ), QgsStringUtils::UpperCamelCase ), QString( "AbcDef" ) );
QCOMPARE( QgsStringUtils::capitalize( QString( "ABC DEF" ), QgsStringUtils::UpperCamelCase ), QString( "AbcDef" ) );
QCOMPARE( QgsStringUtils::capitalize( QString( "àbc def" ), QgsStringUtils::UpperCamelCase ), QString( "ÀbcDef" ) );
QCOMPARE( QgsStringUtils::capitalize( QString( "àbc dÉf" ), QgsStringUtils::UpperCamelCase ), QString( "ÀbcDéf" ) );
}

void TestQgsStringUtils::ampersandEncode_data()
{
QTest::addColumn<QString>( "input" );
Expand Down

0 comments on commit 57695bd

Please sign in to comment.