24using namespace Qt::StringLiterals;
32void QgsBookmarksToLayerAlgorithm::initAlgorithm(
const QVariantMap & )
34 auto sourceParam = std::make_unique<
35 QgsProcessingParameterEnum>( u
"SOURCE"_s, QObject::tr(
"Bookmark source" ), QStringList() << QObject::tr(
"Project bookmarks" ) << QObject::tr(
"User bookmarks" ),
true, QVariantList() << 0 << 1 );
36 QVariantMap wrapperMetadata;
37 wrapperMetadata.insert( u
"useCheckBoxes"_s,
true );
39 metadata.insert( u
"widget_wrapper"_s, wrapperMetadata );
41 addParameter( sourceParam.release() );
46QString QgsBookmarksToLayerAlgorithm::name()
const
48 return u
"bookmarkstolayer"_s;
51QString QgsBookmarksToLayerAlgorithm::displayName()
const
53 return QObject::tr(
"Convert spatial bookmarks to layer" );
56QStringList QgsBookmarksToLayerAlgorithm::tags()
const
58 return QObject::tr(
"save,extract" ).split(
',' );
61QString QgsBookmarksToLayerAlgorithm::group()
const
63 return QObject::tr(
"Vector general" );
66QString QgsBookmarksToLayerAlgorithm::groupId()
const
68 return u
"vectorgeneral"_s;
71QString QgsBookmarksToLayerAlgorithm::shortHelpString()
const
74 "This algorithm creates a new layer containing polygon features for stored spatial bookmarks.\n\n"
75 "The export can be filtered to only bookmarks belonging to the current project, to all user bookmarks, or a combination of both."
79QString QgsBookmarksToLayerAlgorithm::shortDescription()
const
81 return QObject::tr(
"Converts stored spatial bookmarks to a polygon layer." );
84QIcon QgsBookmarksToLayerAlgorithm::icon()
const
89QString QgsBookmarksToLayerAlgorithm::svgIconPath()
const
94QgsBookmarksToLayerAlgorithm *QgsBookmarksToLayerAlgorithm::createInstance()
const
96 return new QgsBookmarksToLayerAlgorithm();
101 QList<int> sources = parameterAsEnums( parameters, u
"SOURCE"_s, context );
102 if ( sources.contains( 0 ) )
108 if ( sources.contains( 1 ) )
116 QGS_MARK_ALGORITHM_SOURCE
121 fields.
append(
QgsField( u
"group"_s, QMetaType::Type::QString ) );
123 std::unique_ptr<QgsFeatureSink> sink( parameterAsSink( parameters, u
"OUTPUT"_s, context, dest, fields,
Qgis::WkbType::Polygon, crs ) );
127 int count = mBookmarks.count();
129 double step = count > 0 ? 100.0 / count : 1;
131 for (
const QgsBookmark &b : std::as_const( mBookmarks ) )
142 if ( b.extent().crs() != crs )
152 feedback->
reportError( QObject::tr(
"Could not reproject bookmark %1 to destination CRS" ).arg( b.name() ) );
172 outputs.insert( u
"OUTPUT"_s, dest );
181void QgsLayerToBookmarksAlgorithm::initAlgorithm(
const QVariantMap & )
187 auto sourceParam = std::make_unique<
188 QgsProcessingParameterEnum>( u
"DESTINATION"_s, QObject::tr(
"Bookmark destination" ), QStringList() << QObject::tr(
"Project bookmarks" ) << QObject::tr(
"User bookmarks" ),
false, 0 );
189 addParameter( sourceParam.release() );
197QString QgsLayerToBookmarksAlgorithm::name()
const
199 return u
"layertobookmarks"_s;
202QString QgsLayerToBookmarksAlgorithm::displayName()
const
204 return QObject::tr(
"Convert layer to spatial bookmarks" );
207QStringList QgsLayerToBookmarksAlgorithm::tags()
const
209 return QObject::tr(
"save,extract,store" ).split(
',' );
212QString QgsLayerToBookmarksAlgorithm::group()
const
214 return QObject::tr(
"Vector general" );
217QString QgsLayerToBookmarksAlgorithm::groupId()
const
219 return u
"vectorgeneral"_s;
222QString QgsLayerToBookmarksAlgorithm::shortHelpString()
const
224 return QObject::tr(
"This algorithm creates spatial bookmarks corresponding to the extent of features contained in a layer." );
227QString QgsLayerToBookmarksAlgorithm::shortDescription()
const
229 return QObject::tr(
"Converts feature extents to stored spatial bookmarks." );
232QIcon QgsLayerToBookmarksAlgorithm::icon()
const
237QString QgsLayerToBookmarksAlgorithm::svgIconPath()
const
242QgsLayerToBookmarksAlgorithm *QgsLayerToBookmarksAlgorithm::createInstance()
const
244 return new QgsLayerToBookmarksAlgorithm();
249 QGS_MARK_ALGORITHM_SOURCE
251 mDest = parameterAsEnum( parameters, u
"DESTINATION"_s, context );
252 std::unique_ptr<QgsProcessingFeatureSource> source( parameterAsSource( parameters, u
"INPUT"_s, context ) );
257 QString nameExpressionString = parameterAsExpression( parameters, u
"NAME_EXPRESSION"_s, context );
258 QString groupExpressionString = parameterAsExpression( parameters, u
"GROUP_EXPRESSION"_s, context );
261 expressionContext.
appendScope( source->createExpressionContextScope() );
264 if ( !nameExpression.
prepare( &expressionContext ) )
269 std::unique_ptr<QgsExpression> groupExpression;
270 if ( !groupExpressionString.isEmpty() )
272 groupExpression = std::make_unique<QgsExpression>( groupExpressionString );
273 if ( !groupExpression->prepare( &expressionContext ) )
274 throw QgsProcessingException( QObject::tr(
"Invalid group expression: %1" ).arg( groupExpression->parserErrorString() ) );
275 requiredColumns.unite( groupExpression->referencedColumns() );
281 double step = source->featureCount() > 0 ? 100.0 / source->featureCount() : 1;
296 const QString name = nameExpression.
evaluate( &expressionContext ).toString();
305 if ( groupExpression )
307 group = groupExpression->evaluate( &expressionContext ).toString();
308 if ( !groupExpression->evalErrorString().isEmpty() )
310 feedback->
reportError( QObject::tr(
"Error evaluating group expression: %1" ).arg( groupExpression->evalErrorString() ) );
327 return QVariantMap();
347 for (
const QgsBookmark &b : std::as_const( mBookmarks ) )
351 res.insert( u
"COUNT"_s, mBookmarks.size() );
@ VectorPolygon
Vector polygon layers.
@ VectorLine
Vector line layers.
@ SkipGeometryValidityChecks
Invalid geometry checks should always be skipped. This flag can be useful for algorithms which always...
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.
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.
Handles 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)
Fetch next feature and stores in f, returns true on success.
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
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, Qgis::FieldOrigin origin=Qgis::FieldOrigin::Provider, int originIndex=-1)
Appends a field.
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...
static QgsGeometry fromRect(const QgsRectangle &rect)
Creates a new geometry from a QgsRectangle.
Qgis::GeometryOperationResult transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool transformZ=false)
Transforms this geometry as described by the coordinate transform ct.
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.
Base class for providing feedback from a processing algorithm.
void featureAddedToSink(const QString &output)
Reports that a feature was added to the the sink associated with the specified algorithm output.
void featureSinkFinalized(const QString &output)
Reports that a feature sink has been finalized.
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.
void setMetadata(const QVariantMap &metadata)
Sets the parameter's freeform metadata.
An enum based parameter for processing algorithms, allowing for selection from predefined values.
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.
const QgsBookmarkManager * bookmarkManager() const
Returns the project's bookmark manager, which manages bookmarks within the project.
A QgsRectangle with associated coordinate reference system.