QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
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 {
129 {
130 switch ( QgsWkbTypes::geometryType( sublayer.wkbType() ) )
131 {
134
137
140
143
146 }
147
148 break;
149 }
152
155
158
161
164
167
170 break;
171 }
173}
174
176{
177 return mDetails.name();
178}
179
180//
181// QgsFileDataCollectionGroupItem
182//
183QgsFileDataCollectionGroupItem::QgsFileDataCollectionGroupItem( QgsDataItem *parent, const QString &groupName, const QString &path )
184 : QgsDataCollectionItem( parent, groupName, path )
185{
187 mIconName = QStringLiteral( "mIconDbSchema.svg" );
188}
189
191{
192 mSublayers.append( sublayer );
193}
194
196{
197 return true;
198}
199
201{
203 res.reserve( mSublayers.size() );
204
205 for ( const QgsProviderSublayerDetails &sublayer : mSublayers )
206 {
207 res << sublayer.toMimeUri();
208 }
209 return res;
210}
211
212//
213// QgsFileDataCollectionItem
214//
215
216QgsFileDataCollectionItem::QgsFileDataCollectionItem( QgsDataItem *parent, const QString &name, const QString &path, const QList<QgsProviderSublayerDetails> &sublayers )
217 : QgsDataCollectionItem( parent, name, path )
218 , mSublayers( sublayers )
219{
222 else
224
225 if ( !QgsGdalUtils::vsiPrefixForPath( path ).isEmpty() )
226 {
227 mIconName = QStringLiteral( "/mIconZip.svg" );
228 }
229}
230
232{
233 QList< QgsProviderSublayerDetails> sublayers;
235 || mSublayers.empty() )
236 {
238 }
239 else
240 {
241 sublayers = mSublayers;
242 }
243 // only ever use the initial sublayers for first population -- after that we requery when asked to create children,
244 // or the item won't "refresh" and update its sublayers when the actual file changes
245 mSublayers.clear();
246 // remove the fast flag -- after the first population we need to requery the dataset
248
249 QVector<QgsDataItem *> children;
250 children.reserve( sublayers.size() );
251 QMap< QStringList, QgsFileDataCollectionGroupItem * > groupItems;
252 for ( const QgsProviderSublayerDetails &sublayer : std::as_const( sublayers ) )
253 {
254 QgsProviderSublayerItem *item = new QgsProviderSublayerItem( nullptr, sublayer.name(), sublayer, QString() );
255
256 if ( !sublayer.path().isEmpty() )
257 {
258 QStringList currentPath;
259 QStringList remainingPaths = sublayer.path();
260 QgsFileDataCollectionGroupItem *groupItem = nullptr;
261
262 while ( !remainingPaths.empty() )
263 {
264 currentPath << remainingPaths.takeAt( 0 );
265
266 auto it = groupItems.constFind( currentPath );
267 if ( it == groupItems.constEnd() )
268 {
269 QgsFileDataCollectionGroupItem *newGroupItem = new QgsFileDataCollectionGroupItem( this, currentPath.constLast(), path() + '/' + currentPath.join( ',' ) );
271 groupItems.insert( currentPath, newGroupItem );
272 if ( groupItem )
273 groupItem->addChildItem( newGroupItem );
274 else
275 children.append( newGroupItem );
276 groupItem = newGroupItem;
277 }
278 else
279 {
280 groupItem = it.value();
281 }
282
283 if ( groupItem )
284 groupItem->appendSublayer( sublayer );
285 }
286
287 if ( groupItem )
288 groupItem->addChildItem( item );
289 }
290 else
291 {
292 children.append( item );
293 }
294 }
295
296 std::unique_ptr<QgsAbstractDatabaseProviderConnection> conn( databaseConnection() );
297 if ( conn )
298 {
299 mCachedCapabilities = conn->capabilities();
300 mCachedCapabilities2 = conn->capabilities2();
301 mHasCachedCapabilities = true;
302 }
303 if ( conn && ( mCachedCapabilities & QgsAbstractDatabaseProviderConnection::Capability::ListFieldDomains ) )
304 {
305 QString domainError;
306 QStringList fieldDomains;
307 try
308 {
309 fieldDomains = conn->fieldDomainNames();
310 }
312 {
313 domainError = ex.what();
314 }
315
316 if ( !fieldDomains.empty() || !domainError.isEmpty() )
317 {
318 std::unique_ptr< QgsFieldDomainsItem > domainsItem = std::make_unique< QgsFieldDomainsItem >( this, mPath + "/domains", conn->uri(), QStringLiteral( "ogr" ) );
319 // force this item to appear last by setting a maximum string value for the sort key
320 domainsItem->setSortKey( QString( QChar( 0x10FFFF ) ) );
321 children.append( domainsItem.release() );
322 }
323 }
324 if ( conn && ( mCachedCapabilities & QgsAbstractDatabaseProviderConnection::Capability::RetrieveRelationships ) )
325 {
326 QString relationError;
327 QList< QgsWeakRelation > relations;
328 try
329 {
330 relations = conn->relationships();
331 }
333 {
334 relationError = ex.what();
335 }
336
337 if ( !relations.empty() || !relationError.isEmpty() )
338 {
339 std::unique_ptr< QgsRelationshipsItem > relationsItem = std::make_unique< QgsRelationshipsItem >( this, mPath + "/relations", conn->uri(), QStringLiteral( "ogr" ) );
340 // force this item to appear last by setting a maximum string value for the sort key
341 relationsItem->setSortKey( QString( QChar( 0x11FFFF ) ) );
342 children.append( relationsItem.release() );
343 }
344 }
345
346 return children;
347}
348
350{
351 return true;
352}
353
355{
356 // if we've previously opened a connection for this item, we can use the previously
357 // determined capababilities to return an accurate answer.
358 if ( mHasCachedCapabilities )
359 return mCachedCapabilities & QgsAbstractDatabaseProviderConnection::Capability::CreateVectorTable;
360
361 if ( mHasCachedDropSupport )
362 return mCachedSupportsDrop;
363
364 // otherwise, we are limited to VERY VERY cheap calculations only!!
365 // DO NOT UNDER *****ANY***** CIRCUMSTANCES OPEN DATASETS HERE!!!!
366
367 mHasCachedDropSupport = true;
368 if ( !QFileInfo( path() ).isWritable() )
369 {
370 mCachedSupportsDrop = false;
371 return mCachedSupportsDrop;
372 }
373
374 GDALDriverH hDriver = GDALIdentifyDriverEx( path().toUtf8().constData(), GDAL_OF_VECTOR, nullptr, nullptr );
375 if ( !hDriver )
376 {
377 mCachedSupportsDrop = false;
378 return mCachedSupportsDrop;
379 }
380
381 // explicitly blocklist some drivers which we don't want to expose drop support for
382 const QString driverName = GDALGetDriverShortName( hDriver );
383 if ( driverName == QLatin1String( "PDF" )
384 || driverName == QLatin1String( "DXF" ) )
385 {
386 mCachedSupportsDrop = false;
387 return mCachedSupportsDrop;
388 }
389
390 // DO NOT UNDER *****ANY***** CIRCUMSTANCES OPEN DATASETS HERE!!!!
391#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3,4,0)
392 const bool isSingleTableDriver = GDALGetMetadataItem( hDriver, GDAL_DCAP_MULTIPLE_VECTOR_LAYERS, nullptr ) == nullptr;
393#else
394 const QFileInfo pathInfo( path() );
395 const QString suffix = pathInfo.suffix().toLower();
396 const bool isSingleTableDriver = !QgsGdalUtils::multiLayerFileExtensions().contains( suffix );
397#endif
398
399 if ( isSingleTableDriver )
400 {
401 mCachedSupportsDrop = false;
402 return mCachedSupportsDrop;
403 }
404
405 // DO NOT UNDER *****ANY***** CIRCUMSTANCES OPEN DATASETS HERE!!!!
406 mCachedSupportsDrop = true;
407 return mCachedSupportsDrop;
408}
409
411{
412 QgsMimeDataUtils::Uri collectionUri;
413 collectionUri.uri = path();
414 collectionUri.layerType = QStringLiteral( "collection" );
415 collectionUri.filePath = path();
416 return { collectionUri };
417}
418
420{
421 // test that file is valid with OGR
422 if ( OGRGetDriverCount() == 0 )
423 {
424 OGRRegisterAll();
425 }
426 // do not print errors, but write to debug
427 CPLPushErrorHandler( CPLQuietErrorHandler );
428 CPLErrorReset();
429 GDALDriverH hDriver = GDALIdentifyDriverEx( path().toUtf8().constData(), GDAL_OF_VECTOR, nullptr, nullptr );
430 CPLPopErrorHandler();
431
432 if ( ! hDriver )
433 {
434 QgsDebugMsgLevel( QStringLiteral( "GDALIdentifyDriverEx error # %1 : %2 on %3" ).arg( CPLGetLastErrorNo() ).arg( CPLGetLastErrorMsg() ).arg( path() ), 2 );
435 return nullptr;
436 }
437
438 const QString driverName = GDALGetDriverShortName( hDriver );
439 if ( driverName == QLatin1String( "PDF" )
440 || driverName == QLatin1String( "DXF" ) )
441 {
442 // unwanted drivers -- it's slow to create connections for these, and we don't really want
443 // to expose database capabilities for them (even though they kind of are database formats)
444 return nullptr;
445 }
446
448 if ( driverName == QLatin1String( "SQLite" ) )
449 {
450 // sqlite gets special handling, as we delegate to the native spatialite provider
451 if ( QgsProviderMetadata *md = QgsProviderRegistry::instance()->providerMetadata( QStringLiteral( "spatialite" ) ) )
452 {
454 uri.setDatabase( path( ) );
455 conn = static_cast<QgsAbstractDatabaseProviderConnection *>( md->createConnection( uri.uri(), {} ) );
456 }
457 }
458 else
459 {
460 // for all other vector types we use the generic OGR provider
461 if ( QgsProviderMetadata *md = QgsProviderRegistry::instance()->providerMetadata( QStringLiteral( "ogr" ) ) )
462 {
463 QVariantMap parts;
464 parts.insert( QStringLiteral( "path" ), path() );
465 conn = static_cast<QgsAbstractDatabaseProviderConnection *>( md->createConnection( md->encodeUri( parts ), {} ) );
466 }
467 }
468
469 if ( conn )
470 {
471 mCachedCapabilities = conn->capabilities();
472 mCachedCapabilities2 = conn->capabilities2();
473 mHasCachedCapabilities = true;
474 }
475
476 return conn;
477}
478
480{
481 if ( mHasCachedCapabilities )
482 return mCachedCapabilities;
483
484 std::unique_ptr<QgsAbstractDatabaseProviderConnection> conn( databaseConnection() );
485 if ( conn )
486 {
487 mCachedCapabilities = conn->capabilities();
488 mCachedCapabilities2 = conn->capabilities2();
489 mHasCachedCapabilities = true;
490 }
491 return mCachedCapabilities;
492}
493
495{
496 if ( mHasCachedCapabilities )
497 return mCachedCapabilities2;
498
499 std::unique_ptr<QgsAbstractDatabaseProviderConnection> conn( databaseConnection() );
500 if ( conn )
501 {
502 mCachedCapabilities = conn->capabilities();
503 mCachedCapabilities2 = conn->capabilities2();
504 mHasCachedCapabilities = true;
505 }
506 return mCachedCapabilities2;
507}
508
509QList<QgsProviderSublayerDetails> QgsFileDataCollectionItem::sublayers() const
510{
511 return mSublayers;
512}
513
514//
515// QgsFileBasedDataItemProvider
516//
517
519{
520 return QStringLiteral( "files" );
521}
522
524{
526}
527
529{
530 if ( path.isEmpty() )
531 return nullptr;
532
533 const QFileInfo info( path );
534 QString suffix = info.suffix().toLower();
535 const QString name = info.fileName();
536
537 // special handling for some suffixes
538 if ( suffix.compare( QLatin1String( "gpkg" ), Qt::CaseInsensitive ) == 0 )
539 {
540 // Geopackage is special -- it gets a dedicated collection item type
541 QgsGeoPackageCollectionItem *item = new QgsGeoPackageCollectionItem( parentItem, name, path );
542 item->setCapabilities( item->capabilities2() | Qgis::BrowserItemCapability::ItemRepresentsFile );
543 return item;
544 }
545 else if ( suffix == QLatin1String( "txt" ) )
546 {
547 // never ever show .txt files as datasets in browser -- they are only used for geospatial data in extremely rare cases
548 // and are predominantly just noise in the browser
549 return nullptr;
550 }
551 // If a .tab exists, then the corresponding .map/.dat is very likely a
552 // side-car file of the .tab
553 else if ( suffix == QLatin1String( "map" ) || suffix == QLatin1String( "dat" ) )
554 {
555 if ( QFile::exists( QDir( info.path() ).filePath( info.baseName() + ".tab" ) ) || QFile::exists( QDir( info.path() ).filePath( info.baseName() + ".TAB" ) ) )
556 return nullptr;
557 }
558 // .dbf and .shx should only appear if .shp is not present
559 else if ( suffix == QLatin1String( "dbf" ) || suffix == QLatin1String( "shx" ) )
560 {
561 if ( QFile::exists( QDir( info.path() ).filePath( info.baseName() + ".shp" ) ) || QFile::exists( QDir( info.path() ).filePath( info.baseName() + ".SHP" ) ) )
562 return nullptr;
563 }
564 // skip QGIS style xml files
565 else if ( suffix == QLatin1String( "xml" ) && QgsStyle::isXmlStyleFile( path ) )
566 {
567 return nullptr;
568 }
569 // GDAL 3.1 Shapefile driver directly handles .shp.zip files
570 else if ( path.endsWith( QLatin1String( ".shp.zip" ), Qt::CaseInsensitive ) &&
571 GDALIdentifyDriverEx( path.toUtf8().constData(), GDAL_OF_VECTOR, nullptr, nullptr ) )
572 {
573 suffix = QStringLiteral( "shp.zip" );
574 }
575
576 // hide blocklisted URIs, such as .aux.xml files
577 if ( QgsProviderRegistry::instance()->uriIsBlocklisted( path ) )
578 return nullptr;
579
580 QgsSettings settings;
581
583
584 // should we fast scan only?
585 if ( ( settings.value( QStringLiteral( "qgis/scanItemsInBrowser2" ),
586 "extension" ).toString() == QLatin1String( "extension" ) ) ||
587 ( parentItem && settings.value( QStringLiteral( "qgis/scanItemsFastScanUris" ),
588 QStringList() ).toStringList().contains( parentItem->path() ) ) )
589 {
591 }
592
593 const QList<QgsProviderSublayerDetails> sublayers = QgsProviderRegistry::instance()->querySublayers( path, queryFlags );
594
595 if ( sublayers.size() == 1
598 )
599 {
600 QgsProviderSublayerItem *item = new QgsProviderSublayerItem( parentItem, name, sublayers.at( 0 ), path );
602 return item;
603 }
604 else if ( !sublayers.empty() )
605 {
606 QgsFileDataCollectionItem *item = new QgsFileDataCollectionItem( parentItem, name, path, sublayers );
608 return item;
609 }
610 else
611 {
612 return nullptr;
613 }
614}
615
617{
618 QFileInfo info( path );
619 QString suffix = info.suffix().toLower();
620
621 QStringList dirExtensions = QgsOgrProviderUtils::directoryExtensions();
622 return dirExtensions.contains( suffix );
623}
@ Files
Can provides items which corresponds to files.
@ Directories
Can provides items which corresponds to directories.
@ 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,...
QFlags< DataItemProviderCapability > DataItemProviderCapabilities
Capabilities for data item providers.
Definition: qgis.h:727
@ 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.
@ Polygon
Polygons.
@ Unknown
Unknown types.
@ Null
No geometry.
BrowserLayerType
Browser item layer types.
Definition: qgis.h:736
@ Point
Vector point layer.
@ Plugin
Plugin based layer.
@ Line
Vector line layer.
@ TiledScene
Tiled scene layer (since QGIS 3.34)
@ Polygon
Vector polygon layer.
@ Vector
Generic vector layer.
@ VectorTile
Vector tile layer.
@ Raster
Raster layer.
@ TableLayer
Vector non-spatial layer.
@ PointCloud
Point cloud layer.
QFlags< SublayerQueryFlag > SublayerQueryFlags
Sublayer query flags.
Definition: qgis.h:1097
@ Group
Composite group layer. Added in QGIS 3.24.
@ Plugin
Plugin based layer.
@ TiledScene
Tiled scene layer. Added in QGIS 3.34.
@ Annotation
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
@ Vector
Vector layer.
@ VectorTile
Vector tile layer. Added in QGIS 3.14.
@ Mesh
Mesh layer. Added in QGIS 3.2.
@ Raster
Raster layer.
@ PointCloud
Point cloud layer. Added in QGIS 3.18.
QFlags< DatabaseProviderConnectionCapability2 > DatabaseProviderConnectionCapabilities2
Definition: qgis.h:4345
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:448
QString mPath
Definition: qgsdataitem.h:447
QVector< QgsDataItem * > children() const
Definition: qgsdataitem.h:331
Qgis::BrowserItemCapabilities mCapabilities
Definition: qgsdataitem.h:437
QString mIconName
Definition: qgsdataitem.h:449
QString name() const
Returns the name of the item (the displayed text for the item).
Definition: qgsdataitem.h:339
QString path() const
Definition: qgsdataitem.h:348
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:304
virtual void addChildItem(QgsDataItem *child, bool refresh=false)
Inserts a new child item.
QgsDataItem * parent() const
Gets item parent.
Definition: qgsdataitem.h:324
virtual Qgis::BrowserItemCapabilities capabilities2() const
Returns the capabilities for the data item.
Definition: qgsdataitem.h:297
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
Qgis::DataItemProviderCapabilities capabilities() const override
Returns combination of flags from QgsDataProvider::DataCapabilities.
QString name() override
Human-readable name of the provider name.
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 ...
QList< QgsProviderSublayerDetails > sublayers() const
Returns the sublayers.
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:101
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:64
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:3067
static Qgis::GeometryType geometryType(Qgis::WkbType type)
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
Definition: qgswkbtypes.h:862
#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.