33#include <QRegularExpression>
36using namespace Qt::StringLiterals;
52 if ( layer->extent().isNull() )
72 if ( fullExtent.
width() == 0.0 || fullExtent.
height() == 0.0 )
80 fullExtent.
set( -1.0, -1.0, 1.0, 1.0 );
84 const double padFactor = 1e-8;
85 const double widthPad = fullExtent.
xMinimum() * padFactor;
86 const double heightPad = fullExtent.
yMinimum() * padFactor;
87 const double xmin = fullExtent.
xMinimum() - widthPad;
88 const double xmax = fullExtent.
xMaximum() + widthPad;
89 const double ymin = fullExtent.
yMinimum() - heightPad;
90 const double ymax = fullExtent.
yMaximum() + heightPad;
91 fullExtent.
set( xmin, ymin, xmax, ymax );
109 if ( !providerMetadata )
115 return conn.release();
119 if ( !ex.
what().contains(
"createConnection"_L1 ) )
121 QgsDebugError( u
"Error retrieving database connection for layer %1: %2"_s.arg( layer->
name(), ex.
what() ) );
129 if ( !layer || path.isEmpty() )
133 return parts.value( u
"path"_s ).toString() == path;
157 if ( !layer || newPath.isEmpty() )
161 if ( !parts.contains( u
"path"_s ) )
164 parts.insert( u
"path"_s, newPath );
172 QList< QgsMapLayer * > res = layers;
174 for ( Qgis::LayerType type : order )
176 if ( a->type() == type && b->type() != type )
178 else if ( b->type() == type )
188 QString laundered = name.toLower();
189 const thread_local QRegularExpression sRxSwapChars( u
"\\s"_s );
190 laundered.replace( sRxSwapChars, u
"_"_s );
192 const thread_local QRegularExpression sRxRemoveChars( u
"[^a-zA-Z0-9_]"_s );
193 laundered.replace( sRxRemoveChars, QString() );
211 if ( providerType ==
"wms"_L1 )
215 QVariantMap details = metadata->decodeUri( uri );
216 url = QUrl( details.value( u
"url"_s ).toString() );
219 else if ( providerType ==
"xyzvectortiles"_L1 )
223 QVariantMap details = metadata->decodeUri( uri );
224 url = QUrl( details.value( u
"url"_s ).toString() );
227 return !url.isEmpty() && ( url.host().endsWith(
".openstreetmap.org"_L1 ) || url.host().endsWith(
".osm.org"_L1 ) );
235 return QObject::tr(
"Vector" );
237 return QObject::tr(
"Raster" );
239 return QObject::tr(
"Mesh" );
241 return QObject::tr(
"Point Cloud" );
243 return QObject::tr(
"Annotation" );
245 return QObject::tr(
"Vector Tile" );
247 return QObject::tr(
"Plugin" );
249 return QObject::tr(
"Group" );
251 return QObject::tr(
"Tiled Scene" );
264 if ( title.isEmpty() )
265 title = layer->
name();
266 title =
"<b>" + title +
"</b>";
269 QString layerCrs = layer->
crs().
authid();
274 if (
const QgsVectorLayer *vl = qobject_cast<const QgsVectorLayer *>( layer ) )
277 title = QObject::tr(
"%1 (%2)" ).arg( title, layerCrs );
282 if ( !abstract.isEmpty() )
283 parts <<
"<br/>" + abstract.replace(
"\n"_L1,
"<br/>"_L1 );
287 parts << QObject::tr(
"ID: %1" ).arg( layer->
id() );
289 return parts.join(
"<br/>"_L1 );
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.
SourceHierarchyLevel
Defines the structural levels within a data source hierarchy.
Provides common functionality for database based connections.
Represents a coordinate reference system (CRS).
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
double coordinateEpoch() const
Returns the coordinate epoch, as a decimal year.
Contains information about the context in which a coordinate transform is executed.
Custom exception class for Coordinate Reference System related exceptions.
QString title() const
Returns the title of the layer used by QGIS Server in GetCapabilities request.
QString shortName() const
Returns the short name of the layer used by QGIS Server to identify the layer.
QString abstract() const
Returns the abstract of the layerused by QGIS Server in GetCapabilities request.
static QString layerToolTip(const QgsMapLayer *layer)
Returns the consistent tooltip for the given layer.
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 bool layerRefersToUri(const QgsMapLayer *layer, const QString &uri, Qgis::SourceHierarchyLevel level=Qgis::SourceHierarchyLevel::Object)
Returns true if a layer and uri point to the same resource at the specified hierarchy level.
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.
static bool isOpenStreetMapUri(const QString &uri, const QString &providerType)
Returns true if the uri for a given provider is served by OpenStreetMap server.
Base class for all map layer types.
virtual bool isSpatial() const
Returns true if the layer is considered a spatial layer, ie it has some form of geometry associated w...
QString source() const
Returns the source for the layer.
QString providerType() const
Returns the provider type (provider key) for this layer.
QgsCoordinateReferenceSystem crs
QgsMapLayerServerProperties * serverProperties()
Returns QGIS Server Properties for the map layer.
void setDataSource(const QString &dataSource, const QString &baseName=QString(), const QString &provider=QString(), bool loadDefaultStyleFlag=false)
Updates the data source of the layer.
QgsLayerMetadata metadata
QString publicSource(bool hidePassword=false) const
Gets a version of the internal layer definition that has sensitive bits removed (for example,...
Custom exception class which is raised when an operation is not supported.
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 rounded to the spec...
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).
static const QgsSettingsEntryBool * settingsLayerTreeShowIdInLayerTooltips
Settings entry for hidden ID in layer tooltips.
Represents a vector layer which manages a vector based dataset.
static Q_INVOKABLE QString displayString(Qgis::WkbType type)
Returns a non-translated display string type for a WKB type, e.g., the geometry name used in WKT geom...
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
#define QgsDebugMsgLevel(str, level)
#define QgsDebugError(str)