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 );
@ NotPopulated
Children not yet created.
@ Populated
Children created.
@ Fertile
Can create children. Even items without this capability may have children, but cannot create them,...
@ 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
QgsDataItem * parent() const
Gets item parent.
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 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 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).
bool open()
Tries to open the file, returns true on success.
QString metadataValue(const QString &key)
Requests metadata value for the given key.
QList< QgsMimeDataUtils::Uri > UriList
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.
QgsWkbTypes::Type 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.
QgsMapLayerType type() const
Returns the layer type.
QString driverName() const
Returns the layer's driver name.
QString name() const
Returns the layer's name.
A generic data item for file based layers.
QString layerName() const override
QVector< QgsDataItem * > createChildren() override
Create children.
QgsProviderSublayerItem(QgsDataItem *parent, const QString &name, const QgsProviderSublayerDetails &details, const QString &filePath)
Constructor for QgsProviderSublayerItem.
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 GeometryType geometryType(Type type) SIP_HOLDGIL
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
@ PointCloudLayer
Point cloud layer. Added in QGIS 3.18.
@ MeshLayer
Mesh layer. Added in QGIS 3.2.
@ VectorLayer
Vector layer.
@ RasterLayer
Raster layer.
@ GroupLayer
Composite group layer. Added in QGIS 3.24.
@ VectorTileLayer
Vector tile layer. Added in QGIS 3.14.
@ AnnotationLayer
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
@ PluginLayer
Plugin based layer.
std::unique_ptr< std::remove_pointer< GDALDatasetH >::type, GDALDatasetCloser > dataset_unique_ptr
Scoped GDAL dataset.
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.