27void QgsBookmarksToLayerAlgorithm::initAlgorithm(
const QVariantMap & )
29 std::unique_ptr< QgsProcessingParameterEnum > sourceParam = std::make_unique<QgsProcessingParameterEnum >( QStringLiteral(
"SOURCE" ), QObject::tr(
"Bookmark source" ), QStringList() <<
30 QObject::tr(
"Project bookmarks" ) << QObject::tr(
"User bookmarks" ),
true, QVariantList() << 0 << 1 );
31 QVariantMap wrapperMetadata;
32 wrapperMetadata.insert( QStringLiteral(
"useCheckBoxes" ),
true );
34 metadata.insert( QStringLiteral(
"widget_wrapper" ), wrapperMetadata );
35 sourceParam->setMetadata( metadata );
36 addParameter( sourceParam.release() );
41QString QgsBookmarksToLayerAlgorithm::name()
const
43 return QStringLiteral(
"bookmarkstolayer" );
46QString QgsBookmarksToLayerAlgorithm::displayName()
const
48 return QObject::tr(
"Convert spatial bookmarks to layer" );
51QStringList QgsBookmarksToLayerAlgorithm::tags()
const
53 return QObject::tr(
"save,extract" ).split(
',' );
56QString QgsBookmarksToLayerAlgorithm::group()
const
58 return QObject::tr(
"Vector general" );
61QString QgsBookmarksToLayerAlgorithm::groupId()
const
63 return QStringLiteral(
"vectorgeneral" );
66QString QgsBookmarksToLayerAlgorithm::shortHelpString()
const
68 return QObject::tr(
"This algorithm creates a new layer containing polygon features for stored spatial bookmarks.\n\n"
69 "The export can be filtered to only bookmarks belonging to the current project, to all user bookmarks, or a combination of both." );
72QString QgsBookmarksToLayerAlgorithm::shortDescription()
const
74 return QObject::tr(
"Converts stored spatial bookmarks to a polygon layer." );
77QIcon QgsBookmarksToLayerAlgorithm::icon()
const
82QString QgsBookmarksToLayerAlgorithm::svgIconPath()
const
87QgsBookmarksToLayerAlgorithm *QgsBookmarksToLayerAlgorithm::createInstance()
const
89 return new QgsBookmarksToLayerAlgorithm();
94 QList< int > sources = parameterAsEnums( parameters, QStringLiteral(
"SOURCE" ), context );
95 if ( sources.contains( 0 ) )
101 if ( sources.contains( 1 ) )
111 fields.
append(
QgsField( QStringLiteral(
"name" ), QVariant::String ) );
112 fields.
append(
QgsField( QStringLiteral(
"group" ), QVariant::String ) );
114 std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral(
"OUTPUT" ), context, dest, fields,
QgsWkbTypes::Polygon,
crs ) );
118 int count = mBookmarks.count();
120 double step = count > 0 ? 100.0 / count : 1;
122 for (
const QgsBookmark &b : std::as_const( mBookmarks ) )
133 if ( b.extent().crs() !=
crs )
143 feedback->
reportError( QObject::tr(
"Could not reproject bookmark %1 to destination CRS" ).arg( b.name() ) );
158 outputs.insert( QStringLiteral(
"OUTPUT" ), dest );
167void QgsLayerToBookmarksAlgorithm::initAlgorithm(
const QVariantMap & )
171 std::unique_ptr< QgsProcessingParameterEnum > sourceParam = std::make_unique<QgsProcessingParameterEnum >( QStringLiteral(
"DESTINATION" ), QObject::tr(
"Bookmark destination" ), QStringList() <<
172 QObject::tr(
"Project bookmarks" ) << QObject::tr(
"User bookmarks" ),
false, 0 );
173 addParameter( sourceParam.release() );
175 addParameter(
new QgsProcessingParameterExpression( QStringLiteral(
"NAME_EXPRESSION" ), QObject::tr(
"Name field" ), QVariant(), QStringLiteral(
"INPUT" ) ) );
176 addParameter(
new QgsProcessingParameterExpression( QStringLiteral(
"GROUP_EXPRESSION" ), QObject::tr(
"Group field" ), QVariant(), QStringLiteral(
"INPUT" ),
true ) );
181QString QgsLayerToBookmarksAlgorithm::name()
const
183 return QStringLiteral(
"layertobookmarks" );
186QString QgsLayerToBookmarksAlgorithm::displayName()
const
188 return QObject::tr(
"Convert layer to spatial bookmarks" );
191QStringList QgsLayerToBookmarksAlgorithm::tags()
const
193 return QObject::tr(
"save,extract,store" ).split(
',' );
196QString QgsLayerToBookmarksAlgorithm::group()
const
198 return QObject::tr(
"Vector general" );
201QString QgsLayerToBookmarksAlgorithm::groupId()
const
203 return QStringLiteral(
"vectorgeneral" );
206QString QgsLayerToBookmarksAlgorithm::shortHelpString()
const
208 return QObject::tr(
"This algorithm creates spatial bookmarks corresponding to the extent of features contained in a layer." );
211QString QgsLayerToBookmarksAlgorithm::shortDescription()
const
213 return QObject::tr(
"Converts feature extents to stored spatial bookmarks." );
216QIcon QgsLayerToBookmarksAlgorithm::icon()
const
221QString QgsLayerToBookmarksAlgorithm::svgIconPath()
const
226QgsLayerToBookmarksAlgorithm *QgsLayerToBookmarksAlgorithm::createInstance()
const
228 return new QgsLayerToBookmarksAlgorithm();
233 mDest = parameterAsEnum( parameters, QStringLiteral(
"DESTINATION" ), context );
234 std::unique_ptr< QgsProcessingFeatureSource > source( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
239 QString nameExpressionString = parameterAsExpression( parameters, QStringLiteral(
"NAME_EXPRESSION" ), context );
240 QString groupExpressionString = parameterAsExpression( parameters, QStringLiteral(
"GROUP_EXPRESSION" ), context );
243 expressionContext.
appendScope( source->createExpressionContextScope() );
246 if ( !nameExpression.
prepare( &expressionContext ) )
251 std::unique_ptr< QgsExpression > groupExpression;
252 if ( !groupExpressionString.isEmpty() )
254 groupExpression = std::make_unique< QgsExpression >( groupExpressionString );
255 if ( !groupExpression->prepare( &expressionContext ) )
256 throw QgsProcessingException( QObject::tr(
"Invalid group expression: %1" ).arg( groupExpression->parserErrorString() ) );
257 requiredColumns.unite( groupExpression->referencedColumns() );
263 double step = source->featureCount() > 0 ? 100.0 / source->featureCount() : 1;
278 const QString name = nameExpression.
evaluate( &expressionContext ).toString();
287 if ( groupExpression )
289 group = groupExpression->evaluate( &expressionContext ).toString();
290 if ( !groupExpression->evalErrorString().isEmpty() )
292 feedback->
reportError( QObject::tr(
"Error evaluating group expression: %1" ).arg( groupExpression->evalErrorString() ) );
309 return QVariantMap();
326 for (
const QgsBookmark &b : std::as_const( mBookmarks ) )
330 res.insert( QStringLiteral(
"COUNT" ), mBookmarks.size() );
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
static QgsBookmarkManager * bookmarkManager()
Returns the application's bookmark manager, used for storing installation-wide bookmarks.
static QString iconPath(const QString &iconFile)
Returns path to the desired icon file.
Manages storage of a set of bookmarks.
QString addBookmark(const QgsBookmark &bookmark, bool *ok=nullptr)
Adds a bookmark to the manager.
QList< QgsBookmark > bookmarks() const
Returns a list of all bookmarks contained in the manager.
Represents a spatial bookmark, with a name, CRS and extent.
void setGroup(const QString &group)
Sets the bookmark's group, which is a user-visible string identifying the bookmark's category.
void setExtent(const QgsReferencedRectangle &extent)
Sets the bookmark's spatial extent.
void setName(const QString &name)
Sets the bookmark's name, which is a user-visible string identifying the bookmark.
This class represents a coordinate reference system (CRS).
Custom exception class for Coordinate Reference System related exceptions.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
Class for parsing and evaluation of expressions (formerly called "search strings").
bool prepare(const QgsExpressionContext *context)
Gets the expression ready for evaluation - find out column indexes.
QString evalErrorString() const
Returns evaluation error.
QString parserErrorString() const
Returns parser error.
QSet< QString > referencedColumns() const
Gets list of columns referenced by the expression.
QVariant evaluate()
Evaluate the feature and return the result.
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
This class wraps a request for features to a vector layer (or directly its vector data provider).
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
@ FastInsert
Use faster inserts, at the cost of updating the passed features to reflect changes made at the provid...
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.
bool hasGeometry() const
Returns true if the feature has an associated geometry.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
bool isCanceled() const SIP_HOLDGIL
Tells whether the operation has been canceled already.
void setProgress(double progress)
Sets the current progress for the feedback object.
Encapsulate a field in an attribute table or data source.
Container of fields for a vector layer.
bool append(const QgsField &field, FieldOrigin origin=OriginProvider, int originIndex=-1)
Appends a field. The field must have unique name, otherwise it is rejected (returns false)
A geometry is the spatial representation of a feature.
QgsGeometry densifyByCount(int extraNodesPerSegment) const
Returns a copy of the geometry which has been densified by adding the specified number of extra nodes...
Qgis::GeometryOperationResult transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool transformZ=false) SIP_THROW(QgsCsException)
Transforms this geometry as described by the coordinate transform ct.
static QgsGeometry fromRect(const QgsRectangle &rect) SIP_HOLDGIL
Creates a new geometry from a QgsRectangle.
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
Contains information about the context in which a processing algorithm is executed.
QgsExpressionContext & expressionContext()
Returns the expression context.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context.
QgsProject * project() const
Returns the project in which the algorithm is being executed.
Custom exception class for processing related exceptions.
@ FlagSkipGeometryValidityChecks
Invalid geometry checks should always be skipped. This flag can be useful for algorithms which always...
Base class for providing feedback from a processing 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.
A coordinate reference system parameter for processing algorithms.
An expression parameter for processing algorithms.
A feature sink output for processing algorithms.
An input feature source (such as vector layers) parameter for processing algorithms.
@ TypeVectorLine
Vector line layers.
@ TypeVectorPolygon
Vector polygon layers.
const QgsBookmarkManager * bookmarkManager() const
Returns the project's bookmark manager, which manages bookmarks within the project.
A QgsRectangle with associated coordinate reference system.
const QgsCoordinateReferenceSystem & crs