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