QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
22 #include "qgsogrproviderutils.h"
25 #include "qgsgeopackagedataitems.h"
40 :
QgsLayerItem( parent, name, filePath.isEmpty() ? details.uri() : filePath, details.uri(), layerTypeFromSublayer( details ), details.providerKey() )
57 if ( mDetails.
driverName() == QLatin1String(
"SQLite" ) )
60 path() + QStringLiteral(
"/columns/ " ),
61 QStringLiteral( R
"(dbname="%1")" ).arg( parent()->path().replace( '"', QLatin1String( R
"(\")" ) ) ),
62 QStringLiteral( "spatialite" ), QString(),
name() ) );
70 switch ( sublayer.
type() )
118 return mDetails.
name();
127 , mSublayers( sublayers )
136 mIconName = QStringLiteral(
"/mIconZip.svg" );
142 QList< QgsProviderSublayerDetails> sublayers;
144 || mSublayers.empty() )
150 sublayers = mSublayers;
159 children.reserve( sublayers.size() );
178 collectionUri.
layerType = QStringLiteral(
"collection" );
180 return { collectionUri };
186 const QFileInfo fi(
mPath );
187 if ( fi.suffix().toLower() != QLatin1String(
"sqlite" ) && fi.suffix().toLower() != QLatin1String(
"db" ) )
195 if ( OGRGetDriverCount() == 0 )
200 CPLPushErrorHandler( CPLQuietErrorHandler );
202 gdal::dataset_unique_ptr hDS( GDALOpenEx(
path().toUtf8().constData(), GDAL_OF_VECTOR | GDAL_OF_READONLY,
nullptr,
nullptr,
nullptr ) );
203 CPLPopErrorHandler();
207 QgsDebugMsgLevel( QStringLiteral(
"GDALOpen error # %1 : %2 on %3" ).arg( CPLGetLastErrorNo() ).arg( CPLGetLastErrorMsg() ).arg(
path() ), 2 );
211 GDALDriverH hDriver = GDALGetDatasetDriver( hDS.get() );
212 QString driverName = GDALGetDriverShortName( hDriver );
214 if ( driverName == QLatin1String(
"SQLite" ) )
233 return QStringLiteral(
"files" );
243 if ( path.isEmpty() )
246 const QFileInfo info( path );
247 QString suffix = info.suffix().toLower();
248 const QString
name = info.fileName();
251 if ( suffix.compare( QLatin1String(
"gpkg" ), Qt::CaseInsensitive ) == 0 )
254 QgsGeoPackageCollectionItem *item =
new QgsGeoPackageCollectionItem( parentItem,
name, path );
258 else if ( suffix == QLatin1String(
"txt" ) )
266 else if ( suffix == QLatin1String(
"map" ) || suffix == QLatin1String(
"dat" ) )
268 if ( QFile::exists( QDir( info.path() ).filePath( info.baseName() +
".tab" ) ) || QFile::exists( QDir( info.path() ).filePath( info.baseName() +
".TAB" ) ) )
272 else if ( suffix == QLatin1String(
"dbf" ) || suffix == QLatin1String(
"shx" ) )
274 if ( QFile::exists( QDir( info.path() ).filePath( info.baseName() +
".shp" ) ) || QFile::exists( QDir( info.path() ).filePath( info.baseName() +
".SHP" ) ) )
283 else if ( path.endsWith( QLatin1String(
".shp.zip" ), Qt::CaseInsensitive ) &&
284 GDALIdentifyDriverEx( path.toUtf8().constData(), GDAL_OF_VECTOR,
nullptr,
nullptr ) )
286 suffix = QStringLiteral(
"shp.zip" );
289 else if ( suffix == QLatin1String(
"mbtiles" ) )
294 if ( reader.
metadataValue( QStringLiteral(
"format" ) ) == QLatin1String(
"pbf" ) )
298 uq.addQueryItem( QStringLiteral(
"type" ), QStringLiteral(
"mbtiles" ) );
299 uq.addQueryItem( QStringLiteral(
"url" ), path );
300 const QString encodedUri = uq.toString();
301 QgsVectorTileLayerItem *item =
new QgsVectorTileLayerItem( parentItem,
name, path, encodedUri );
309 uq.addQueryItem( QStringLiteral(
"type" ), QStringLiteral(
"mbtiles" ) );
310 uq.addQueryItem( QStringLiteral(
"url" ), QUrl::fromLocalFile( path ).toString() );
311 const QString encodedUri = uq.toString();
326 Qgis::SublayerQueryFlags queryFlags = Qgis::SublayerQueryFlags();
329 if ( ( settings.
value( QStringLiteral(
"qgis/scanItemsInBrowser2" ),
330 "extension" ).toString() == QLatin1String(
"extension" ) ) ||
331 ( parentItem && settings.
value( QStringLiteral(
"qgis/scanItemsFastScanUris" ),
332 QStringList() ).toStringList().contains( parentItem->
path() ) ) )
339 if ( sublayers.size() == 1
348 else if ( !sublayers.empty() )
362 QFileInfo info( path );
363 QString suffix = info.suffix().toLower();
365 QStringList dirExtensions = QgsOgrProviderUtils::directoryExtensions();
366 return dirExtensions.contains( suffix );
bool handlesDirectoryPath(const QString &path) override
Returns true if the provider will handle the directory at the specified path.
QString uri
Identifier of the data source recognized by its providerKey.
bool hasDragEnabled() const override
Returns true if the item may be dragged.
Class for storing the component parts of a RDBMS data source URI (e.g. a Postgres data source).
A Collection: logical collection of layers or subcollections, e.g. GRASS location/mapset,...
static bool isXmlStyleFile(const QString &path)
Tests if the file at path is a QGIS style XML file.
QString driverName() const
Returns the layer's driver name.
QList< QgsProviderSublayerDetails > querySublayers(const QString &uri, Qgis::SublayerQueryFlags flags=Qgis::SublayerQueryFlags(), QgsFeedback *feedback=nullptr) const
Queries the specified uri and returns a list of any valid sublayers found in the dataset which can be...
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
@ MeshLayer
Mesh layer. Added in QGIS 3.2.
@ VectorLayer
Vector layer.
@ NotPopulated
Children not yet created.
#define QgsDebugMsgLevel(str, level)
QString uri() const
Returns the layer's URI.
A generic data item for file based layers.
QString layerType
Type of URI.
QgsAbstractDatabaseProviderConnection * databaseConnection() const override
For data items that represent a DB connection or one of its children, this method returns a connectio...
@ AnnotationLayer
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
bool open()
Tries to open the file, returns true on success.
@ PointCloud
Point cloud layer.
QgsFileDataCollectionItem(QgsDataItem *parent, const QString &name, const QString &path, const QList< QgsProviderSublayerDetails > &sublayers)
Constructor for QgsFileDataCollectionItem.
void setDatabase(const QString &database)
Sets the URI database name.
QString name() const
Returns the name of the item (the displayed text for the item).
This class is a composition of two QSettings instances:
@ FastScan
Indicates that the provider must scan for sublayers using the fastest possible approach – e....
QList< QgsMimeDataUtils::Uri > UriList
A collection of field items with some internal logic to retrieve the fields and a the vector layer in...
BrowserLayerType
Browser item layer types.
QgsMimeDataUtils::UriList mimeUris() const override
Returns mime URIs for the data item, most data providers will only return a single URI but some data ...
A data collection item for file based data collections (e.g. NetCDF files).
static bool sublayerDetailsAreIncomplete(const QList< QgsProviderSublayerDetails > &details, QgsProviderUtils::SublayerCompletenessFlags flags=QgsProviderUtils::SublayerCompletenessFlags())
Returns true if the sublayer details are incomplete, and require a more in-depth scan.
@ Plugin
Plugin based layer.
Utility class for reading and writing MBTiles files (which are SQLite3 databases).
@ ItemRepresentsFile
Item's path() directly represents a file on disk (since QGIS 3.22)
std::unique_ptr< std::remove_pointer< GDALDatasetH >::type, GDALDatasetCloser > dataset_unique_ptr
Scoped GDAL dataset.
QgsDataItem * parent() const
Gets item parent.
@ GroupLayer
Composite group layer. Added in QGIS 3.24.
@ RasterLayer
Raster layer.
@ Populated
Children created.
virtual void setState(Qgis::BrowserItemState state)
Set item state.
Contains details about a sub layer available from a dataset.
QString filePath
Path to file, if uri is associated with a file.
@ IgnoreUnknownFeatureCount
Indicates that an unknown feature count should not be considered as incomplete.
QgsProviderMetadata * providerMetadata(const QString &providerKey) const
Returns metadata of the provider or nullptr if not found.
QString qgsVsiPrefix(const QString &path)
QString metadataValue(const QString &key) const
Requests metadata value for the given key.
QString name() const
Returns the layer's name.
@ VectorTile
Vector tile layer.
@ IgnoreUnknownGeometryType
Indicates that an unknown geometry type should not be considered as incomplete.
virtual void setCapabilities(Qgis::BrowserItemCapabilities capabilities)
Sets the capabilities for the data item.
QgsProviderSublayerItem(QgsDataItem *parent, const QString &name, const QgsProviderSublayerDetails &details, const QString &filePath)
Constructor for QgsProviderSublayerItem.
@ VectorTileLayer
Vector tile layer. Added in QGIS 3.14.
QString name() override
Human-readable name of the provider name.
static GeometryType geometryType(Type type) SIP_HOLDGIL
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
QgsMapLayerType type() const
Returns the layer type.
QVector< QgsDataItem * > children() const
QString uri(bool expandAuthConfig=true) const
Returns the complete URI as a string.
Item that represents a layer that can be opened with one of the providers.
QgsWkbTypes::Type wkbType() const
Returns the layer's WKB type, or QgsWkbTypes::Unknown if the WKB type is not application or unknown.
@ Point
Vector point layer.
virtual Qgis::BrowserItemCapabilities capabilities2() const
Returns the capabilities for the data item.
@ ResolveGeometryType
Attempt to resolve the geometry type for vector sublayers.
@ TableLayer
Vector non-spatial layer.
QgsDataItem * createDataItem(const QString &path, QgsDataItem *parentItem) override
Create a new instance of QgsDataItem (or nullptr) for given path and parent item.
@ Fast
CreateChildren() is fast enough to be run in main thread when refreshing items, most root items (wms,...
QVector< QgsDataItem * > createChildren() override
Create children.
QVector< QgsDataItem * > createChildren() override
Create children.
int capabilities() const override
Returns combination of flags from QgsDataProvider::DataCapabilities.
Base class for all items in the model.
@ PointCloudLayer
Point cloud layer. Added in QGIS 3.18.
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
QString layerName() const override
The QgsAbstractDatabaseProviderConnection class provides common functionality for DB based connection...
@ Fertile
Can create children. Even items without this capability may have children, but cannot create them,...
@ PluginLayer
Plugin based layer.
@ Polygon
Vector polygon layer.
@ Vector
Generic vector layer.