28#include <QRegularExpression>
38 QgsDebugMsgLevel( QStringLiteral(
"Layer count: %1" ).arg( layers.count() ), 5 );
44 if ( layer->extent().isNull() )
60 QgsDebugError( QStringLiteral(
"Could not reproject layer extent" ) );
64 if ( fullExtent.
width() == 0.0 || fullExtent.
height() == 0.0 )
73 fullExtent.
set( -1.0, -1.0, 1.0, 1.0 );
77 const double padFactor = 1e-8;
78 const double widthPad = fullExtent.
xMinimum() * padFactor;
79 const double heightPad = fullExtent.
yMinimum() * padFactor;
80 const double xmin = fullExtent.
xMinimum() - widthPad;
81 const double xmax = fullExtent.
xMaximum() + widthPad;
82 const double ymin = fullExtent.
yMinimum() - heightPad;
83 const double ymax = fullExtent.
yMaximum() + heightPad;
84 fullExtent.
set( xmin, ymin, xmax, ymax );
102 if ( ! providerMetadata )
108 return conn.release();
112 QgsDebugError( QStringLiteral(
"Error retrieving database connection for layer %1: %2" ).arg( layer->
name(), ex.
what() ) );
119 if ( !layer || path.isEmpty() )
123 return parts.value( QStringLiteral(
"path" ) ).toString() == path;
128 if ( !layer || newPath.isEmpty() )
132 if ( !parts.contains( QStringLiteral(
"path" ) ) )
135 parts.insert( QStringLiteral(
"path" ), newPath );
143 QList< QgsMapLayer * > res = layers;
146 for ( Qgis::LayerType type : order )
148 if ( a->type() == type && b->type() != type )
150 else if ( b->type() == type )
160 QString laundered = name.toLower();
161 const thread_local QRegularExpression sRxSwapChars( QStringLiteral(
"\\s" ) );
162 laundered.replace( sRxSwapChars, QStringLiteral(
"_" ) );
164 const thread_local QRegularExpression sRxRemoveChars( QStringLiteral(
"[^a-zA-Z0-9_]" ) );
165 laundered.replace( sRxRemoveChars, QString() );
The QgsAbstractDatabaseProviderConnection class provides common functionality for DB based connection...
This class 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.
virtual QString name() const =0
Returns a provider name.
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 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 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, const QString &provider, bool loadDefaultStyleFlag=false)
Updates the data source of the layer.
virtual Q_INVOKABLE QgsDataProvider * dataProvider()
Returns the layer's data provider, 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.
QString toString(int precision=16) const
Returns a string representation of form xmin,ymin : xmax,ymax Coordinates will be truncated to the sp...
double yMaximum() const SIP_HOLDGIL
Returns the y maximum value (top side of rectangle).
double xMaximum() const SIP_HOLDGIL
Returns the x maximum value (right side of rectangle).
double xMinimum() const SIP_HOLDGIL
Returns the x minimum value (left side of rectangle).
double yMinimum() const SIP_HOLDGIL
Returns the y minimum value (bottom side of rectangle).
double height() const SIP_HOLDGIL
Returns the height of the rectangle.
void set(const QgsPointXY &p1, const QgsPointXY &p2, bool normalize=true)
Sets the rectangle from two QgsPoints.
void setMinimal() SIP_HOLDGIL
Set a rectangle so that min corner is at max and max corner is at min.
double width() const SIP_HOLDGIL
Returns the width of the rectangle.
void combineExtentWith(const QgsRectangle &rect)
Expands the rectangle so that it covers both the original rectangle and the given rectangle.
#define QgsDebugMsgLevel(str, level)
#define QgsDebugError(str)
const QgsCoordinateReferenceSystem & crs