24using namespace Qt::StringLiterals;
28QgsCombineStylesAlgorithm::QgsCombineStylesAlgorithm() =
default;
30QgsCombineStylesAlgorithm::~QgsCombineStylesAlgorithm() =
default;
32void QgsCombineStylesAlgorithm::initAlgorithm(
const QVariantMap & )
38 const QStringList options = QStringList()
39 << QObject::tr(
"Symbols" )
40 << QObject::tr(
"Color ramps" )
41 << QObject::tr(
"Text formats" )
42 << QObject::tr(
"Label settings" );
43 addParameter(
new QgsProcessingParameterEnum( u
"OBJECTS"_s, QObject::tr(
"Objects to combine" ), options,
true, QVariantList() << 0 << 1 << 2 << 3 ) );
50QString QgsCombineStylesAlgorithm::name()
const
52 return u
"combinestyles"_s;
55QString QgsCombineStylesAlgorithm::displayName()
const
57 return QObject::tr(
"Combine style databases" );
60QStringList QgsCombineStylesAlgorithm::tags()
const
62 return QObject::tr(
"symbols,colors,ramps,formats,labels,text,fonts,merge" ).split(
',' );
65QString QgsCombineStylesAlgorithm::group()
const
67 return QObject::tr(
"Cartography" );
70QString QgsCombineStylesAlgorithm::groupId()
const
72 return u
"cartography"_s;
75QString QgsCombineStylesAlgorithm::shortHelpString()
const
77 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 "
78 "source databases these will be renamed to have unique names in the output combined database." );
81QString QgsCombineStylesAlgorithm::shortDescription()
const
83 return QObject::tr(
"Combines multiple style databases into a single database." );
86QgsCombineStylesAlgorithm *QgsCombineStylesAlgorithm::createInstance()
const
88 return new QgsCombineStylesAlgorithm();
93 const QStringList inputs = parameterAsFileList( parameters, u
"INPUT"_s, context );
95 QList<QgsStyle::StyleEntity> objects;
96 const QList<int> selectedObjects = parameterAsEnums( parameters, u
"OBJECTS"_s, context );
97 if ( selectedObjects.contains( 0 ) )
99 if ( selectedObjects.contains( 1 ) )
101 if ( selectedObjects.contains( 2 ) )
103 if ( selectedObjects.contains( 3 ) )
110 QMap<QgsStyle::StyleEntity, QSet<QString>> usedNames;
111 auto makeUniqueName = [&usedNames](
const QString &sourceName,
QgsStyle::StyleEntity type ) -> QString {
112 QString candidate = sourceName;
117 exists = usedNames[type].contains( candidate );
122 candidate = sourceName + u
" (%1)"_s.arg( i );
125 usedNames[type].insert( candidate );
129 for (
const QString &source : inputs )
133 feedback->
setProgress( 100 * i /
static_cast<double>( inputs.count() ) );
134 feedback->
pushInfo( QObject::tr(
"Importing %1" ).arg( source ) );
143 feedback->
reportError( QObject::tr(
"Could not read %1" ).arg( source ) );
151 const QStringList symbolNames = sourceStyle.
symbolNames();
152 for (
const QString &name : symbolNames )
162 for (
const QString &name : colorRampNames )
172 for (
const QString &name : formatNames )
182 for (
const QString &name : formatNames )
195 feedback->
pushInfo( QObject::tr(
"Writing output file" ) );
198 const QString file = parameterAsString( parameters, u
"OUTPUT"_s, context );
205 results.insert( u
"OUTPUT"_s, file );
206 results.insert( u
"SYMBOLS"_s, style.
symbolCount() );
@ File
Files (i.e. non map layer sources, such as text files).
void setProgress(double progress)
Sets the current progress for the feedback object.
Contains information about the context in which a processing algorithm is executed.
Custom exception class for processing related exceptions.
Base class for providing feedback from a processing algorithm.
virtual void pushInfo(const QString &info)
Pushes a general informational message from the algorithm.
virtual void reportError(const QString &error, bool fatalError=false)
Reports that the algorithm encountered an error while executing.
A numeric output for processing algorithms.
An enum based parameter for processing algorithms, allowing for selection from predefined values.
A generic file based destination parameter, for specifying the destination path for a file (non-map l...
A parameter for processing algorithms which accepts multiple map layers.
A database of saved style entities, including symbols, color ramps, text formats and others.
int colorRampCount()
Returns count of color ramps.
QgsTextFormat textFormat(const QString &name) const
Returns the text format with the specified name.
bool tagSymbol(StyleEntity type, const QString &symbol, const QStringList &tags)
Tags the symbol with the tags in the list.
QStringList textFormatNames() const
Returns a list of names of text formats in the style.
bool addColorRamp(const QString &name, QgsColorRamp *colorRamp, bool update=false)
Adds a color ramp to the style.
QgsSymbol * symbol(const QString &name)
Returns a NEW copy of symbol.
int labelSettingsCount() const
Returns count of label settings in the style.
StyleEntity
Enum for Entities involved in a style.
@ LabelSettingsEntity
Label settings.
@ TextFormatEntity
Text formats.
@ ColorrampEntity
Color ramps.
QStringList tagsOfSymbol(StyleEntity type, const QString &symbol)
Returns the tags associated with the symbol.
QStringList colorRampNames() const
Returns a list of names of color ramps.
int textFormatCount() const
Returns count of text formats in the style.
bool exportXml(const QString &filename)
Exports the style as a XML file.
QgsColorRamp * colorRamp(const QString &name) const
Returns a new copy of the specified color ramp.
int symbolCount()
Returns count of symbols in style.
bool createMemoryDatabase()
Creates a temporary memory database.
QStringList labelSettingsNames() const
Returns a list of names of label settings in the style.
bool addTextFormat(const QString &name, const QgsTextFormat &format, bool update=false)
Adds a text format with the specified name to the style.
QgsPalLayerSettings labelSettings(const QString &name) const
Returns the label settings with the specified name.
bool addSymbol(const QString &name, QgsSymbol *symbol, bool update=false)
Adds a symbol to style and takes symbol's ownership.
QStringList symbolNames() const
Returns a list of names of symbols.
bool importXml(const QString &filename)
Imports the symbols and colorramps into the default style database from the given XML file.
bool addLabelSettings(const QString &name, const QgsPalLayerSettings &settings, bool update=false)
Adds label settings with the specified name to the style.