@@ -32,7 +32,7 @@ void QgsCategorizeUsingStyleAlgorithm::initAlgorithm( const QVariantMap & )
32
32
QList< int >() << QgsProcessing::TypeVector ) );
33
33
addParameter ( new QgsProcessingParameterExpression ( QStringLiteral ( " FIELD" ), QObject::tr ( " Categorize using expression" ), QVariant (), QStringLiteral ( " INPUT" ) ) );
34
34
35
- addParameter ( new QgsProcessingParameterFile ( QStringLiteral ( " STYLE" ), QObject::tr ( " Style database" ), QgsProcessingParameterFile::File, QStringLiteral ( " xml" ) ) );
35
+ addParameter ( new QgsProcessingParameterFile ( QStringLiteral ( " STYLE" ), QObject::tr ( " Style database (leave blank to use saved symbols) " ), QgsProcessingParameterFile::File, QStringLiteral ( " xml" ), QVariant (), true ) );
36
36
addParameter ( new QgsProcessingParameterBoolean ( QStringLiteral ( " CASE_SENSITIVE" ), QObject::tr ( " Use case-sensitive match to symbol names" ), false ) );
37
37
addParameter ( new QgsProcessingParameterBoolean ( QStringLiteral ( " TOLERANT" ), QObject::tr ( " Ignore non-alphanumeric characters while matching" ), false ) );
38
38
@@ -77,7 +77,8 @@ QString QgsCategorizeUsingStyleAlgorithm::groupId() const
77
77
78
78
QString QgsCategorizeUsingStyleAlgorithm::shortHelpString () const
79
79
{
80
- return QObject::tr ( " Sets a vector layer's renderer to a categorized renderer using matching symbols from a style database.\n\n "
80
+ return QObject::tr ( " Sets a vector layer's renderer to a categorized renderer using matching symbols from a style database. If no "
81
+ " style file is specified, symbols from the user's current style library are used instead.\n\n "
81
82
" The specified expression (or field name) is used to create categories for the renderer. A category will be "
82
83
" created for each unique value within the layer.\n\n "
83
84
" Each category is individually matched to the symbols which exist within the specified QGIS XML style database. Whenever "
@@ -161,10 +162,20 @@ QVariantMap QgsCategorizeUsingStyleAlgorithm::processAlgorithm( const QVariantMa
161
162
const bool caseSensitive = parameterAsBool ( parameters, QStringLiteral ( " CASE_SENSITIVE" ), context );
162
163
const bool tolerant = parameterAsBool ( parameters, QStringLiteral ( " TOLERANT" ), context );
163
164
164
- QgsStyle style;
165
- if ( !style.importXml ( styleFile ) )
165
+ QgsStyle *style = nullptr ;
166
+ std::unique_ptr< QgsStyle >importedStyle;
167
+ if ( !styleFile.isEmpty () )
166
168
{
167
- throw QgsProcessingException ( QObject::tr ( " An error occurred while reading style file: %1" ).arg ( style.errorString () ) );
169
+ importedStyle = qgis::make_unique< QgsStyle >();
170
+ if ( !importedStyle->importXml ( styleFile ) )
171
+ {
172
+ throw QgsProcessingException ( QObject::tr ( " An error occurred while reading style file: %1" ).arg ( importedStyle->errorString () ) );
173
+ }
174
+ style = importedStyle.get ();
175
+ }
176
+ else
177
+ {
178
+ style = QgsStyle::defaultStyle ();
168
179
}
169
180
170
181
QgsFields nonMatchingCategoryFields;
@@ -211,7 +222,7 @@ QVariantMap QgsCategorizeUsingStyleAlgorithm::processAlgorithm( const QVariantMa
211
222
212
223
QVariantList unmatchedCategories;
213
224
QStringList unmatchedSymbols;
214
- const int matched = mRenderer ->matchToSymbols ( & style, type, unmatchedCategories, unmatchedSymbols, caseSensitive, tolerant );
225
+ const int matched = mRenderer ->matchToSymbols ( style, type, unmatchedCategories, unmatchedSymbols, caseSensitive, tolerant );
215
226
216
227
if ( matched > 0 )
217
228
{
0 commit comments