28QgsSaveToStyleVisitor::QgsSaveToStyleVisitor(
QgsStyle *style,
const QList<QgsStyle::StyleEntity> &objects )
36 if ( mObjects.empty() || mObjects.contains( entity.
entity->
type() ) )
38 const QString name = QString( mParentNames.join(
' ' ) +
' ' + entity.
description ).trimmed();
39 QString candidate = name;
44 exists = mStyle->allNames( entity.
entity->
type() ).contains( candidate );
49 candidate = name + QStringLiteral(
" (%1)" ).arg( i );
51 mStyle->addEntity( candidate, entity.
entity,
true );
98 mParentNames.pop_back();
108QgsStyleFromProjectAlgorithm::QgsStyleFromProjectAlgorithm() =
default;
110QgsStyleFromProjectAlgorithm::~QgsStyleFromProjectAlgorithm() =
default;
112void QgsStyleFromProjectAlgorithm::initAlgorithm(
const QVariantMap & )
118 const QStringList options = QStringList()
119 << QObject::tr(
"Symbols" )
120 << QObject::tr(
"Color ramps" )
121 << QObject::tr(
"Text formats" )
122 << QObject::tr(
"Label settings" );
123 addParameter(
new QgsProcessingParameterEnum( QStringLiteral(
"OBJECTS" ), QObject::tr(
"Objects to extract" ), options,
true, QVariantList() << 0 << 1 << 2 << 3 ) );
130QString QgsStyleFromProjectAlgorithm::name()
const
132 return QStringLiteral(
"stylefromproject" );
135QString QgsStyleFromProjectAlgorithm::displayName()
const
137 return QObject::tr(
"Create style database from project" );
140QStringList QgsStyleFromProjectAlgorithm::tags()
const
142 return QObject::tr(
"symbols,color,ramps,colors,formats,labels,text,fonts" ).split(
',' );
145QString QgsStyleFromProjectAlgorithm::group()
const
147 return QObject::tr(
"Cartography" );
150QString QgsStyleFromProjectAlgorithm::groupId()
const
152 return QStringLiteral(
"cartography" );
155QString QgsStyleFromProjectAlgorithm::shortHelpString()
const
157 return QObject::tr(
"This algorithm extracts all style objects (including symbols, color ramps, text formats and label settings) from a QGIS project.\n\n"
158 "The extracted symbols are saved to a QGIS style database (XML format), which can be managed and imported via the Style Manager dialog." );
161QString QgsStyleFromProjectAlgorithm::shortDescription()
const
163 return QObject::tr(
"Creates a style database by extracting all symbols, color ramps, text formats and label settings from a QGIS project." );
166QgsStyleFromProjectAlgorithm *QgsStyleFromProjectAlgorithm::createInstance()
const
168 return new QgsStyleFromProjectAlgorithm();
173 mProjectPath = parameterAsFile( parameters, QStringLiteral(
"INPUT" ), context );
174 if ( mProjectPath.isEmpty() && !context.
project() )
177 const QList<int> selectedObjects = parameterAsEnums( parameters, QStringLiteral(
"OBJECTS" ), context );
178 if ( selectedObjects.contains( 0 ) )
180 if ( selectedObjects.contains( 1 ) )
182 if ( selectedObjects.contains( 2 ) )
184 if ( selectedObjects.contains( 3 ) )
187 mStyle = std::make_unique<QgsStyle>();
188 mStyle->createMemoryDatabase();
190 if ( mProjectPath.isEmpty() )
193 QgsSaveToStyleVisitor visitor( mStyle.get(), mObjects );
201 if ( !mProjectPath.isEmpty() )
210 QgsSaveToStyleVisitor visitor( mStyle.get(), mObjects );
211 p.accept( &visitor );
214 const QString file = parameterAsString( parameters, QStringLiteral(
"OUTPUT" ), context );
215 if ( !mStyle->exportXml( file ) )
221 results.insert( QStringLiteral(
"OUTPUT" ), file );
222 results.insert( QStringLiteral(
"SYMBOLS" ), mStyle->symbolCount() );
223 results.insert( QStringLiteral(
"COLORRAMPS" ), mStyle->colorRampCount() );
224 results.insert( QStringLiteral(
"TEXTFORMATS" ), mStyle->textFormatCount() );
225 results.insert( QStringLiteral(
"LABELSETTINGS" ), mStyle->labelSettingsCount() );
@ File
Parameter is a single file.
@ DontLoad3DViews
Skip loading 3D views.
@ DontUpgradeAnnotations
Don't upgrade old annotation items to QgsAnnotationItem.
@ DontResolveLayers
Don't resolve layer paths (i.e. don't load any layer content). Dramatically improves project read tim...
QFlags< ProjectCapability > ProjectCapabilities
Flags which control project capabilities.
Contains information about the context in which a processing algorithm is executed.
QgsProject * project() const
Returns the project in which the algorithm is being executed.
Custom exception class for processing related exceptions.
Base class for providing feedback from a processing algorithm.
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...
An input file or folder parameter for processing algorithms.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
bool accept(QgsStyleEntityVisitorInterface *visitor) const
Accepts the specified style entity visitor, causing it to visit all style entities associated with th...
virtual QgsStyle::StyleEntity type() const =0
Returns the type of style entity.
@ ReportFooter
Report footer section.
@ Report
A QGIS print report.
@ Annotation
An individual annotation.
@ Annotations
Annotations collection.
@ Project
QGIS Project node.
@ ReportSection
Report sub section.
@ Layouts
Layout collection.
@ LayoutItem
Individual item in a print layout.
@ SymbolRule
Rule based symbology or label child rule.
@ ReportHeader
Report header section.
@ PrintLayout
An individual print layout.
A database of saved style entities, including symbols, color ramps, text formats and others.
@ LabelSettingsEntity
Label settings.
@ TextFormatEntity
Text formats.
@ ColorrampEntity
Color ramps.
Contains information relating to a node (i.e.
QString description
A string describing the node.
QgsStyleEntityVisitorInterface::NodeType type
Node type.
Contains information relating to the style entity currently being visited.
QString description
A string describing the style entity.
const QgsStyleEntityInterface * entity
Reference to style entity being visited.