QGIS API Documentation 4.1.0-Master (01362494303)
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"
32#include "qgssettingstree.h"
33#include "qgsstyle.h"
34
35#include <QString>
36#include <QUrlQuery>
37
38#include "moc_qgsfilebaseddataitemprovider.cpp"
39
40using namespace Qt::StringLiterals;
41
43 = new QgsSettingsEntryString( u"scan-items"_s, QgsSettingsTree::sTreeBrowser, u"extension"_s, u"Strategy used to scan file-based items in the browser. Set to \"extension\" to identify items by their file extension only, or \"contents\" to open each file and probe its actual contents (slower but more accurate)."_s );
44
45//
46// QgsProviderSublayerItem
47//
48
50 : QgsLayerItem( parent, name, filePath.isEmpty() ? details.uri() : filePath, details.uri(), layerTypeFromSublayer( details ), details.providerKey() )
51 , mDetails( details )
52{
53 mToolTip = details.uri();
54
55 // no children, except for vector layers, which will show the fields item
57}
58
60{
61 QVector<QgsDataItem *> children;
62
63 if ( mDetails.type() == Qgis::LayerType::Vector )
64 {
65 // sqlite gets special handling because it delegates to the dedicated spatialite provider
66 if ( mDetails.driverName() == "SQLite"_L1 )
67 {
68 children.push_back( new QgsFieldsItem( this, path() + u"/columns/ "_s, QStringLiteral( R"(dbname="%1")" ).arg( parent()->path().replace( '"', R"(\")"_L1 ) ), u"spatialite"_s, QString(), name() ) );
69 }
70 else if ( mDetails.providerKey() == "ogr"_L1 )
71 {
72 // otherwise we use the default OGR database connection approach, which is the generic way to handle this
73 // for all OGR layer types
74 children.push_back( new QgsFieldsItem( this, path() + u"/columns/ "_s, path(), u"ogr"_s, QString(), name() ) );
75
76 std::unique_ptr<QgsAbstractDatabaseProviderConnection> conn( databaseConnection() );
78 {
79 QString relationError;
80 QList< QgsWeakRelation > relations;
81 try
82 {
83 relations = conn->relationships( QString(), mDetails.name() );
84 }
86 {
87 relationError = ex.what();
88 }
89
90 if ( !relations.empty() || !relationError.isEmpty() )
91 {
92 auto relationsItem = std::make_unique< QgsRelationshipsItem >( this, mPath + "/relations", conn->uri(), u"ogr"_s, QString(), mDetails.name() );
93 // force this item to appear last by setting a maximum string value for the sort key
94 relationsItem->setSortKey( QString( QChar( 0x11FFFF ) ) );
95 children.append( relationsItem.release() );
96 }
97 }
98 }
99 }
100 return children;
101}
102
107
109{
110 if ( parent() )
111 {
113 return connection;
114 }
115
116 if ( mDetails.providerKey() == "ogr"_L1 )
117 {
118 if ( QgsProviderMetadata *md = QgsProviderRegistry::instance()->providerMetadata( u"ogr"_s ) )
119 {
120 QVariantMap parts;
121 parts.insert( u"path"_s, path() );
122 return static_cast<QgsAbstractDatabaseProviderConnection *>( md->createConnection( md->encodeUri( parts ), {} ) );
123 }
124 }
125
126 return nullptr;
127}
128
129Qgis::BrowserLayerType QgsProviderSublayerItem::layerTypeFromSublayer( const QgsProviderSublayerDetails &sublayer )
130{
131 switch ( sublayer.type() )
132 {
134 {
135 switch ( QgsWkbTypes::geometryType( sublayer.wkbType() ) )
136 {
139
142
145
148
151 }
152
153 break;
154 }
157
160
163
166
169
172
175 break;
176 }
178}
179
181{
182 return mDetails.name();
183}
184
185//
186// QgsFileDataCollectionGroupItem
187//
194
196{
197 mSublayers.append( sublayer );
198}
199
201{
202 return true;
203}
204
206{
208 res.reserve( mSublayers.size() );
209
210 for ( const QgsProviderSublayerDetails &sublayer : mSublayers )
211 {
212 res << sublayer.toMimeUri();
213 }
214 return res;
215}
216
217//
218// QgsFileDataCollectionItem
219//
220
221QgsFileDataCollectionItem::QgsFileDataCollectionItem( QgsDataItem *parent, const QString &name, const QString &path, const QList<QgsProviderSublayerDetails> &sublayers, const QVariantMap &extraUriParts )
223 , mSublayers( sublayers )
224 , mExtraUriParts( extraUriParts )
225{
228 else
230
232 {
233 mIconName = u"/mIconZip.svg"_s;
234 }
235}
236
238{
239 QList< QgsProviderSublayerDetails> sublayers;
241 {
242 QSet< QString > providers;
243 for ( const QgsProviderSublayerDetails &details : std::as_const( mSublayers ) )
244 {
245 providers.insert( details.providerKey() );
246 }
247
248 for ( const QString &provider : std::as_const( providers ) )
249 {
250 if ( QgsProviderMetadata *metadata = QgsProviderRegistry::instance()->providerMetadata( provider ) )
251 {
252 if ( !mExtraUriParts.empty() )
253 {
254 QVariantMap uriParts = metadata->decodeUri( path() );
255 for ( auto it = mExtraUriParts.constBegin(); it != mExtraUriParts.constEnd(); ++it )
256 {
257 uriParts.insert( it.key(), it.value() );
258 }
259 const QString updatedUri = metadata->encodeUri( uriParts );
260
261 sublayers.append( metadata->querySublayers( updatedUri.isEmpty() ? path() : updatedUri, Qgis::SublayerQueryFlag::ResolveGeometryType ) );
262 }
263 else
264 {
265 sublayers.append( metadata->querySublayers( path(), Qgis::SublayerQueryFlag::ResolveGeometryType ) );
266 }
267 }
268 }
269 }
270 else if ( mSublayers.empty() )
271 {
273 }
274 else
275 {
276 sublayers = mSublayers;
277 }
278 // only ever use the initial sublayers for first population -- after that we requery when asked to create children,
279 // or the item won't "refresh" and update its sublayers when the actual file changes
280 mSublayers.clear();
281 // remove the fast flag -- after the first population we need to requery the dataset
283
284 QVector<QgsDataItem *> children;
285 children.reserve( sublayers.size() );
286 QMap< QStringList, QgsFileDataCollectionGroupItem * > groupItems;
287 for ( const QgsProviderSublayerDetails &sublayer : std::as_const( sublayers ) )
288 {
289 QgsProviderSublayerItem *item = new QgsProviderSublayerItem( nullptr, sublayer.name(), sublayer, QString() );
290
291 if ( !sublayer.path().isEmpty() )
292 {
293 QStringList currentPath;
294 QStringList remainingPaths = sublayer.path();
295 QgsFileDataCollectionGroupItem *groupItem = nullptr;
296
297 while ( !remainingPaths.empty() )
298 {
299 currentPath << remainingPaths.takeAt( 0 );
300
301 auto it = groupItems.constFind( currentPath );
302 if ( it == groupItems.constEnd() )
303 {
304 QgsFileDataCollectionGroupItem *newGroupItem = new QgsFileDataCollectionGroupItem( this, currentPath.constLast(), path() + '/' + currentPath.join( ',' ) );
306 groupItems.insert( currentPath, newGroupItem );
307 if ( groupItem )
308 groupItem->addChildItem( newGroupItem );
309 else
310 children.append( newGroupItem );
311 groupItem = newGroupItem;
312 }
313 else
314 {
315 groupItem = it.value();
316 }
317
318 if ( groupItem )
319 groupItem->appendSublayer( sublayer );
320 }
321
322 if ( groupItem )
323 groupItem->addChildItem( item );
324 }
325 else
326 {
327 children.append( item );
328 }
329 }
330
331 std::unique_ptr<QgsAbstractDatabaseProviderConnection> conn( databaseConnection() );
332 if ( conn )
333 {
334 mCachedCapabilities = conn->capabilities();
335 mCachedCapabilities2 = conn->capabilities2();
336 mHasCachedCapabilities = true;
337 }
338 if ( conn && ( mCachedCapabilities & QgsAbstractDatabaseProviderConnection::Capability::ListFieldDomains ) )
339 {
340 QString domainError;
341 QStringList fieldDomains;
342 try
343 {
344 fieldDomains = conn->fieldDomainNames();
345 }
347 {
348 domainError = ex.what();
349 }
350
351 if ( !fieldDomains.empty() || !domainError.isEmpty() )
352 {
353 auto domainsItem = std::make_unique< QgsFieldDomainsItem >( this, mPath + "/domains", conn->uri(), u"ogr"_s );
354 // force this item to appear last by setting a maximum string value for the sort key
355 domainsItem->setSortKey( QString( QChar( 0xFFFF ) ) );
356 children.append( domainsItem.release() );
357 }
358 }
360 {
361 QString relationError;
362 QList< QgsWeakRelation > relations;
363 try
364 {
365 relations = conn->relationships();
366 }
368 {
369 relationError = ex.what();
370 }
371
372 if ( !relations.empty() || !relationError.isEmpty() )
373 {
374 auto relationsItem = std::make_unique< QgsRelationshipsItem >( this, mPath + "/relations", conn->uri(), u"ogr"_s );
375 // force this item to appear last by setting a maximum string value for the sort key
376 relationsItem->setSortKey( QString( QChar( 0x11FFFF ) ) );
377 children.append( relationsItem.release() );
378 }
379 }
380
381 return children;
382}
383
385{
386 return true;
387}
388
390{
391 // if we've previously opened a connection for this item, we can use the previously
392 // determined capababilities to return an accurate answer.
393 if ( mHasCachedCapabilities )
395
396 if ( mHasCachedDropSupport )
397 return mCachedSupportsDrop;
398
399 // otherwise, we are limited to VERY VERY cheap calculations only!!
400 // DO NOT UNDER *****ANY***** CIRCUMSTANCES OPEN DATASETS HERE!!!!
401
402 mHasCachedDropSupport = true;
403 if ( !QFileInfo( path() ).isWritable() )
404 {
405 mCachedSupportsDrop = false;
406 return mCachedSupportsDrop;
407 }
408
409 GDALDriverH hDriver = GDALIdentifyDriverEx( path().toUtf8().constData(), GDAL_OF_VECTOR, nullptr, nullptr );
410 if ( !hDriver )
411 {
412 mCachedSupportsDrop = false;
413 return mCachedSupportsDrop;
414 }
415
416 // explicitly blocklist some drivers which we don't want to expose drop support for
417 const QString driverName = GDALGetDriverShortName( hDriver );
418 if ( driverName == "PDF"_L1 || driverName == "DXF"_L1 )
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 = u"collection"_s;
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( u"GDALIdentifyDriverEx error # %1 : %2 on %3"_s.arg( CPLGetLastErrorNo() ).arg( CPLGetLastErrorMsg() ).arg( path() ), 2 );
469 return nullptr;
470 }
471
472 const QString driverName = GDALGetDriverShortName( hDriver );
473 if ( driverName == "PDF"_L1 || driverName == "DXF"_L1 )
474 {
475 // unwanted drivers -- it's slow to create connections for these, and we don't really want
476 // to expose database capabilities for them (even though they kind of are database formats)
477 return nullptr;
478 }
479
481 if ( driverName == "SQLite"_L1 )
482 {
483 // sqlite gets special handling, as we delegate to the native spatialite provider
484 if ( QgsProviderMetadata *md = QgsProviderRegistry::instance()->providerMetadata( u"spatialite"_s ) )
485 {
487 uri.setDatabase( path() );
488 conn = static_cast<QgsAbstractDatabaseProviderConnection *>( md->createConnection( uri.uri(), {} ) );
489 }
490 }
491 else
492 {
493 // for all other vector types we use the generic OGR provider
494 if ( QgsProviderMetadata *md = QgsProviderRegistry::instance()->providerMetadata( u"ogr"_s ) )
495 {
496 QVariantMap parts;
497 parts.insert( u"path"_s, path() );
498 conn = static_cast<QgsAbstractDatabaseProviderConnection *>( md->createConnection( md->encodeUri( parts ), {} ) );
499 }
500 }
501
502 if ( conn )
503 {
504 mCachedCapabilities = conn->capabilities();
505 mCachedCapabilities2 = conn->capabilities2();
506 mHasCachedCapabilities = true;
507 }
508
509 return conn;
510}
511
513{
514 if ( mHasCachedCapabilities )
515 return mCachedCapabilities;
516
517 std::unique_ptr<QgsAbstractDatabaseProviderConnection> conn( databaseConnection() );
518 if ( conn )
519 {
520 mCachedCapabilities = conn->capabilities();
521 mCachedCapabilities2 = conn->capabilities2();
522 mHasCachedCapabilities = true;
523 }
524 return mCachedCapabilities;
525}
526
528{
529 if ( mHasCachedCapabilities )
530 return mCachedCapabilities2;
531
532 std::unique_ptr<QgsAbstractDatabaseProviderConnection> conn( databaseConnection() );
533 if ( conn )
534 {
535 mCachedCapabilities = conn->capabilities();
536 mCachedCapabilities2 = conn->capabilities2();
537 mHasCachedCapabilities = true;
538 }
539 return mCachedCapabilities2;
540}
541
542QList<QgsProviderSublayerDetails> QgsFileDataCollectionItem::sublayers() const
543{
544 return mSublayers;
545}
546
547//
548// QgsFileBasedDataItemProvider
549//
550
552{
553 return u"files"_s;
554}
555
560
562{
563 return createDataItemForPathPrivate( path, parentItem, nullptr, Qgis::SublayerQueryFlags(), QVariantMap() );
564}
565
567 const QString &path, QgsDataItem *parentItem, const QStringList &allowedProviders, const QVariantMap &extraUriParts, Qgis::SublayerQueryFlags queryFlags
568)
569{
570 return createDataItemForPathPrivate( path, parentItem, &allowedProviders, queryFlags, extraUriParts );
571}
572
573QgsDataItem *QgsFileBasedDataItemProvider::createDataItemForPathPrivate(
574 const QString &path, QgsDataItem *parentItem, const QStringList *allowedProviders, Qgis::SublayerQueryFlags queryFlags, const QVariantMap &extraUriParts
575)
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 ) && GDALIdentifyDriverEx( path.toUtf8().constData(), GDAL_OF_VECTOR, nullptr, nullptr ) )
618 {
619 suffix = u"shp.zip"_s;
620 }
621
622 // hide blocklisted URIs, such as .aux.xml files
623 if ( QgsProviderRegistry::instance()->uriIsBlocklisted( path ) )
624 return nullptr;
625
626 // should we fast scan only?
627 if ( ( settingsScanItemsInBrowser->value() == "extension"_L1 ) || ( parentItem && QgsSettingsRegistryCore::settingsScanItemsFastScanUris->value().contains( parentItem->path() ) ) )
628 {
630 }
631
632 QList<QgsProviderSublayerDetails> sublayers;
633 if ( !allowedProviders )
634 {
635 sublayers = QgsProviderRegistry::instance()->querySublayers( path, queryFlags );
636 }
637 else
638 {
639 for ( const QString &provider : *allowedProviders )
640 {
641 if ( QgsProviderMetadata *metadata = QgsProviderRegistry::instance()->providerMetadata( provider ) )
642 {
643 if ( !extraUriParts.empty() )
644 {
645 QVariantMap uriParts = metadata->decodeUri( path );
646 for ( auto it = extraUriParts.constBegin(); it != extraUriParts.constEnd(); ++it )
647 {
648 uriParts.insert( it.key(), it.value() );
649 }
650
651 sublayers.append( metadata->querySublayers( metadata->encodeUri( uriParts ), queryFlags ) );
652 }
653 else
654 {
655 sublayers.append( metadata->querySublayers( path, queryFlags ) );
656 }
657 }
658 }
659 }
660
661 if ( sublayers.size() == 1
663 {
664 QgsProviderSublayerItem *item = new QgsProviderSublayerItem( parentItem, name, sublayers.at( 0 ), path );
666 return item;
667 }
668 else if ( !sublayers.empty() )
669 {
670 QgsFileDataCollectionItem *item = new QgsFileDataCollectionItem( parentItem, name, path, sublayers, extraUriParts );
672 return item;
673 }
674 else
675 {
676 return nullptr;
677 }
678}
679
681{
682 QFileInfo info( path );
683 QString suffix = info.suffix().toLower();
684
685 QStringList dirExtensions = QgsOgrProviderUtils::directoryExtensions();
686 return dirExtensions.contains( suffix );
687}
@ Files
Can provides items which corresponds to files.
Definition qgis.h:1045
@ Directories
Can provides items which corresponds to directories.
Definition qgis.h:1046
@ NotPopulated
Children not yet created.
Definition qgis.h:987
@ Populated
Children created.
Definition qgis.h:989
@ Fertile
Can create children. Even items without this capability may have children, but cannot create them,...
Definition qgis.h:1002
@ RefreshChildrenWhenItemIsRefreshed
When the item is refreshed, all its populated children will also be refreshed in turn.
Definition qgis.h:1008
@ ItemRepresentsFile
Item's path() directly represents a file on disk.
Definition qgis.h:1007
@ Fast
CreateChildren() is fast enough to be run in main thread when refreshing items, most root items (wms,...
Definition qgis.h:1003
@ Archive
File archive type (e.g. vsizip).
Definition qgis.h:6246
QFlags< DataItemProviderCapability > DataItemProviderCapabilities
Capabilities for data item providers.
Definition qgis.h:1059
@ FastScan
Indicates that the provider must scan for sublayers using the fastest possible approach – e....
Definition qgis.h:1511
@ ResolveGeometryType
Attempt to resolve the geometry type for vector sublayers.
Definition qgis.h:1512
@ Point
Points.
Definition qgis.h:380
@ Line
Lines.
Definition qgis.h:381
@ Polygon
Polygons.
Definition qgis.h:382
@ Unknown
Unknown types.
Definition qgis.h:383
@ Null
No geometry.
Definition qgis.h:384
BrowserLayerType
Browser item layer types.
Definition qgis.h:1068
@ Point
Vector point layer.
Definition qgis.h:1072
@ Plugin
Plugin based layer.
Definition qgis.h:1078
@ Line
Vector line layer.
Definition qgis.h:1073
@ TiledScene
Tiled scene layer.
Definition qgis.h:1082
@ Polygon
Vector polygon layer.
Definition qgis.h:1074
@ Vector
Generic vector layer.
Definition qgis.h:1070
@ VectorTile
Vector tile layer.
Definition qgis.h:1080
@ Mesh
Mesh layer.
Definition qgis.h:1079
@ Raster
Raster layer.
Definition qgis.h:1071
@ TableLayer
Vector non-spatial layer.
Definition qgis.h:1075
@ PointCloud
Point cloud layer.
Definition qgis.h:1081
QFlags< SublayerQueryFlag > SublayerQueryFlags
Sublayer query flags.
Definition qgis.h:1518
@ Group
Composite group layer. Added in QGIS 3.24.
Definition qgis.h:214
@ Plugin
Plugin based layer.
Definition qgis.h:209
@ TiledScene
Tiled scene layer. Added in QGIS 3.34.
Definition qgis.h:215
@ Annotation
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
Definition qgis.h:212
@ Vector
Vector layer.
Definition qgis.h:207
@ VectorTile
Vector tile layer. Added in QGIS 3.14.
Definition qgis.h:211
@ Mesh
Mesh layer. Added in QGIS 3.2.
Definition qgis.h:210
@ Raster
Raster layer.
Definition qgis.h:208
@ PointCloud
Point cloud layer. Added in QGIS 3.18.
Definition qgis.h:213
QFlags< DatabaseProviderConnectionCapability2 > DatabaseProviderConnectionCapabilities2
Definition qgis.h:5898
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.
static const QgsSettingsEntryString * settingsScanItemsInBrowser
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.
T value(const QString &dynamicKeyPart=QString()) const
Returns settings value.
A string settings entry.
static const QgsSettingsEntryStringList * settingsScanItemsFastScanUris
Settings entry for fast scan URIs in browser.
static QgsSettingsTreeNode * sTreeBrowser
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.