23 QgsCombineStylesAlgorithm::QgsCombineStylesAlgorithm() =
default;
25 QgsCombineStylesAlgorithm::~QgsCombineStylesAlgorithm() =
default;
27 void QgsCombineStylesAlgorithm::initAlgorithm(
const QVariantMap & )
32 QObject::tr(
"Style files (*.xml)" ) ) );
34 QStringList options = QStringList()
35 << QObject::tr(
"Symbols" )
36 << QObject::tr(
"Color ramps" )
37 << QObject::tr(
"Text formats" )
38 << QObject::tr(
"Label settings" );
39 addParameter(
new QgsProcessingParameterEnum( QStringLiteral(
"OBJECTS" ), QObject::tr(
"Objects to combine" ), options,
true, QVariantList() << 0 << 1 << 2 << 3 ) );
46 QString QgsCombineStylesAlgorithm::name()
const
48 return QStringLiteral(
"combinestyles" );
51 QString QgsCombineStylesAlgorithm::displayName()
const
53 return QObject::tr(
"Combine style databases" );
56 QStringList QgsCombineStylesAlgorithm::tags()
const
58 return QObject::tr(
"symbols,colors,ramps,formats,labels,text,fonts,merge" ).split(
',' );
61 QString QgsCombineStylesAlgorithm::group()
const
63 return QObject::tr(
"Cartography" );
66 QString QgsCombineStylesAlgorithm::groupId()
const
68 return QStringLiteral(
"cartography" );
71 QString QgsCombineStylesAlgorithm::shortHelpString()
const
73 return QObject::tr(
"This algorithm combines multiple QGIS style databases into a single style database. If any symbols exist with duplicate names between the different "
74 "source databases these will be renamed to have unique names in the output combined database." );
77 QString QgsCombineStylesAlgorithm::shortDescription()
const
79 return QObject::tr(
"Combines multiple style databases into a single database." );
82 QgsCombineStylesAlgorithm *QgsCombineStylesAlgorithm::createInstance()
const
84 return new QgsCombineStylesAlgorithm();
89 const QStringList inputs = parameterAsFileList( parameters, QStringLiteral(
"INPUT" ), context );
91 QList< QgsStyle::StyleEntity > objects;
92 const QList< int > selectedObjects = parameterAsEnums( parameters, QStringLiteral(
"OBJECTS" ), context );
93 if ( selectedObjects.contains( 0 ) )
95 if ( selectedObjects.contains( 1 ) )
97 if ( selectedObjects.contains( 2 ) )
99 if ( selectedObjects.contains( 3 ) )
106 QMap< QgsStyle::StyleEntity, QSet< QString> > usedNames;
107 auto makeUniqueName = [&usedNames](
const QString & sourceName,
QgsStyle::StyleEntity type )->QString
109 QString candidate = sourceName;
114 exists = usedNames[ type ].contains( candidate );
119 candidate = sourceName + QStringLiteral(
" (%1)" ).arg( i );
122 usedNames[ type ].insert( candidate );
126 for (
const QString &source : inputs )
130 feedback->
setProgress( 100 * i /
static_cast< double >( inputs.count() ) );
131 feedback->
pushInfo( QObject::tr(
"Importing %1" ).arg( source ) );
138 feedback->
reportError( QObject::tr(
"Could not read %1" ).arg( source ) );
145 const QStringList symbolNames = sourceStyle.
symbolNames();
146 for (
const QString &name : symbolNames )
156 for (
const QString &name : colorRampNames )
166 for (
const QString &name : formatNames )
176 for (
const QString &name : formatNames )
189 feedback->
pushInfo( QObject::tr(
"Writing output file" ) );
192 const QString file = parameterAsString( parameters, QStringLiteral(
"OUTPUT" ), context );
199 results.insert( QStringLiteral(
"OUTPUT" ), file );
200 results.insert( QStringLiteral(
"SYMBOLS" ), style.
symbolCount() );
201 results.insert( QStringLiteral(
"COLORRAMPS" ), style.
colorRampCount() );
202 results.insert( QStringLiteral(
"TEXTFORMATS" ), style.
textFormatCount() );