30#include <QRegularExpression>
33using namespace Qt::StringLiterals;
49 if ( layer->extent().isNull() )
69 if ( fullExtent.
width() == 0.0 || fullExtent.
height() == 0.0 )
78 fullExtent.
set( -1.0, -1.0, 1.0, 1.0 );
82 const double padFactor = 1e-8;
83 const double widthPad = fullExtent.
xMinimum() * padFactor;
84 const double heightPad = fullExtent.
yMinimum() * padFactor;
85 const double xmin = fullExtent.
xMinimum() - widthPad;
86 const double xmax = fullExtent.
xMaximum() + widthPad;
87 const double ymin = fullExtent.
yMinimum() - heightPad;
88 const double ymax = fullExtent.
yMaximum() + heightPad;
89 fullExtent.
set( xmin, ymin, xmax, ymax );
107 if ( ! providerMetadata )
113 return conn.release();
117 if ( !ex.
what().contains(
"createConnection"_L1 ) )
119 QgsDebugError( u
"Error retrieving database connection for layer %1: %2"_s.arg( layer->
name(), ex.
what() ) );
127 if ( !layer || path.isEmpty() )
131 return parts.value( u
"path"_s ).toString() == path;
136 if ( !layer || newPath.isEmpty() )
140 if ( !parts.contains( u
"path"_s ) )
143 parts.insert( u
"path"_s, newPath );
151 QList< QgsMapLayer * > res = layers;
154 for ( Qgis::LayerType type : order )
156 if ( a->type() == type && b->type() != type )
158 else if ( b->type() == type )
168 QString laundered = name.toLower();
169 const thread_local QRegularExpression sRxSwapChars( u
"\\s"_s );
170 laundered.replace( sRxSwapChars, u
"_"_s );
172 const thread_local QRegularExpression sRxRemoveChars( u
"[^a-zA-Z0-9_]"_s );
173 laundered.replace( sRxRemoveChars, QString() );
184 QVariantMap details = metadata->decodeUri( layer->
source() );
185 QUrl url( details.value( u
"url"_s ).toString() );
186 if ( url.host().endsWith(
".openstreetmap.org"_L1 ) || url.host().endsWith(
".osm.org"_L1 ) )
200 return QObject::tr(
"Vector" );
202 return QObject::tr(
"Raster" );
204 return QObject::tr(
"Mesh" );
206 return QObject::tr(
"Point Cloud" );
208 return QObject::tr(
"Annotation" );
210 return QObject::tr(
"Vector Tile" );
212 return QObject::tr(
"Plugin" );
214 return QObject::tr(
"Group" );
216 return QObject::tr(
"Tiled Scene" );
LayerType
Types of layers that can be added to a map.
@ Group
Composite group layer. Added in QGIS 3.24.
@ Plugin
Plugin based layer.
@ TiledScene
Tiled scene layer. Added in QGIS 3.34.
@ Annotation
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
@ VectorTile
Vector tile layer. Added in QGIS 3.14.
@ Mesh
Mesh layer. Added in QGIS 3.2.
@ PointCloud
Point cloud layer. Added in QGIS 3.18.
Provides common functionality for database based connections.
Represents a coordinate reference system (CRS).
Contains information about the context in which a coordinate transform is executed.
Custom exception class for Coordinate Reference System related exceptions.
static bool updateLayerSourcePath(QgsMapLayer *layer, const QString &newPath)
Updates a layer's data source, replacing its data source with a path referring to newPath.
static QgsRectangle combinedExtent(const QList< QgsMapLayer * > &layers, const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &transformContext)
Returns the combined extent of a list of layers.
static QgsAbstractDatabaseProviderConnection * databaseConnection(const QgsMapLayer *layer)
Creates and returns the (possibly nullptr) database connection for a layer.
static QString layerTypeToString(Qgis::LayerType type)
Returns the translated name of the type for a given layer type.
static QList< QgsMapLayer * > sortLayersByType(const QList< QgsMapLayer * > &layers, const QList< Qgis::LayerType > &order)
Sorts a list of map layers by their layer type, respecting the order of types specified.
static QString launderLayerName(const QString &name)
Launders a layer's name, converting it into a format which is general suitable for file names or data...
static bool isOpenStreetMapLayer(QgsMapLayer *layer)
Returns true if the layer is served by OpenStreetMap server.
static bool layerSourceMatchesPath(const QgsMapLayer *layer, const QString &path)
Returns true if the source of the specified layer matches the given path.
Base class for all map layer types.
QString source() const
Returns the source for the layer.
QString providerType() const
Returns the provider type (provider key) for this layer.
void setDataSource(const QString &dataSource, const QString &baseName=QString(), const QString &provider=QString(), bool loadDefaultStyleFlag=false)
Updates the data source of the layer.
QgsProviderMetadata * providerMetadata() const
Returns the layer data provider's metadata, it may be nullptr.
Custom exception class for provider connection related exceptions.
QVariantMap decodeUri(const QString &providerKey, const QString &uri)
Breaks a provider data source URI into its component paths (e.g.
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
QString encodeUri(const QString &providerKey, const QVariantMap &parts)
Reassembles a provider data source URI from its component paths (e.g.
QgsProviderMetadata * providerMetadata(const QString &providerKey) const
Returns metadata of the provider or nullptr if not found.
A rectangle specified with double values.
Q_INVOKABLE QString toString(int precision=16) const
Returns a string representation of form xmin,ymin : xmax,ymax Coordinates will be truncated to the sp...
void set(const QgsPointXY &p1, const QgsPointXY &p2, bool normalize=true)
Sets the rectangle from two QgsPoints.
void combineExtentWith(const QgsRectangle &rect)
Expands the rectangle so that it covers both the original rectangle and the given rectangle.
void setNull()
Mark a rectangle as being null (holding no spatial information).
#define QgsDebugMsgLevel(str, level)
#define QgsDebugError(str)