QGIS API Documentation 3.99.0-Master (26c88405ac0)
Loading...
Searching...
No Matches
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
18#include "qgsdataprovider.h"
19#include "qgsfielddomainsitem.h"
20#include "qgsfieldsitem.h"
21#include "qgsgdalutils.h"
22#include "qgsgeopackagedataitems.h"
23#include "qgslogger.h"
24#include "qgsogrproviderutils.h"
25#include "qgsprovidermetadata.h"
26#include "qgsproviderregistry.h"
28#include "qgsproviderutils.h"
30#include "qgssettings.h"
31#include "qgsstyle.h"
32
33#include <QUrlQuery>
34
35#include "moc_qgsfilebaseddataitemprovider.cpp"
36
37//
38// QgsProviderSublayerItem
39//
40
42 const QgsProviderSublayerDetails &details, const QString &filePath )
43 : QgsLayerItem( parent, name, filePath.isEmpty() ? details.uri() : filePath, details.uri(), layerTypeFromSublayer( details ), details.providerKey() )
44 , mDetails( details )
45{
46 mToolTip = details.uri();
47
48 // no children, except for vector layers, which will show the fields item
50}
51
53{
54 QVector<QgsDataItem *> children;
55
56 if ( mDetails.type() == Qgis::LayerType::Vector )
57 {
58 // sqlite gets special handling because it delegates to the dedicated spatialite provider
59 if ( mDetails.driverName() == QLatin1String( "SQLite" ) )
60 {
61 children.push_back( new QgsFieldsItem( this,
62 path() + QStringLiteral( "/columns/ " ),
63 QStringLiteral( R"(dbname="%1")" ).arg( parent()->path().replace( '"', QLatin1String( R"(\")" ) ) ),
64 QStringLiteral( "spatialite" ), QString(), name() ) );
65 }
66 else if ( mDetails.providerKey() == QLatin1String( "ogr" ) )
67 {
68 // otherwise we use the default OGR database connection approach, which is the generic way to handle this
69 // for all OGR layer types
70 children.push_back( new QgsFieldsItem( this,
71 path() + QStringLiteral( "/columns/ " ),
72 path(),
73 QStringLiteral( "ogr" ), QString(), name() ) );
74
75 std::unique_ptr<QgsAbstractDatabaseProviderConnection> conn( databaseConnection() );
77 {
78 QString relationError;
79 QList< QgsWeakRelation > relations;
80 try
81 {
82 relations = conn->relationships( QString(), mDetails.name() );
83 }
85 {
86 relationError = ex.what();
87 }
88
89 if ( !relations.empty() || !relationError.isEmpty() )
90 {
91 auto relationsItem = std::make_unique< QgsRelationshipsItem >( this, mPath + "/relations", conn->uri(), QStringLiteral( "ogr" ), QString(), mDetails.name() );
92 // force this item to appear last by setting a maximum string value for the sort key
93 relationsItem->setSortKey( QString( QChar( 0x11FFFF ) ) );
94 children.append( relationsItem.release() );
95 }
96 }
97 }
98 }
99 return children;
100}
101
106
108{
109 if ( parent() )
110 {
112 return connection;
113 }
114
115 if ( mDetails.providerKey() == QLatin1String( "ogr" ) )
116 {
117 if ( QgsProviderMetadata *md = QgsProviderRegistry::instance()->providerMetadata( QStringLiteral( "ogr" ) ) )
118 {
119 QVariantMap parts;
120 parts.insert( QStringLiteral( "path" ), path() );
121 return static_cast<QgsAbstractDatabaseProviderConnection *>( md->createConnection( md->encodeUri( parts ), {} ) );
122 }
123 }
124
125 return nullptr;
126}
127
128Qgis::BrowserLayerType QgsProviderSublayerItem::layerTypeFromSublayer( const QgsProviderSublayerDetails &sublayer )
129{
130 switch ( sublayer.type() )
131 {
133 {
134 switch ( QgsWkbTypes::geometryType( sublayer.wkbType() ) )
135 {
138
141
144
147
150 }
151
152 break;
153 }
156
159
162
165
168
171
174 break;
175 }
177}
178
180{
181 return mDetails.name();
182}
183
184//
185// QgsFileDataCollectionGroupItem
186//
188 : QgsDataCollectionItem( parent, groupName, path )
189{
191 mIconName = QStringLiteral( "mIconDbSchema.svg" );
192}
193
195{
196 mSublayers.append( sublayer );
197}
198
200{
201 return true;
202}
203
205{
207 res.reserve( mSublayers.size() );
208
209 for ( const QgsProviderSublayerDetails &sublayer : mSublayers )
210 {
211 res << sublayer.toMimeUri();
212 }
213 return res;
214}
215
216//
217// QgsFileDataCollectionItem
218//
219
220QgsFileDataCollectionItem::QgsFileDataCollectionItem( QgsDataItem *parent, const QString &name, const QString &path, const QList<QgsProviderSublayerDetails> &sublayers, const QVariantMap &extraUriParts )
222 , mSublayers( sublayers )
223 , mExtraUriParts( extraUriParts )
224{
227 else
229
231 {
232 mIconName = QStringLiteral( "/mIconZip.svg" );
233 }
234}
235
237{
238 QList< QgsProviderSublayerDetails> sublayers;
240 {
241 QSet< QString > providers;
242 for ( const QgsProviderSublayerDetails &details : std::as_const( mSublayers ) )
243 {
244 providers.insert( details.providerKey() );
245 }
246
247 for ( const QString &provider : std::as_const( providers ) )
248 {
249 if ( QgsProviderMetadata *metadata = QgsProviderRegistry::instance()->providerMetadata( provider ) )
250 {
251 if ( !mExtraUriParts.empty() )
252 {
253 QVariantMap uriParts = metadata->decodeUri( path() );
254 for ( auto it = mExtraUriParts.constBegin(); it != mExtraUriParts.constEnd(); ++it )
255 {
256 uriParts.insert( it.key(), it.value() );
257 }
258 const QString updatedUri = metadata->encodeUri( uriParts );
259
260 sublayers.append( metadata->querySublayers( updatedUri.isEmpty() ? path() : updatedUri, Qgis::SublayerQueryFlag::ResolveGeometryType ) );
261 }
262 else
263 {
264 sublayers.append( metadata->querySublayers( path(), Qgis::SublayerQueryFlag::ResolveGeometryType ) );
265 }
266 }
267 }
268 }
269 else if ( mSublayers.empty() )
270 {
272 }
273 else
274 {
275 sublayers = mSublayers;
276 }
277 // only ever use the initial sublayers for first population -- after that we requery when asked to create children,
278 // or the item won't "refresh" and update its sublayers when the actual file changes
279 mSublayers.clear();
280 // remove the fast flag -- after the first population we need to requery the dataset
282
283 QVector<QgsDataItem *> children;
284 children.reserve( sublayers.size() );
285 QMap< QStringList, QgsFileDataCollectionGroupItem * > groupItems;
286 for ( const QgsProviderSublayerDetails &sublayer : std::as_const( sublayers ) )
287 {
288 QgsProviderSublayerItem *item = new QgsProviderSublayerItem( nullptr, sublayer.name(), sublayer, QString() );
289
290 if ( !sublayer.path().isEmpty() )
291 {
292 QStringList currentPath;
293 QStringList remainingPaths = sublayer.path();
294 QgsFileDataCollectionGroupItem *groupItem = nullptr;
295
296 while ( !remainingPaths.empty() )
297 {
298 currentPath << remainingPaths.takeAt( 0 );
299
300 auto it = groupItems.constFind( currentPath );
301 if ( it == groupItems.constEnd() )
302 {
303 QgsFileDataCollectionGroupItem *newGroupItem = new QgsFileDataCollectionGroupItem( this, currentPath.constLast(), path() + '/' + currentPath.join( ',' ) );
305 groupItems.insert( currentPath, newGroupItem );
306 if ( groupItem )
307 groupItem->addChildItem( newGroupItem );
308 else
309 children.append( newGroupItem );
310 groupItem = newGroupItem;
311 }
312 else
313 {
314 groupItem = it.value();
315 }
316
317 if ( groupItem )
318 groupItem->appendSublayer( sublayer );
319 }
320
321 if ( groupItem )
322 groupItem->addChildItem( item );
323 }
324 else
325 {
326 children.append( item );
327 }
328 }
329
330 std::unique_ptr<QgsAbstractDatabaseProviderConnection> conn( databaseConnection() );
331 if ( conn )
332 {
333 mCachedCapabilities = conn->capabilities();
334 mCachedCapabilities2 = conn->capabilities2();
335 mHasCachedCapabilities = true;
336 }
337 if ( conn && ( mCachedCapabilities & QgsAbstractDatabaseProviderConnection::Capability::ListFieldDomains ) )
338 {
339 QString domainError;
340 QStringList fieldDomains;
341 try
342 {
343 fieldDomains = conn->fieldDomainNames();
344 }
346 {
347 domainError = ex.what();
348 }
349
350 if ( !fieldDomains.empty() || !domainError.isEmpty() )
351 {
352 auto domainsItem = std::make_unique< QgsFieldDomainsItem >( this, mPath + "/domains", conn->uri(), QStringLiteral( "ogr" ) );
353 // force this item to appear last by setting a maximum string value for the sort key
354 domainsItem->setSortKey( QString( QChar( 0x10FFFF ) ) );
355 children.append( domainsItem.release() );
356 }
357 }
359 {
360 QString relationError;
361 QList< QgsWeakRelation > relations;
362 try
363 {
364 relations = conn->relationships();
365 }
367 {
368 relationError = ex.what();
369 }
370
371 if ( !relations.empty() || !relationError.isEmpty() )
372 {
373 auto relationsItem = std::make_unique< QgsRelationshipsItem >( this, mPath + "/relations", conn->uri(), QStringLiteral( "ogr" ) );
374 // force this item to appear last by setting a maximum string value for the sort key
375 relationsItem->setSortKey( QString( QChar( 0x11FFFF ) ) );
376 children.append( relationsItem.release() );
377 }
378 }
379
380 return children;
381}
382
384{
385 return true;
386}
387
389{
390 // if we've previously opened a connection for this item, we can use the previously
391 // determined capababilities to return an accurate answer.
392 if ( mHasCachedCapabilities )
394
395 if ( mHasCachedDropSupport )
396 return mCachedSupportsDrop;
397
398 // otherwise, we are limited to VERY VERY cheap calculations only!!
399 // DO NOT UNDER *****ANY***** CIRCUMSTANCES OPEN DATASETS HERE!!!!
400
401 mHasCachedDropSupport = true;
402 if ( !QFileInfo( path() ).isWritable() )
403 {
404 mCachedSupportsDrop = false;
405 return mCachedSupportsDrop;
406 }
407
408 GDALDriverH hDriver = GDALIdentifyDriverEx( path().toUtf8().constData(), GDAL_OF_VECTOR, nullptr, nullptr );
409 if ( !hDriver )
410 {
411 mCachedSupportsDrop = false;
412 return mCachedSupportsDrop;
413 }
414
415 // explicitly blocklist some drivers which we don't want to expose drop support for
416 const QString driverName = GDALGetDriverShortName( hDriver );
417 if ( driverName == QLatin1String( "PDF" )
418 || driverName == QLatin1String( "DXF" ) )
419 {
420 mCachedSupportsDrop = false;
421 return mCachedSupportsDrop;
422 }
423
424 // DO NOT UNDER *****ANY***** CIRCUMSTANCES OPEN DATASETS HERE!!!!
425#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3,4,0)
426 const bool isSingleTableDriver = !GDALGetMetadataItem( hDriver, GDAL_DCAP_MULTIPLE_VECTOR_LAYERS, nullptr );
427#else
428 const QFileInfo pathInfo( path() );
429 const QString suffix = pathInfo.suffix().toLower();
430 const bool isSingleTableDriver = !QgsGdalUtils::multiLayerFileExtensions().contains( suffix );
431#endif
432
433 if ( isSingleTableDriver )
434 {
435 mCachedSupportsDrop = false;
436 return mCachedSupportsDrop;
437 }
438
439 // DO NOT UNDER *****ANY***** CIRCUMSTANCES OPEN DATASETS HERE!!!!
440 mCachedSupportsDrop = true;
441 return mCachedSupportsDrop;
442}
443
445{
446 QgsMimeDataUtils::Uri collectionUri;
447 collectionUri.uri = path();
448 collectionUri.layerType = QStringLiteral( "collection" );
449 collectionUri.filePath = path();
450 return { collectionUri };
451}
452
454{
455 // test that file is valid with OGR
456 if ( OGRGetDriverCount() == 0 )
457 {
458 OGRRegisterAll();
459 }
460 // do not print errors, but write to debug
461 CPLPushErrorHandler( CPLQuietErrorHandler );
462 CPLErrorReset();
463 GDALDriverH hDriver = GDALIdentifyDriverEx( path().toUtf8().constData(), GDAL_OF_VECTOR, nullptr, nullptr );
464 CPLPopErrorHandler();
465
466 if ( ! hDriver )
467 {
468 QgsDebugMsgLevel( QStringLiteral( "GDALIdentifyDriverEx error # %1 : %2 on %3" ).arg( CPLGetLastErrorNo() ).arg( CPLGetLastErrorMsg() ).arg( path() ), 2 );
469 return nullptr;
470 }
471
472 const QString driverName = GDALGetDriverShortName( hDriver );
473 if ( driverName == QLatin1String( "PDF" )
474 || driverName == QLatin1String( "DXF" ) )
475 {
476 // unwanted drivers -- it's slow to create connections for these, and we don't really want
477 // to expose database capabilities for them (even though they kind of are database formats)
478 return nullptr;
479 }
480
482 if ( driverName == QLatin1String( "SQLite" ) )
483 {
484 // sqlite gets special handling, as we delegate to the native spatialite provider
485 if ( QgsProviderMetadata *md = QgsProviderRegistry::instance()->providerMetadata( QStringLiteral( "spatialite" ) ) )
486 {
488 uri.setDatabase( path( ) );
489 conn = static_cast<QgsAbstractDatabaseProviderConnection *>( md->createConnection( uri.uri(), {} ) );
490 }
491 }
492 else
493 {
494 // for all other vector types we use the generic OGR provider
495 if ( QgsProviderMetadata *md = QgsProviderRegistry::instance()->providerMetadata( QStringLiteral( "ogr" ) ) )
496 {
497 QVariantMap parts;
498 parts.insert( QStringLiteral( "path" ), path() );
499 conn = static_cast<QgsAbstractDatabaseProviderConnection *>( md->createConnection( md->encodeUri( parts ), {} ) );
500 }
501 }
502
503 if ( conn )
504 {
505 mCachedCapabilities = conn->capabilities();
506 mCachedCapabilities2 = conn->capabilities2();
507 mHasCachedCapabilities = true;
508 }
509
510 return conn;
511}
512
514{
515 if ( mHasCachedCapabilities )
516 return mCachedCapabilities;
517
518 std::unique_ptr<QgsAbstractDatabaseProviderConnection> conn( databaseConnection() );
519 if ( conn )
520 {
521 mCachedCapabilities = conn->capabilities();
522 mCachedCapabilities2 = conn->capabilities2();
523 mHasCachedCapabilities = true;
524 }
525 return mCachedCapabilities;
526}
527
529{
530 if ( mHasCachedCapabilities )
531 return mCachedCapabilities2;
532
533 std::unique_ptr<QgsAbstractDatabaseProviderConnection> conn( databaseConnection() );
534 if ( conn )
535 {
536 mCachedCapabilities = conn->capabilities();
537 mCachedCapabilities2 = conn->capabilities2();
538 mHasCachedCapabilities = true;
539 }
540 return mCachedCapabilities2;
541}
542
543QList<QgsProviderSublayerDetails> QgsFileDataCollectionItem::sublayers() const
544{
545 return mSublayers;
546}
547
548//
549// QgsFileBasedDataItemProvider
550//
551
553{
554 return QStringLiteral( "files" );
555}
556
561
563{
564 return createDataItemForPathPrivate( path, parentItem, nullptr, Qgis::SublayerQueryFlags(), QVariantMap() );
565}
566
567QgsDataItem *QgsFileBasedDataItemProvider::createLayerItemForPath( const QString &path, QgsDataItem *parentItem, const QStringList &allowedProviders, const QVariantMap &extraUriParts, Qgis::SublayerQueryFlags queryFlags )
568{
569 return createDataItemForPathPrivate( path, parentItem, &allowedProviders, queryFlags, extraUriParts );
570}
571
572QgsDataItem *QgsFileBasedDataItemProvider::createDataItemForPathPrivate( const QString &path, QgsDataItem *parentItem, const QStringList *allowedProviders, Qgis::SublayerQueryFlags queryFlags, const QVariantMap &extraUriParts )
573{
574 if ( path.isEmpty() )
575 return nullptr;
576
577 const QFileInfo info( path );
578 QString suffix = info.suffix().toLower();
579 const QString name = info.fileName();
580
581 // special handling for some suffixes
582 if ( suffix.compare( QLatin1String( "gpkg" ), Qt::CaseInsensitive ) == 0 )
583 {
584 // Geopackage is special -- it gets a dedicated collection item type
585 QgsGeoPackageCollectionItem *item = new QgsGeoPackageCollectionItem( parentItem, name, path );
586 item->setCapabilities( item->capabilities2() | Qgis::BrowserItemCapability::ItemRepresentsFile );
587 return item;
588 }
589 else if ( suffix == QLatin1String( "txt" ) )
590 {
591 // never ever show .txt files as datasets in browser -- they are only used for geospatial data in extremely rare cases
592 // and are predominantly just noise in the browser
593 return nullptr;
594 }
595 // If a .tab exists, then the corresponding .map/.dat is very likely a
596 // side-car file of the .tab
597 else if ( suffix == QLatin1String( "map" ) || suffix == QLatin1String( "dat" ) )
598 {
599 if ( QFile::exists( QDir( info.path() ).filePath( info.baseName() + ".tab" ) ) || QFile::exists( QDir( info.path() ).filePath( info.baseName() + ".TAB" ) ) )
600 return nullptr;
601 }
602 // .dbf and .shx should only appear if .shp is not present
603 else if ( suffix == QLatin1String( "dbf" ) || suffix == QLatin1String( "shx" ) )
604 {
605 if ( QFile::exists( QDir( info.path() ).filePath( info.baseName() + ".shp" ) ) || QFile::exists( QDir( info.path() ).filePath( info.baseName() + ".SHP" ) ) )
606 return nullptr;
607 }
608 // skip QGIS style xml files
609 else if ( suffix == QLatin1String( "xml" ) && QgsStyle::isXmlStyleFile( path ) )
610 {
611 return nullptr;
612 }
613 // GDAL 3.1 Shapefile driver directly handles .shp.zip files
614 else if ( path.endsWith( QLatin1String( ".shp.zip" ), Qt::CaseInsensitive ) &&
615 GDALIdentifyDriverEx( path.toUtf8().constData(), GDAL_OF_VECTOR, nullptr, nullptr ) )
616 {
617 suffix = QStringLiteral( "shp.zip" );
618 }
619
620 // hide blocklisted URIs, such as .aux.xml files
621 if ( QgsProviderRegistry::instance()->uriIsBlocklisted( path ) )
622 return nullptr;
623
624 QgsSettings settings;
625
626 // should we fast scan only?
627 if ( ( settings.value( QStringLiteral( "qgis/scanItemsInBrowser2" ),
628 "extension" ).toString() == QLatin1String( "extension" ) ) ||
629 ( parentItem && settings.value( QStringLiteral( "qgis/scanItemsFastScanUris" ),
630 QStringList() ).toStringList().contains( parentItem->path() ) ) )
631 {
633 }
634
635 QList<QgsProviderSublayerDetails> sublayers;
636 if ( !allowedProviders )
637 {
638 sublayers = QgsProviderRegistry::instance()->querySublayers( path, queryFlags );
639 }
640 else
641 {
642 for ( const QString &provider : *allowedProviders )
643 {
644 if ( QgsProviderMetadata *metadata = QgsProviderRegistry::instance()->providerMetadata( provider ) )
645 {
646 if ( !extraUriParts.empty() )
647 {
648 QVariantMap uriParts = metadata->decodeUri( path );
649 for ( auto it = extraUriParts.constBegin(); it != extraUriParts.constEnd(); ++it )
650 {
651 uriParts.insert( it.key(), it.value() );
652 }
653
654 sublayers.append( metadata->querySublayers( metadata->encodeUri( uriParts ), queryFlags ) );
655 }
656 else
657 {
658 sublayers.append( metadata->querySublayers( path, queryFlags ) );
659 }
660 }
661 }
662 }
663
664 if ( sublayers.size() == 1
667 )
668 {
669 QgsProviderSublayerItem *item = new QgsProviderSublayerItem( parentItem, name, sublayers.at( 0 ), path );
671 return item;
672 }
673 else if ( !sublayers.empty() )
674 {
675 QgsFileDataCollectionItem *item = new QgsFileDataCollectionItem( parentItem, name, path, sublayers, extraUriParts );
677 return item;
678 }
679 else
680 {
681 return nullptr;
682 }
683}
684
686{
687 QFileInfo info( path );
688 QString suffix = info.suffix().toLower();
689
690 QStringList dirExtensions = QgsOgrProviderUtils::directoryExtensions();
691 return dirExtensions.contains( suffix );
692}
@ Files
Can provides items which corresponds to files.
Definition qgis.h:978
@ Directories
Can provides items which corresponds to directories.
Definition qgis.h:979
@ NotPopulated
Children not yet created.
Definition qgis.h:939
@ Populated
Children created.
Definition qgis.h:941
@ Fertile
Can create children. Even items without this capability may have children, but cannot create them,...
Definition qgis.h:954
@ RefreshChildrenWhenItemIsRefreshed
When the item is refreshed, all its populated children will also be refreshed in turn.
Definition qgis.h:960
@ ItemRepresentsFile
Item's path() directly represents a file on disk.
Definition qgis.h:959
@ Fast
CreateChildren() is fast enough to be run in main thread when refreshing items, most root items (wms,...
Definition qgis.h:955
@ Archive
File archive type (e.g. vsizip).
Definition qgis.h:5746
QFlags< DataItemProviderCapability > DataItemProviderCapabilities
Capabilities for data item providers.
Definition qgis.h:992
@ FastScan
Indicates that the provider must scan for sublayers using the fastest possible approach – e....
Definition qgis.h:1392
@ ResolveGeometryType
Attempt to resolve the geometry type for vector sublayers.
Definition qgis.h:1393
@ Point
Points.
Definition qgis.h:359
@ Line
Lines.
Definition qgis.h:360
@ Polygon
Polygons.
Definition qgis.h:361
@ Unknown
Unknown types.
Definition qgis.h:362
@ Null
No geometry.
Definition qgis.h:363
BrowserLayerType
Browser item layer types.
Definition qgis.h:1001
@ Point
Vector point layer.
Definition qgis.h:1005
@ Plugin
Plugin based layer.
Definition qgis.h:1011
@ Line
Vector line layer.
Definition qgis.h:1006
@ TiledScene
Tiled scene layer.
Definition qgis.h:1015
@ Polygon
Vector polygon layer.
Definition qgis.h:1007
@ Vector
Generic vector layer.
Definition qgis.h:1003
@ VectorTile
Vector tile layer.
Definition qgis.h:1013
@ Mesh
Mesh layer.
Definition qgis.h:1012
@ Raster
Raster layer.
Definition qgis.h:1004
@ TableLayer
Vector non-spatial layer.
Definition qgis.h:1008
@ PointCloud
Point cloud layer.
Definition qgis.h:1014
QFlags< SublayerQueryFlag > SublayerQueryFlags
Sublayer query flags.
Definition qgis.h:1399
@ Group
Composite group layer. Added in QGIS 3.24.
Definition qgis.h:198
@ Plugin
Plugin based layer.
Definition qgis.h:193
@ TiledScene
Tiled scene layer. Added in QGIS 3.34.
Definition qgis.h:199
@ Annotation
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
Definition qgis.h:196
@ Vector
Vector layer.
Definition qgis.h:191
@ VectorTile
Vector tile layer. Added in QGIS 3.14.
Definition qgis.h:195
@ Mesh
Mesh layer. Added in QGIS 3.2.
Definition qgis.h:194
@ Raster
Raster layer.
Definition qgis.h:192
@ PointCloud
Point cloud layer. Added in QGIS 3.18.
Definition qgis.h:197
QFlags< DatabaseProviderConnectionCapability2 > DatabaseProviderConnectionCapabilities2
Definition qgis.h:5398
Provides common functionality for database based connections.
Qgis::DatabaseProviderConnectionCapabilities2 capabilities2() const
Returns extended connection capabilities.
@ CreateVectorTable
Can CREATE a vector (or aspatial) table/layer.
@ RetrieveRelationships
Can retrieve relationships from the database.
@ ListFieldDomains
Can return a list of field domain names via fieldDomainNames().
Capabilities capabilities() const
Returns connection capabilities.
QgsDataCollectionItem(QgsDataItem *parent, const QString &name, const QString &path=QString(), const QString &providerKey=QString())
Constructor for QgsDataCollectionItem, with the specified parent item.
Base class for all items in the model.
Definition qgsdataitem.h:47
QString mToolTip
QString mPath
QVector< QgsDataItem * > children() const
Qgis::BrowserItemCapabilities mCapabilities
QgsDataItem(Qgis::BrowserItemType type, QgsDataItem *parent, const QString &name, const QString &path, const QString &providerKey=QString())
Constructor for QgsDataItem, with the specified parent item.
QString mIconName
QString name() const
Returns the name of the item (the displayed text for the item).
QString path() const
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.
QString providerKey() const
Returns the provider key that created this item (e.g.
virtual Qgis::BrowserItemCapabilities capabilities2() const
Returns the capabilities for the data item.
Stores the component parts of a 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
A browser item which contains a collection of field items.
static QgsDataItem * createLayerItemForPath(const QString &path, QgsDataItem *parentItem, const QStringList &providers, const QVariantMap &extraUriParts, Qgis::SublayerQueryFlags queryFlags)
Static method to create a data item for sublayers corresponding to a file-like path.
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.
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.
QgsFileDataCollectionItem(QgsDataItem *parent, const QString &name, const QString &path, const QList< QgsProviderSublayerDetails > &sublayers, const QVariantMap &extraUriParts=QVariantMap())
Constructor for QgsFileDataCollectionItem.
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...
Qgis::DatabaseProviderConnectionCapabilities2 databaseConnectionCapabilities2() const
Returns extended connection capabilities, if a databaseConnection() is available.
static Qgis::VsiHandlerType vsiHandlerType(const QString &prefix)
Returns the VSI handler type for a given VSI prefix.
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 ...
QString uri() const
Returns layer uri or empty string if layer cannot be created.
QgsLayerItem(QgsDataItem *parent, const QString &name, const QString &path, const QString &uri, Qgis::BrowserLayerType layerType, const QString &providerKey)
Constructor for QgsLayerItem.
QList< QgsMimeDataUtils::Uri > UriList
Custom exception class for provider connection related exceptions.
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.
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 name() const
Returns the layer's name.
A generic data item for file based layers.
QString layerName() const override
Returns the layer name.
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.
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)
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
#define QgsDebugMsgLevel(str, level)
Definition qgslogger.h:61
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.