21#include "qgsogrproviderutils.h"
23#include "qgsgeopackagedataitems.h"
40 :
QgsLayerItem( parent, name, filePath.isEmpty() ? details.uri() : filePath, details.uri(), layerTypeFromSublayer( details ), details.providerKey() )
53 if ( mDetails.
type() == Qgis::LayerType::Vector )
56 if ( mDetails.
driverName() == QLatin1String(
"SQLite" ) )
59 path() + QStringLiteral(
"/columns/ " ),
60 QStringLiteral( R
"(dbname="%1")" ).arg( parent()->path().replace( '"', QLatin1String( R
"(\")" ) ) ),
61 QStringLiteral( "spatialite" ), QString(),
name() ) );
63 else if ( mDetails.
providerKey() == QLatin1String(
"ogr" ) )
68 path() + QStringLiteral(
"/columns/ " ),
70 QStringLiteral(
"ogr" ), QString(),
name() ) );
73 if ( conn && ( conn->capabilities() & QgsAbstractDatabaseProviderConnection::Capability::RetrieveRelationships ) )
75 QString relationError;
76 QList< QgsWeakRelation > relations;
79 relations = conn->relationships( QString(), mDetails.
name() );
83 relationError = ex.
what();
86 if ( !relations.empty() || !relationError.isEmpty() )
88 std::unique_ptr< QgsRelationshipsItem > relationsItem = std::make_unique< QgsRelationshipsItem >(
this,
mPath +
"/relations", conn->uri(), QStringLiteral(
"ogr" ), QString(), mDetails.
name() );
90 relationsItem->setSortKey( QString( QChar( 0x11FFFF ) ) );
91 children.append( relationsItem.release() );
112 if ( mDetails.
providerKey() == QLatin1String(
"ogr" ) )
117 parts.insert( QStringLiteral(
"path" ),
path() );
127 switch ( sublayer.
type() )
129 case Qgis::LayerType::Vector:
133 case Qgis::GeometryType::Point:
136 case Qgis::GeometryType::Line:
139 case Qgis::GeometryType::Polygon:
142 case Qgis::GeometryType::Null:
145 case Qgis::GeometryType::Unknown:
151 case Qgis::LayerType::Raster:
154 case Qgis::LayerType::Plugin:
157 case Qgis::LayerType::Mesh:
160 case Qgis::LayerType::VectorTile:
163 case Qgis::LayerType::PointCloud:
166 case Qgis::LayerType::Annotation:
167 case Qgis::LayerType::Group:
175 return mDetails.
name();
185 mIconName = QStringLiteral(
"mIconDbSchema.svg" );
190 mSublayers.append( sublayer );
201 res.reserve( mSublayers.size() );
216 , mSublayers( sublayers )
225 mIconName = QStringLiteral(
"/mIconZip.svg" );
231 QList< QgsProviderSublayerDetails> sublayers;
233 || mSublayers.empty() )
239 sublayers = mSublayers;
248 children.reserve( sublayers.size() );
249 QMap< QStringList, QgsFileDataCollectionGroupItem * > groupItems;
254 if ( !sublayer.
path().isEmpty() )
256 QStringList currentPath;
257 QStringList remainingPaths = sublayer.
path();
260 while ( !remainingPaths.empty() )
262 currentPath << remainingPaths.takeAt( 0 );
264 auto it = groupItems.constFind( currentPath );
265 if ( it == groupItems.constEnd() )
269 groupItems.insert( currentPath, newGroupItem );
274 groupItem = newGroupItem;
278 groupItem = it.value();
295 if ( conn && ( conn->capabilities() & QgsAbstractDatabaseProviderConnection::Capability::ListFieldDomains ) )
298 QStringList fieldDomains;
301 fieldDomains = conn->fieldDomainNames();
305 domainError = ex.
what();
308 if ( !fieldDomains.empty() || !domainError.isEmpty() )
310 std::unique_ptr< QgsFieldDomainsItem > domainsItem = std::make_unique< QgsFieldDomainsItem >(
this,
mPath +
"/domains", conn->uri(), QStringLiteral(
"ogr" ) );
312 domainsItem->setSortKey( QString( QChar( 0x10FFFF ) ) );
313 children.append( domainsItem.release() );
316 if ( conn && ( conn->capabilities() & QgsAbstractDatabaseProviderConnection::Capability::RetrieveRelationships ) )
318 QString relationError;
319 QList< QgsWeakRelation > relations;
322 relations = conn->relationships();
326 relationError = ex.
what();
329 if ( !relations.empty() || !relationError.isEmpty() )
331 std::unique_ptr< QgsRelationshipsItem > relationsItem = std::make_unique< QgsRelationshipsItem >(
this,
mPath +
"/relations", conn->uri(), QStringLiteral(
"ogr" ) );
333 relationsItem->setSortKey( QString( QChar( 0x11FFFF ) ) );
334 children.append( relationsItem.release() );
350 collectionUri.
layerType = QStringLiteral(
"collection" );
352 return { collectionUri };
358 if ( OGRGetDriverCount() == 0 )
363 CPLPushErrorHandler( CPLQuietErrorHandler );
365 GDALDriverH hDriver = GDALIdentifyDriverEx(
path().toUtf8().constData(), GDAL_OF_VECTOR,
nullptr,
nullptr );
366 CPLPopErrorHandler();
370 QgsDebugMsgLevel( QStringLiteral(
"GDALIdentifyDriverEx error # %1 : %2 on %3" ).arg( CPLGetLastErrorNo() ).arg( CPLGetLastErrorMsg() ).arg(
path() ), 2 );
374 const QString driverName = GDALGetDriverShortName( hDriver );
375 if ( driverName == QLatin1String(
"PDF" ) )
383 if ( driverName == QLatin1String(
"SQLite" ) )
399 parts.insert( QStringLiteral(
"path" ),
path() );
412 return QStringLiteral(
"files" );
422 if ( path.isEmpty() )
425 const QFileInfo info( path );
426 QString suffix = info.suffix().toLower();
427 const QString
name = info.fileName();
430 if ( suffix.compare( QLatin1String(
"gpkg" ), Qt::CaseInsensitive ) == 0 )
433 QgsGeoPackageCollectionItem *item =
new QgsGeoPackageCollectionItem( parentItem,
name, path );
437 else if ( suffix == QLatin1String(
"txt" ) )
445 else if ( suffix == QLatin1String(
"map" ) || suffix == QLatin1String(
"dat" ) )
447 if ( QFile::exists( QDir( info.path() ).filePath( info.baseName() +
".tab" ) ) || QFile::exists( QDir( info.path() ).filePath( info.baseName() +
".TAB" ) ) )
451 else if ( suffix == QLatin1String(
"dbf" ) || suffix == QLatin1String(
"shx" ) )
453 if ( QFile::exists( QDir( info.path() ).filePath( info.baseName() +
".shp" ) ) || QFile::exists( QDir( info.path() ).filePath( info.baseName() +
".SHP" ) ) )
462 else if ( path.endsWith( QLatin1String(
".shp.zip" ), Qt::CaseInsensitive ) &&
463 GDALIdentifyDriverEx( path.toUtf8().constData(), GDAL_OF_VECTOR,
nullptr,
nullptr ) )
465 suffix = QStringLiteral(
"shp.zip" );
468 else if ( suffix == QLatin1String(
"mbtiles" ) )
473 if ( reader.
metadataValue( QStringLiteral(
"format" ) ) == QLatin1String(
"pbf" ) )
477 uq.addQueryItem( QStringLiteral(
"type" ), QStringLiteral(
"mbtiles" ) );
478 uq.addQueryItem( QStringLiteral(
"url" ), path );
479 const QString encodedUri = uq.toString();
480 QgsVectorTileLayerItem *item =
new QgsVectorTileLayerItem( parentItem,
name, path, encodedUri );
488 uq.addQueryItem( QStringLiteral(
"type" ), QStringLiteral(
"mbtiles" ) );
489 uq.addQueryItem( QStringLiteral(
"url" ), QUrl::fromLocalFile( path ).toString() );
490 const QString encodedUri = uq.toString();
505 Qgis::SublayerQueryFlags queryFlags = Qgis::SublayerQueryFlags();
508 if ( ( settings.
value( QStringLiteral(
"qgis/scanItemsInBrowser2" ),
509 "extension" ).toString() == QLatin1String(
"extension" ) ) ||
510 ( parentItem && settings.
value( QStringLiteral(
"qgis/scanItemsFastScanUris" ),
511 QStringList() ).toStringList().contains( parentItem->
path() ) ) )
518 if ( sublayers.size() == 1
527 else if ( !sublayers.empty() )
541 QFileInfo info( path );
542 QString suffix = info.suffix().toLower();
544 QStringList dirExtensions = QgsOgrProviderUtils::directoryExtensions();
545 return dirExtensions.contains( suffix );
@ NotPopulated
Children not yet created.
@ Populated
Children created.
@ Fertile
Can create children. Even items without this capability may have children, but cannot create them,...
@ RefreshChildrenWhenItemIsRefreshed
When the item is refreshed, all its populated children will also be refreshed in turn (since QGIS 3....
@ ItemRepresentsFile
Item's path() directly represents a file on disk (since QGIS 3.22)
@ Fast
CreateChildren() is fast enough to be run in main thread when refreshing items, most root items (wms,...
@ FastScan
Indicates that the provider must scan for sublayers using the fastest possible approach – e....
@ ResolveGeometryType
Attempt to resolve the geometry type for vector sublayers.
BrowserLayerType
Browser item layer types.
@ Point
Vector point layer.
@ Plugin
Plugin based layer.
@ Polygon
Vector polygon layer.
@ Vector
Generic vector layer.
@ VectorTile
Vector tile layer.
@ TableLayer
Vector non-spatial layer.
@ PointCloud
Point cloud layer.
The QgsAbstractDatabaseProviderConnection class provides common functionality for DB based connection...
A Collection: logical collection of layers or subcollections, e.g.
Base class for all items in the model.
QVector< QgsDataItem * > children() const
Qgis::BrowserItemCapabilities mCapabilities
QString name() const
Returns the name of the item (the displayed text for the item).
virtual void setState(Qgis::BrowserItemState state)
Set item state.
virtual void setCapabilities(Qgis::BrowserItemCapabilities capabilities)
Sets the capabilities for the data item.
virtual void addChildItem(QgsDataItem *child, bool refresh=false)
Inserts a new child item.
QgsDataItem * parent() const
Gets item parent.
virtual Qgis::BrowserItemCapabilities capabilities2() const
Returns the capabilities for the data item.
Class for storing the component parts of a RDBMS data source URI (e.g.
QString uri(bool expandAuthConfig=true) const
Returns the complete URI as a string.
void setDatabase(const QString &database)
Sets the URI database name.
A collection of field items with some internal logic to retrieve the fields and a the vector layer in...
QString name() override
Human-readable name of the provider name.
int capabilities() const override
Returns combination of flags from QgsDataProvider::DataCapabilities.
bool handlesDirectoryPath(const QString &path) override
Returns true if the provider will handle the directory at the specified path.
QgsDataItem * createDataItem(const QString &path, QgsDataItem *parentItem) override
Create a new instance of QgsDataItem (or nullptr) for given path and parent item.
A data collection item for grouping of the content in file based data collections (e....
QgsFileDataCollectionGroupItem(QgsDataItem *parent, const QString &groupName, const QString &path)
Constructor for QgsFileDataCollectionGroupItem.
void appendSublayer(const QgsProviderSublayerDetails &sublayer)
Adds a sublayer to the group.
QgsMimeDataUtils::UriList mimeUris() const override
Returns mime URIs for the data item, most data providers will only return a single URI but some data ...
bool hasDragEnabled() const override
Returns true if the item may be dragged.
A data collection item for file based data collections (e.g.
bool hasDragEnabled() const override
Returns true if the item may be dragged.
QVector< QgsDataItem * > createChildren() override
Create children.
QgsMimeDataUtils::UriList mimeUris() const override
Returns mime URIs for the data item, most data providers will only return a single URI but some data ...
QgsAbstractDatabaseProviderConnection * databaseConnection() const override
For data items that represent a DB connection or one of its children, this method returns a connectio...
QgsFileDataCollectionItem(QgsDataItem *parent, const QString &name, const QString &path, const QList< QgsProviderSublayerDetails > &sublayers)
Constructor for QgsFileDataCollectionItem.
Item that represents a layer that can be opened with one of the providers.
Utility class for reading and writing MBTiles files (which are SQLite3 databases).
QString metadataValue(const QString &key) const
Requests metadata value for the given key.
bool open()
Tries to open the file, returns true on success.
QList< QgsMimeDataUtils::Uri > UriList
Custom exception class for provider connection related exceptions.
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...
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
QgsProviderMetadata * providerMetadata(const QString &providerKey) const
Returns metadata of the provider or nullptr if not found.
Contains details about a sub layer available from a dataset.
QStringList path() const
Returns the path to the sublayer.
Qgis::LayerType type() const
Returns the layer type.
Qgis::WkbType wkbType() const
Returns the layer's WKB type, or QgsWkbTypes::Unknown if the WKB type is not application or unknown.
QString uri() const
Returns the layer's URI.
QgsMimeDataUtils::Uri toMimeUri() const
Converts the sublayer details to a QgsMimeDataUtils::Uri representing the sublayer.
QString driverName() const
Returns the layer's driver name.
QString providerKey() const
Returns the associated data provider key.
QString name() const
Returns the layer's name.
A generic data item for file based layers.
QString layerName() const override
QgsAbstractDatabaseProviderConnection * databaseConnection() const override
For data items that represent a DB connection or one of its children, this method returns a connectio...
QVector< QgsDataItem * > createChildren() override
Create children.
QgsProviderSublayerItem(QgsDataItem *parent, const QString &name, const QgsProviderSublayerDetails &details, const QString &filePath)
Constructor for QgsProviderSublayerItem.
QgsProviderSublayerDetails sublayerDetails() const
Returns the sublayer details for the item.
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.
@ IgnoreUnknownGeometryType
Indicates that an unknown geometry type should not be considered as incomplete.
@ IgnoreUnknownFeatureCount
Indicates that an unknown feature count should not be considered as incomplete.
This class is a composition of two QSettings instances:
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
static bool isXmlStyleFile(const QString &path)
Tests if the file at path is a QGIS style XML file.
static Qgis::GeometryType geometryType(Qgis::WkbType type) SIP_HOLDGIL
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
QString qgsVsiPrefix(const QString &path)
#define QgsDebugMsgLevel(str, level)
QString filePath
Path to file, if uri is associated with a file.
QString uri
Identifier of the data source recognized by its providerKey.
QString layerType
Type of URI.