QGIS API Documentation 3.32.0-Lima (311a8cb8a6)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
qgsfilebaseddataitemprovider.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsfilebaseddataitemprovider.cpp
3 --------------------------------------
4 Date : July 2021
5 Copyright : (C) 2021 by Nyall Dawson
6 Email : nyall dot dawson at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
17#include "qgsdataprovider.h"
18#include "qgsproviderregistry.h"
19#include "qgslogger.h"
20#include "qgssettings.h"
21#include "qgsogrproviderutils.h"
22#include "qgsstyle.h"
23#include "qgsgeopackagedataitems.h"
25#include "qgsfieldsitem.h"
26#include "qgsfielddomainsitem.h"
28#include "qgsproviderutils.h"
29#include "qgsprovidermetadata.h"
30#include "qgsgdalutils.h"
31#include <QUrlQuery>
32
33//
34// QgsProviderSublayerItem
35//
36
38 const QgsProviderSublayerDetails &details, const QString &filePath )
39 : QgsLayerItem( parent, name, filePath.isEmpty() ? details.uri() : filePath, details.uri(), layerTypeFromSublayer( details ), details.providerKey() )
40 , mDetails( details )
41{
42 mToolTip = details.uri();
43
44 // no children, except for vector layers, which will show the fields item
46}
47
49{
50 QVector<QgsDataItem *> children;
51
52 if ( mDetails.type() == Qgis::LayerType::Vector )
53 {
54 // sqlite gets special handling because it delegates to the dedicated spatialite provider
55 if ( mDetails.driverName() == QLatin1String( "SQLite" ) )
56 {
57 children.push_back( new QgsFieldsItem( this,
58 path() + QStringLiteral( "/columns/ " ),
59 QStringLiteral( R"(dbname="%1")" ).arg( parent()->path().replace( '"', QLatin1String( R"(\")" ) ) ),
60 QStringLiteral( "spatialite" ), QString(), name() ) );
61 }
62 else if ( mDetails.providerKey() == QLatin1String( "ogr" ) )
63 {
64 // otherwise we use the default OGR database connection approach, which is the generic way to handle this
65 // for all OGR layer types
66 children.push_back( new QgsFieldsItem( this,
67 path() + QStringLiteral( "/columns/ " ),
68 path(),
69 QStringLiteral( "ogr" ), QString(), name() ) );
70
71 std::unique_ptr<QgsAbstractDatabaseProviderConnection> conn( databaseConnection() );
72 if ( conn && ( conn->capabilities() & QgsAbstractDatabaseProviderConnection::Capability::RetrieveRelationships ) )
73 {
74 QString relationError;
75 QList< QgsWeakRelation > relations;
76 try
77 {
78 relations = conn->relationships( QString(), mDetails.name() );
79 }
81 {
82 relationError = ex.what();
83 }
84
85 if ( !relations.empty() || !relationError.isEmpty() )
86 {
87 std::unique_ptr< QgsRelationshipsItem > relationsItem = std::make_unique< QgsRelationshipsItem >( this, mPath + "/relations", conn->uri(), QStringLiteral( "ogr" ), QString(), mDetails.name() );
88 // force this item to appear last by setting a maximum string value for the sort key
89 relationsItem->setSortKey( QString( QChar( 0x11FFFF ) ) );
90 children.append( relationsItem.release() );
91 }
92 }
93 }
94 }
95 return children;
96}
97
99{
100 return mDetails;
101}
102
104{
105 if ( parent() )
106 {
108 return connection;
109 }
110
111 if ( mDetails.providerKey() == QLatin1String( "ogr" ) )
112 {
113 if ( QgsProviderMetadata *md = QgsProviderRegistry::instance()->providerMetadata( QStringLiteral( "ogr" ) ) )
114 {
115 QVariantMap parts;
116 parts.insert( QStringLiteral( "path" ), path() );
117 return static_cast<QgsAbstractDatabaseProviderConnection *>( md->createConnection( md->encodeUri( parts ), {} ) );
118 }
119 }
120
121 return nullptr;
122}
123
124Qgis::BrowserLayerType QgsProviderSublayerItem::layerTypeFromSublayer( const QgsProviderSublayerDetails &sublayer )
125{
126 switch ( sublayer.type() )
127 {
128 case Qgis::LayerType::Vector:
129 {
130 switch ( QgsWkbTypes::geometryType( sublayer.wkbType() ) )
131 {
132 case Qgis::GeometryType::Point:
134
135 case Qgis::GeometryType::Line:
137
138 case Qgis::GeometryType::Polygon:
140
141 case Qgis::GeometryType::Null:
143
144 case Qgis::GeometryType::Unknown:
146 }
147
148 break;
149 }
150 case Qgis::LayerType::Raster:
152
153 case Qgis::LayerType::Plugin:
155
156 case Qgis::LayerType::Mesh:
158
159 case Qgis::LayerType::VectorTile:
161
162 case Qgis::LayerType::PointCloud:
164
165 case Qgis::LayerType::Annotation:
166 case Qgis::LayerType::Group:
167 break;
168 }
170}
171
173{
174 return mDetails.name();
175}
176
177//
178// QgsFileDataCollectionGroupItem
179//
180QgsFileDataCollectionGroupItem::QgsFileDataCollectionGroupItem( QgsDataItem *parent, const QString &groupName, const QString &path )
181 : QgsDataCollectionItem( parent, groupName, path )
182{
184 mIconName = QStringLiteral( "mIconDbSchema.svg" );
185}
186
188{
189 mSublayers.append( sublayer );
190}
191
193{
194 return true;
195}
196
198{
200 res.reserve( mSublayers.size() );
201
202 for ( const QgsProviderSublayerDetails &sublayer : mSublayers )
203 {
204 res << sublayer.toMimeUri();
205 }
206 return res;
207}
208
209//
210// QgsFileDataCollectionItem
211//
212
213QgsFileDataCollectionItem::QgsFileDataCollectionItem( QgsDataItem *parent, const QString &name, const QString &path, const QList<QgsProviderSublayerDetails> &sublayers )
214 : QgsDataCollectionItem( parent, name, path )
215 , mSublayers( sublayers )
216{
219 else
221
222 if ( !QgsGdalUtils::vsiPrefixForPath( path ).isEmpty() )
223 {
224 mIconName = QStringLiteral( "/mIconZip.svg" );
225 }
226}
227
229{
230 QList< QgsProviderSublayerDetails> sublayers;
232 || mSublayers.empty() )
233 {
235 }
236 else
237 {
238 sublayers = mSublayers;
239 }
240 // only ever use the initial sublayers for first population -- after that we requery when asked to create children,
241 // or the item won't "refresh" and update its sublayers when the actual file changes
242 mSublayers.clear();
243 // remove the fast flag -- after the first population we need to requery the dataset
245
246 QVector<QgsDataItem *> children;
247 children.reserve( sublayers.size() );
248 QMap< QStringList, QgsFileDataCollectionGroupItem * > groupItems;
249 for ( const QgsProviderSublayerDetails &sublayer : std::as_const( sublayers ) )
250 {
251 QgsProviderSublayerItem *item = new QgsProviderSublayerItem( nullptr, sublayer.name(), sublayer, QString() );
252
253 if ( !sublayer.path().isEmpty() )
254 {
255 QStringList currentPath;
256 QStringList remainingPaths = sublayer.path();
257 QgsFileDataCollectionGroupItem *groupItem = nullptr;
258
259 while ( !remainingPaths.empty() )
260 {
261 currentPath << remainingPaths.takeAt( 0 );
262
263 auto it = groupItems.constFind( currentPath );
264 if ( it == groupItems.constEnd() )
265 {
266 QgsFileDataCollectionGroupItem *newGroupItem = new QgsFileDataCollectionGroupItem( this, currentPath.constLast(), path() + '/' + currentPath.join( ',' ) );
268 groupItems.insert( currentPath, newGroupItem );
269 if ( groupItem )
270 groupItem->addChildItem( newGroupItem );
271 else
272 children.append( newGroupItem );
273 groupItem = newGroupItem;
274 }
275 else
276 {
277 groupItem = it.value();
278 }
279
280 if ( groupItem )
281 groupItem->appendSublayer( sublayer );
282 }
283
284 if ( groupItem )
285 groupItem->addChildItem( item );
286 }
287 else
288 {
289 children.append( item );
290 }
291 }
292
293 std::unique_ptr<QgsAbstractDatabaseProviderConnection> conn( databaseConnection() );
294 if ( conn )
295 {
296 mCachedCapabilities = conn->capabilities();
297 mCachedCapabilities2 = conn->capabilities2();
298 mHasCachedCapabilities = true;
299 }
300 if ( conn && ( mCachedCapabilities & QgsAbstractDatabaseProviderConnection::Capability::ListFieldDomains ) )
301 {
302 QString domainError;
303 QStringList fieldDomains;
304 try
305 {
306 fieldDomains = conn->fieldDomainNames();
307 }
309 {
310 domainError = ex.what();
311 }
312
313 if ( !fieldDomains.empty() || !domainError.isEmpty() )
314 {
315 std::unique_ptr< QgsFieldDomainsItem > domainsItem = std::make_unique< QgsFieldDomainsItem >( this, mPath + "/domains", conn->uri(), QStringLiteral( "ogr" ) );
316 // force this item to appear last by setting a maximum string value for the sort key
317 domainsItem->setSortKey( QString( QChar( 0x10FFFF ) ) );
318 children.append( domainsItem.release() );
319 }
320 }
321 if ( conn && ( mCachedCapabilities & QgsAbstractDatabaseProviderConnection::Capability::RetrieveRelationships ) )
322 {
323 QString relationError;
324 QList< QgsWeakRelation > relations;
325 try
326 {
327 relations = conn->relationships();
328 }
330 {
331 relationError = ex.what();
332 }
333
334 if ( !relations.empty() || !relationError.isEmpty() )
335 {
336 std::unique_ptr< QgsRelationshipsItem > relationsItem = std::make_unique< QgsRelationshipsItem >( this, mPath + "/relations", conn->uri(), QStringLiteral( "ogr" ) );
337 // force this item to appear last by setting a maximum string value for the sort key
338 relationsItem->setSortKey( QString( QChar( 0x11FFFF ) ) );
339 children.append( relationsItem.release() );
340 }
341 }
342
343 return children;
344}
345
347{
348 return true;
349}
350
352{
353 // if we've previously opened a connection for this item, we can use the previously
354 // determined capababilities to return an accurate answer.
355 if ( mHasCachedCapabilities )
356 return mCachedCapabilities & QgsAbstractDatabaseProviderConnection::Capability::CreateVectorTable;
357
358 if ( mHasCachedDropSupport )
359 return mCachedSupportsDrop;
360
361 // otherwise, we are limited to VERY VERY cheap calculations only!!
362 // DO NOT UNDER *****ANY***** CIRCUMSTANCES OPEN DATASETS HERE!!!!
363
364 mHasCachedDropSupport = true;
365 if ( !QFileInfo( path() ).isWritable() )
366 {
367 mCachedSupportsDrop = false;
368 return mCachedSupportsDrop;
369 }
370
371 GDALDriverH hDriver = GDALIdentifyDriverEx( path().toUtf8().constData(), GDAL_OF_VECTOR, nullptr, nullptr );
372 if ( !hDriver )
373 {
374 mCachedSupportsDrop = false;
375 return mCachedSupportsDrop;
376 }
377
378 // explicitly blocklist some drivers which we don't want to expose drop support for
379 const QString driverName = GDALGetDriverShortName( hDriver );
380 if ( driverName == QLatin1String( "PDF" )
381 || driverName == QLatin1String( "DXF" ) )
382 {
383 mCachedSupportsDrop = false;
384 return mCachedSupportsDrop;
385 }
386
387 // DO NOT UNDER *****ANY***** CIRCUMSTANCES OPEN DATASETS HERE!!!!
388#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3,4,0)
389 const bool isSingleTableDriver = GDALGetMetadataItem( hDriver, GDAL_DCAP_MULTIPLE_VECTOR_LAYERS, nullptr ) == nullptr;
390#else
391 const QFileInfo pathInfo( path() );
392 const QString suffix = pathInfo.suffix().toLower();
393 const bool isSingleTableDriver = !QgsGdalUtils::multiLayerFileExtensions().contains( suffix );
394#endif
395
396 if ( isSingleTableDriver )
397 {
398 mCachedSupportsDrop = false;
399 return mCachedSupportsDrop;
400 }
401
402 // DO NOT UNDER *****ANY***** CIRCUMSTANCES OPEN DATASETS HERE!!!!
403 mCachedSupportsDrop = true;
404 return mCachedSupportsDrop;
405}
406
408{
409 QgsMimeDataUtils::Uri collectionUri;
410 collectionUri.uri = path();
411 collectionUri.layerType = QStringLiteral( "collection" );
412 collectionUri.filePath = path();
413 return { collectionUri };
414}
415
417{
418 // test that file is valid with OGR
419 if ( OGRGetDriverCount() == 0 )
420 {
421 OGRRegisterAll();
422 }
423 // do not print errors, but write to debug
424 CPLPushErrorHandler( CPLQuietErrorHandler );
425 CPLErrorReset();
426 GDALDriverH hDriver = GDALIdentifyDriverEx( path().toUtf8().constData(), GDAL_OF_VECTOR, nullptr, nullptr );
427 CPLPopErrorHandler();
428
429 if ( ! hDriver )
430 {
431 QgsDebugMsgLevel( QStringLiteral( "GDALIdentifyDriverEx error # %1 : %2 on %3" ).arg( CPLGetLastErrorNo() ).arg( CPLGetLastErrorMsg() ).arg( path() ), 2 );
432 return nullptr;
433 }
434
435 const QString driverName = GDALGetDriverShortName( hDriver );
436 if ( driverName == QLatin1String( "PDF" )
437 || driverName == QLatin1String( "DXF" ) )
438 {
439 // unwanted drivers -- it's slow to create connections for these, and we don't really want
440 // to expose database capabilities for them (even though they kind of are database formats)
441 return nullptr;
442 }
443
445 if ( driverName == QLatin1String( "SQLite" ) )
446 {
447 // sqlite gets special handling, as we delegate to the native spatialite provider
448 if ( QgsProviderMetadata *md = QgsProviderRegistry::instance()->providerMetadata( QStringLiteral( "spatialite" ) ) )
449 {
451 uri.setDatabase( path( ) );
452 conn = static_cast<QgsAbstractDatabaseProviderConnection *>( md->createConnection( uri.uri(), {} ) );
453 }
454 }
455 else
456 {
457 // for all other vector types we use the generic OGR provider
458 if ( QgsProviderMetadata *md = QgsProviderRegistry::instance()->providerMetadata( QStringLiteral( "ogr" ) ) )
459 {
460 QVariantMap parts;
461 parts.insert( QStringLiteral( "path" ), path() );
462 conn = static_cast<QgsAbstractDatabaseProviderConnection *>( md->createConnection( md->encodeUri( parts ), {} ) );
463 }
464 }
465
466 if ( conn )
467 {
468 mCachedCapabilities = conn->capabilities();
469 mCachedCapabilities2 = conn->capabilities2();
470 mHasCachedCapabilities = true;
471 }
472
473 return conn;
474}
475
476QgsAbstractDatabaseProviderConnection::Capabilities QgsFileDataCollectionItem::databaseConnectionCapabilities() const
477{
478 if ( mHasCachedCapabilities )
479 return mCachedCapabilities;
480
481 std::unique_ptr<QgsAbstractDatabaseProviderConnection> conn( databaseConnection() );
482 if ( conn )
483 {
484 mCachedCapabilities = conn->capabilities();
485 mCachedCapabilities2 = conn->capabilities2();
486 mHasCachedCapabilities = true;
487 }
488 return mCachedCapabilities;
489}
490
491Qgis::DatabaseProviderConnectionCapabilities2 QgsFileDataCollectionItem::databaseConnectionCapabilities2() const
492{
493 if ( mHasCachedCapabilities )
494 return mCachedCapabilities2;
495
496 std::unique_ptr<QgsAbstractDatabaseProviderConnection> conn( databaseConnection() );
497 if ( conn )
498 {
499 mCachedCapabilities = conn->capabilities();
500 mCachedCapabilities2 = conn->capabilities2();
501 mHasCachedCapabilities = true;
502 }
503 return mCachedCapabilities2;
504}
505
506//
507// QgsFileBasedDataItemProvider
508//
509
511{
512 return QStringLiteral( "files" );
513}
514
516{
518}
519
521{
522 if ( path.isEmpty() )
523 return nullptr;
524
525 const QFileInfo info( path );
526 QString suffix = info.suffix().toLower();
527 const QString name = info.fileName();
528
529 // special handling for some suffixes
530 if ( suffix.compare( QLatin1String( "gpkg" ), Qt::CaseInsensitive ) == 0 )
531 {
532 // Geopackage is special -- it gets a dedicated collection item type
533 QgsGeoPackageCollectionItem *item = new QgsGeoPackageCollectionItem( parentItem, name, path );
534 item->setCapabilities( item->capabilities2() | Qgis::BrowserItemCapability::ItemRepresentsFile );
535 return item;
536 }
537 else if ( suffix == QLatin1String( "txt" ) )
538 {
539 // never ever show .txt files as datasets in browser -- they are only used for geospatial data in extremely rare cases
540 // and are predominantly just noise in the browser
541 return nullptr;
542 }
543 // If a .tab exists, then the corresponding .map/.dat is very likely a
544 // side-car file of the .tab
545 else if ( suffix == QLatin1String( "map" ) || suffix == QLatin1String( "dat" ) )
546 {
547 if ( QFile::exists( QDir( info.path() ).filePath( info.baseName() + ".tab" ) ) || QFile::exists( QDir( info.path() ).filePath( info.baseName() + ".TAB" ) ) )
548 return nullptr;
549 }
550 // .dbf and .shx should only appear if .shp is not present
551 else if ( suffix == QLatin1String( "dbf" ) || suffix == QLatin1String( "shx" ) )
552 {
553 if ( QFile::exists( QDir( info.path() ).filePath( info.baseName() + ".shp" ) ) || QFile::exists( QDir( info.path() ).filePath( info.baseName() + ".SHP" ) ) )
554 return nullptr;
555 }
556 // skip QGIS style xml files
557 else if ( suffix == QLatin1String( "xml" ) && QgsStyle::isXmlStyleFile( path ) )
558 {
559 return nullptr;
560 }
561 // GDAL 3.1 Shapefile driver directly handles .shp.zip files
562 else if ( path.endsWith( QLatin1String( ".shp.zip" ), Qt::CaseInsensitive ) &&
563 GDALIdentifyDriverEx( path.toUtf8().constData(), GDAL_OF_VECTOR, nullptr, nullptr ) )
564 {
565 suffix = QStringLiteral( "shp.zip" );
566 }
567
568 // hide blocklisted URIs, such as .aux.xml files
569 if ( QgsProviderRegistry::instance()->uriIsBlocklisted( path ) )
570 return nullptr;
571
572 QgsSettings settings;
573
574 Qgis::SublayerQueryFlags queryFlags = Qgis::SublayerQueryFlags();
575
576 // should we fast scan only?
577 if ( ( settings.value( QStringLiteral( "qgis/scanItemsInBrowser2" ),
578 "extension" ).toString() == QLatin1String( "extension" ) ) ||
579 ( parentItem && settings.value( QStringLiteral( "qgis/scanItemsFastScanUris" ),
580 QStringList() ).toStringList().contains( parentItem->path() ) ) )
581 {
583 }
584
585 const QList<QgsProviderSublayerDetails> sublayers = QgsProviderRegistry::instance()->querySublayers( path, queryFlags );
586
587 if ( sublayers.size() == 1
590 )
591 {
592 QgsProviderSublayerItem *item = new QgsProviderSublayerItem( parentItem, name, sublayers.at( 0 ), path );
594 return item;
595 }
596 else if ( !sublayers.empty() )
597 {
598 QgsFileDataCollectionItem *item = new QgsFileDataCollectionItem( parentItem, name, path, sublayers );
600 return item;
601 }
602 else
603 {
604 return nullptr;
605 }
606}
607
609{
610 QFileInfo info( path );
611 QString suffix = info.suffix().toLower();
612
613 QStringList dirExtensions = QgsOgrProviderUtils::directoryExtensions();
614 return dirExtensions.contains( suffix );
615}
@ 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.
Definition: qgis.h:605
@ Point
Vector point layer.
@ Plugin
Plugin based layer.
@ Line
Vector line layer.
@ Polygon
Vector polygon layer.
@ Vector
Generic vector layer.
@ VectorTile
Vector tile layer.
@ Raster
Raster layer.
@ TableLayer
Vector non-spatial layer.
@ PointCloud
Point cloud layer.
The QgsAbstractDatabaseProviderConnection class provides common functionality for DB based connection...
Qgis::DatabaseProviderConnectionCapabilities2 capabilities2() const
Returns extended connection capabilities.
Capabilities capabilities() const
Returns connection capabilities.
A Collection: logical collection of layers or subcollections, e.g.
Base class for all items in the model.
Definition: qgsdataitem.h:46
QString mToolTip
Definition: qgsdataitem.h:456
QString mPath
Definition: qgsdataitem.h:455
QVector< QgsDataItem * > children() const
Definition: qgsdataitem.h:337
Qgis::BrowserItemCapabilities mCapabilities
Definition: qgsdataitem.h:445
QString mIconName
Definition: qgsdataitem.h:457
QString name() const
Returns the name of the item (the displayed text for the item).
Definition: qgsdataitem.h:345
QString path() const
Definition: qgsdataitem.h:354
virtual void setState(Qgis::BrowserItemState state)
Set item state.
virtual void setCapabilities(Qgis::BrowserItemCapabilities capabilities)
Sets the capabilities for the data item.
Definition: qgsdataitem.h:310
virtual void addChildItem(QgsDataItem *child, bool refresh=false)
Inserts a new child item.
QgsDataItem * parent() const
Gets item parent.
Definition: qgsdataitem.h:330
virtual Qgis::BrowserItemCapabilities capabilities2() const
Returns the capabilities for the data item.
Definition: qgsdataitem.h:303
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.
QString what() const
Definition: qgsexception.h:49
A collection of field items with some internal logic to retrieve the fields and a the vector layer in...
Definition: qgsfieldsitem.h:34
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.
QgsAbstractDatabaseProviderConnection::Capabilities databaseConnectionCapabilities() const
Returns the associated connection capabilities, if a databaseConnection() is available.
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 canAddVectorLayers() const
Returns true if the file is likely to support addition of vector layers.
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.
Qgis::DatabaseProviderConnectionCapabilities2 databaseConnectionCapabilities2() const
Returns extended connection capabilities, if a databaseConnection() is available.
static QString vsiPrefixForPath(const QString &path)
Returns a the vsi prefix which corresponds to a file path, or an empty string if the path is not asso...
static QStringList multiLayerFileExtensions()
Returns a list of file extensions which potentially contain multiple layers representing GDAL raster ...
Item that represents a layer that can be opened with one of the providers.
Definition: qgslayeritem.h:31
QList< QgsMimeDataUtils::Uri > UriList
Custom exception class for provider connection related exceptions.
Definition: qgsexception.h:102
Holds data provider key, description, and associated shared library file or function pointer informat...
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.
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:
Definition: qgssettings.h:63
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.
Definition: qgsstyle.cpp:3041
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...
Definition: qgswkbtypes.h:865
#define QgsDebugMsgLevel(str, level)
Definition: qgslogger.h:39
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.