QGIS API Documentation 4.3.0-Master (91d4a333d5d)
Loading...
Searching...
No Matches
qgsmaplayerutils.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsmaplayerutils.h
3 -------------------
4 begin : May 2021
5 copyright : (C) 2021 Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17#ifndef QGSMAPLAYERUTILS_H
18#define QGSMAPLAYERUTILS_H
19
20#define MAXIMUM_OPENSTREETMAP_TILES_FETCH 5000
21
22#include "qgis.h"
23#include "qgis_core.h"
24#include "qgis_sip.h"
25#include "qgsmaplayer.h"
26
27class QgsRectangle;
31class QgsGeometry;
32
38class CORE_EXPORT QgsMapLayerUtils
39{
40 public:
46 static QgsRectangle combinedExtent( const QList<QgsMapLayer *> &layers, const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &transformContext );
47
54
62 static bool layerSourceMatchesPath( const QgsMapLayer *layer, const QString &path );
63
81
90 static bool updateLayerSourcePath( QgsMapLayer *layer, const QString &newPath );
91
100 static QList< QgsMapLayer * > sortLayersByType( const QList< QgsMapLayer * > &layers, const QList< Qgis::LayerType > &order );
101
114 static QString launderLayerName( const QString &name );
115
121 static bool isOpenStreetMapLayer( QgsMapLayer *layer );
122
128 static bool isOpenStreetMapUri( const QString &uri, const QString &providerType );
129
135 static QString layerTypeToString( Qgis::LayerType type );
136
142 static QString layerToolTip( const QgsMapLayer *layer );
143
168 QgsMapLayer *layer,
169 const QString &providerKey,
170 const QString &targetDataSource,
171 const QString &name,
172 const QString &description,
173 bool useAsDefault,
174 const QString &uiFileContent,
177 );
178};
179
185class CORE_EXPORT QgsSaveStyleResult
186{
187 public:
190
192 QStringList sldErrorMessages;
193
196
199
201 QString qmlError;
202};
203#endif // QGSMAPLAYERUTILS_H
@ SLD
SLD style format.
Definition qgis.h:7348
@ QML
QML style format.
Definition qgis.h:7347
QFlags< SaveStyleFormat > SaveStyleFormats
Definition qgis.h:7351
LayerType
Types of layers that can be added to a map.
Definition qgis.h:206
SourceHierarchyLevel
Defines the structural levels within a data source hierarchy.
Definition qgis.h:1547
@ Object
Represents a specific data entity, e.g. a table, view, or layer.
Definition qgis.h:1550
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.
A geometry is the spatial representation of a feature.
Contains utility functions for working with map layers.
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 QgsSaveStyleResult saveLayerStyleToDatabase(QgsMapLayer *layer, const QString &providerKey, const QString &targetDataSource, const QString &name, const QString &description, bool useAsDefault, const QString &uiFileContent, const Qgis::SaveStyleFormats formats=Qgis::SaveStyleFormats(Qgis::SaveStyleFormat::QML|Qgis::SaveStyleFormat::SLD), QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories)
Saves QML and SLD representations of layer's style to a table in the database identified by providerK...
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.
Definition qgsmaplayer.h:84
QFlags< StyleCategory > StyleCategories
QFlags< SaveStyleResult > SaveStyleResults
Results of saving styles to database.
Custom exception class which is raised when an operation is not supported.
A rectangle specified with double values.
Represents the result of saving a style.
QStringList sldWarningMessages
List of warning messages generated while exporting the style to SLD.
QStringList sldErrorMessages
List of error messages generated while exporting the style to SLD.
QString qmlError
Error message generated while saving the style as QML, or an empty string if no error occurred.
QString providerSaveStyleError
Error message reported by the data provider when saving the style, or an empty string if no error occ...
QgsMapLayer::SaveStyleResults saveResult
Flags representing which style formats (QML and/or SLD) were successfully saved.
#define SIP_FACTORY
Definition qgis_sip.h:83
#define SIP_THROW(name,...)
Definition qgis_sip.h:215