29#include <QRegularExpression>
39 QgsDebugMsgLevel( QStringLiteral(
"Layer count: %1" ).arg( layers.count() ), 5 );
45 if ( layer->extent().isNull() )
61 QgsDebugMsg( QStringLiteral(
"Could not reproject layer extent" ) );
65 if ( fullExtent.
width() == 0.0 || fullExtent.
height() == 0.0 )
74 fullExtent.
set( -1.0, -1.0, 1.0, 1.0 );
78 const double padFactor = 1e-8;
79 const double widthPad = fullExtent.
xMinimum() * padFactor;
80 const double heightPad = fullExtent.
yMinimum() * padFactor;
81 const double xmin = fullExtent.
xMinimum() - widthPad;
82 const double xmax = fullExtent.
xMaximum() + widthPad;
83 const double ymin = fullExtent.
yMinimum() - heightPad;
84 const double ymax = fullExtent.
yMaximum() + heightPad;
85 fullExtent.
set( xmin, ymin, xmax, ymax );
103 if ( ! providerMetadata )
109 return conn.release();
113 QgsDebugMsg( QStringLiteral(
"Error retrieving database connection for layer %1: %2" ).arg( layer->
name(), ex.
what() ) );
120 if ( !layer || path.isEmpty() )
124 return parts.value( QStringLiteral(
"path" ) ).toString() == path;
129 if ( !layer || newPath.isEmpty() )
133 if ( !parts.contains( QStringLiteral(
"path" ) ) )
136 parts.insert( QStringLiteral(
"path" ), newPath );
144 QList< QgsMapLayer * > res = layers;
147 for ( QgsMapLayerType type : order )
149 if ( a->type() == type && b->type() != type )
151 else if ( b->type() == type )
161 QString laundered = name.toLower();
162 const thread_local QRegularExpression sRxSwapChars( QStringLiteral(
"\\s" ) );
163 laundered.replace( sRxSwapChars, QStringLiteral(
"_" ) );
165 const thread_local QRegularExpression sRxRemoveChars( QStringLiteral(
"[^a-zA-Z0-9_]" ) );
166 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 QList< QgsMapLayer * > sortLayersByType(const QList< QgsMapLayer * > &layers, const QList< QgsMapLayerType > &order)
Sorts a list of map layers by their layer type, respecting the order of types specified.
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 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)
const QgsCoordinateReferenceSystem & crs