QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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 : QgsLayerItem( parent, name, filePath.isEmpty() ? details.uri() : filePath, details.uri(), layerTypeFromSublayer( details ), details.providerKey() )
46 , mDetails( details )
47{
48 mToolTip = details.uri();
49
50 // no children, except for vector layers, which will show the fields item
52}
53
55{
56 QVector<QgsDataItem *> children;
57
58 if ( mDetails.type() == Qgis::LayerType::Vector )
59 {
60 // sqlite gets special handling because it delegates to the dedicated spatialite provider
61 if ( mDetails.driverName() == "SQLite"_L1 )
62 {
63 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() ) );
64 }
65 else if ( mDetails.providerKey() == "ogr"_L1 )
66 {
67 // otherwise we use the default OGR database connection approach, which is the generic way to handle this
68 // for all OGR layer types
69 children.push_back( new QgsFieldsItem( this, path() + u"/columns/ "_s, path(), u"ogr"_s, QString(), name() ) );
70
71 std::unique_ptr<QgsAbstractDatabaseProviderConnection> conn( databaseConnection() );
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 auto relationsItem = std::make_unique< QgsRelationshipsItem >( this, mPath + "/relations", conn->uri(), u"ogr"_s, 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
102
104{
105 if ( parent() )
106 {
108 return connection;
109 }
110
111 if ( mDetails.providerKey() == "ogr"_L1 )
112 {
113 if ( QgsProviderMetadata *md = QgsProviderRegistry::instance()->providerMetadata( u"ogr"_s ) )
114 {
115 QVariantMap parts;
116 parts.insert( u"path"_s, 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//
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, const QVariantMap &extraUriParts )
218 , mSublayers( sublayers )
219 , mExtraUriParts( extraUriParts )
220{
223 else
225
227 {
228 mIconName = u"/mIconZip.svg"_s;
229 }
230}
231
233{
234 QList< QgsProviderSublayerDetails> sublayers;
236 {
237 QSet< QString > providers;
238 for ( const QgsProviderSublayerDetails &details : std::as_const( mSublayers ) )
239 {
240 providers.insert( details.providerKey() );
241 }
242
243 for ( const QString &provider : std::as_const( providers ) )
244 {
245 if ( QgsProviderMetadata *metadata = QgsProviderRegistry::instance()->providerMetadata( provider ) )
246 {
247 if ( !mExtraUriParts.empty() )
248 {
249 QVariantMap uriParts = metadata->decodeUri( path() );
250 for ( auto it = mExtraUriParts.constBegin(); it != mExtraUriParts.constEnd(); ++it )
251 {
252 uriParts.insert( it.key(), it.value() );
253 }
254 const QString updatedUri = metadata->encodeUri( uriParts );
255
256 sublayers.append( metadata->querySublayers( updatedUri.isEmpty() ? path() : updatedUri, Qgis::SublayerQueryFlag::ResolveGeometryType ) );
257 }
258 else
259 {
260 sublayers.append( metadata->querySublayers( path(), Qgis::SublayerQueryFlag::ResolveGeometryType ) );
261 }
262 }
263 }
264 }
265 else if ( mSublayers.empty() )
266 {
268 }
269 else
270 {
271 sublayers = mSublayers;
272 }
273 // only ever use the initial sublayers for first population -- after that we requery when asked to create children,
274 // or the item won't "refresh" and update its sublayers when the actual file changes
275 mSublayers.clear();
276 // remove the fast flag -- after the first population we need to requery the dataset
278
279 QVector<QgsDataItem *> children;
280 children.reserve( sublayers.size() );
281 QMap< QStringList, QgsFileDataCollectionGroupItem * > groupItems;
282 for ( const QgsProviderSublayerDetails &sublayer : std::as_const( sublayers ) )
283 {
284 QgsProviderSublayerItem *item = new QgsProviderSublayerItem( nullptr, sublayer.name(), sublayer, QString() );
285
286 if ( !sublayer.path().isEmpty() )
287 {
288 QStringList currentPath;
289 QStringList remainingPaths = sublayer.path();
290 QgsFileDataCollectionGroupItem *groupItem = nullptr;
291
292 while ( !remainingPaths.empty() )
293 {
294 currentPath << remainingPaths.takeAt( 0 );
295
296 auto it = groupItems.constFind( currentPath );
297 if ( it == groupItems.constEnd() )
298 {
299 QgsFileDataCollectionGroupItem *newGroupItem = new QgsFileDataCollectionGroupItem( this, currentPath.constLast(), path() + '/' + currentPath.join( ',' ) );
301 groupItems.insert( currentPath, newGroupItem );
302 if ( groupItem )
303 groupItem->addChildItem( newGroupItem );
304 else
305 children.append( newGroupItem );
306 groupItem = newGroupItem;
307 }
308 else
309 {
310 groupItem = it.value();
311 }
312
313 if ( groupItem )
314 groupItem->appendSublayer( sublayer );
315 }
316
317 if ( groupItem )
318 groupItem->addChildItem( item );
319 }
320 else
321 {
322 children.append( item );
323 }
324 }
325
326 std::unique_ptr<QgsAbstractDatabaseProviderConnection> conn( databaseConnection() );
327 if ( conn )
328 {
329 mCachedCapabilities = conn->capabilities();
330 mCachedCapabilities2 = conn->capabilities2();
331 mHasCachedCapabilities = true;
332 }
333 if ( conn && ( mCachedCapabilities & QgsAbstractDatabaseProviderConnection::Capability::ListFieldDomains ) )
334 {
335 QString domainError;
336 QStringList fieldDomains;
337 try
338 {
339 fieldDomains = conn->fieldDomainNames();
340 }
342 {
343 domainError = ex.what();
344 }
345
346 if ( !fieldDomains.empty() || !domainError.isEmpty() )
347 {
348 auto domainsItem = std::make_unique< QgsFieldDomainsItem >( this, mPath + "/domains", conn->uri(), u"ogr"_s );
349 // force this item to appear last by setting a maximum string value for the sort key
350 domainsItem->setSortKey( QString( QChar( 0xFFFF ) ) );
351 children.append( domainsItem.release() );
352 }
353 }
355 {
356 QString relationError;
357 QList< QgsWeakRelation > relations;
358 try
359 {
360 relations = conn->relationships();
361 }
363 {
364 relationError = ex.what();
365 }
366
367 if ( !relations.empty() || !relationError.isEmpty() )
368 {
369 auto relationsItem = std::make_unique< QgsRelationshipsItem >( this, mPath + "/relations", conn->uri(), u"ogr"_s );
370 // force this item to appear last by setting a maximum string value for the sort key
371 relationsItem->setSortKey( QString( QChar( 0x11FFFF ) ) );
372 children.append( relationsItem.release() );
373 }
374 }
375
376 return children;
377}
378
380{
381 return true;
382}
383
385{
386 // if we've previously opened a connection for this item, we can use the previously
387 // determined capababilities to return an accurate answer.
388 if ( mHasCachedCapabilities )
390
391 if ( mHasCachedDropSupport )
392 return mCachedSupportsDrop;
393
394 // otherwise, we are limited to VERY VERY cheap calculations only!!
395 // DO NOT UNDER *****ANY***** CIRCUMSTANCES OPEN DATASETS HERE!!!!
396
397 mHasCachedDropSupport = true;
398 if ( !QFileInfo( path() ).isWritable() )
399 {
400 mCachedSupportsDrop = false;
401 return mCachedSupportsDrop;
402 }
403
404 GDALDriverH hDriver = GDALIdentifyDriverEx( path().toUtf8().constData(), GDAL_OF_VECTOR, nullptr, nullptr );
405 if ( !hDriver )
406 {
407 mCachedSupportsDrop = false;
408 return mCachedSupportsDrop;
409 }
410
411 // explicitly blocklist some drivers which we don't want to expose drop support for
412 const QString driverName = GDALGetDriverShortName( hDriver );
413 if ( driverName == "PDF"_L1 || driverName == "DXF"_L1 )
414 {
415 mCachedSupportsDrop = false;
416 return mCachedSupportsDrop;
417 }
418
419 // DO NOT UNDER *****ANY***** CIRCUMSTANCES OPEN DATASETS HERE!!!!
420#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION( 3, 4, 0 )
421 const bool isSingleTableDriver = !GDALGetMetadataItem( hDriver, GDAL_DCAP_MULTIPLE_VECTOR_LAYERS, nullptr );
422#else
423 const QFileInfo pathInfo( path() );
424 const QString suffix = pathInfo.suffix().toLower();
425 const bool isSingleTableDriver = !QgsGdalUtils::multiLayerFileExtensions().contains( suffix );
426#endif
427
428 if ( isSingleTableDriver )
429 {
430 mCachedSupportsDrop = false;
431 return mCachedSupportsDrop;
432 }
433
434 // DO NOT UNDER *****ANY***** CIRCUMSTANCES OPEN DATASETS HERE!!!!
435 mCachedSupportsDrop = true;
436 return mCachedSupportsDrop;
437}
438
440{
441 QgsMimeDataUtils::Uri collectionUri;
442 collectionUri.uri = path();
443 collectionUri.layerType = u"collection"_s;
444 collectionUri.filePath = path();
445 return { collectionUri };
446}
447
449{
450 // test that file is valid with OGR
451 if ( OGRGetDriverCount() == 0 )
452 {
453 OGRRegisterAll();
454 }
455 // do not print errors, but write to debug
456 CPLPushErrorHandler( CPLQuietErrorHandler );
457 CPLErrorReset();
458 GDALDriverH hDriver = GDALIdentifyDriverEx( path().toUtf8().constData(), GDAL_OF_VECTOR, nullptr, nullptr );
459 CPLPopErrorHandler();
460
461 if ( !hDriver )
462 {
463 QgsDebugMsgLevel( u"GDALIdentifyDriverEx error # %1 : %2 on %3"_s.arg( CPLGetLastErrorNo() ).arg( CPLGetLastErrorMsg() ).arg( path() ), 2 );
464 return nullptr;
465 }
466
467 const QString driverName = GDALGetDriverShortName( hDriver );
468 if ( driverName == "PDF"_L1 || driverName == "DXF"_L1 )
469 {
470 // unwanted drivers -- it's slow to create connections for these, and we don't really want
471 // to expose database capabilities for them (even though they kind of are database formats)
472 return nullptr;
473 }
474
476 if ( driverName == "SQLite"_L1 )
477 {
478 // sqlite gets special handling, as we delegate to the native spatialite provider
479 if ( QgsProviderMetadata *md = QgsProviderRegistry::instance()->providerMetadata( u"spatialite"_s ) )
480 {
482 uri.setDatabase( path() );
483 conn = static_cast<QgsAbstractDatabaseProviderConnection *>( md->createConnection( uri.uri(), {} ) );
484 }
485 }
486 else
487 {
488 // for all other vector types we use the generic OGR provider
489 if ( QgsProviderMetadata *md = QgsProviderRegistry::instance()->providerMetadata( u"ogr"_s ) )
490 {
491 QVariantMap parts;
492 parts.insert( u"path"_s, path() );
493 conn = static_cast<QgsAbstractDatabaseProviderConnection *>( md->createConnection( md->encodeUri( parts ), {} ) );
494 }
495 }
496
497 if ( conn )
498 {
499 mCachedCapabilities = conn->capabilities();
500 mCachedCapabilities2 = conn->capabilities2();
501 mHasCachedCapabilities = true;
502 }
503
504 return conn;
505}
506
508{
509 if ( mHasCachedCapabilities )
510 return mCachedCapabilities;
511
512 std::unique_ptr<QgsAbstractDatabaseProviderConnection> conn( databaseConnection() );
513 if ( conn )
514 {
515 mCachedCapabilities = conn->capabilities();
516 mCachedCapabilities2 = conn->capabilities2();
517 mHasCachedCapabilities = true;
518 }
519 return mCachedCapabilities;
520}
521
523{
524 if ( mHasCachedCapabilities )
525 return mCachedCapabilities2;
526
527 std::unique_ptr<QgsAbstractDatabaseProviderConnection> conn( databaseConnection() );
528 if ( conn )
529 {
530 mCachedCapabilities = conn->capabilities();
531 mCachedCapabilities2 = conn->capabilities2();
532 mHasCachedCapabilities = true;
533 }
534 return mCachedCapabilities2;
535}
536
537QList<QgsProviderSublayerDetails> QgsFileDataCollectionItem::sublayers() const
538{
539 return mSublayers;
540}
541
542//
543// QgsFileBasedDataItemProvider
544//
545
547{
548 return u"files"_s;
549}
550
555
557{
558 return createDataItemForPathPrivate( path, parentItem, nullptr, Qgis::SublayerQueryFlags(), QVariantMap() );
559}
560
562 const QString &path, QgsDataItem *parentItem, const QStringList &allowedProviders, const QVariantMap &extraUriParts, Qgis::SublayerQueryFlags queryFlags
563)
564{
565 return createDataItemForPathPrivate( path, parentItem, &allowedProviders, queryFlags, extraUriParts );
566}
567
568QgsDataItem *QgsFileBasedDataItemProvider::createDataItemForPathPrivate(
569 const QString &path, QgsDataItem *parentItem, const QStringList *allowedProviders, Qgis::SublayerQueryFlags queryFlags, const QVariantMap &extraUriParts
570)
571{
572 if ( path.isEmpty() )
573 return nullptr;
574
575 const QFileInfo info( path );
576 QString suffix = info.suffix().toLower();
577 const QString name = info.fileName();
578
579 // special handling for some suffixes
580 if ( suffix.compare( "gpkg"_L1, Qt::CaseInsensitive ) == 0 )
581 {
582 // Geopackage is special -- it gets a dedicated collection item type
583 QgsGeoPackageCollectionItem *item = new QgsGeoPackageCollectionItem( parentItem, name, path );
584 item->setCapabilities( item->capabilities2() | Qgis::BrowserItemCapability::ItemRepresentsFile );
585 return item;
586 }
587 else if ( suffix == "txt"_L1 )
588 {
589 // never ever show .txt files as datasets in browser -- they are only used for geospatial data in extremely rare cases
590 // and are predominantly just noise in the browser
591 return nullptr;
592 }
593 // If a .tab exists, then the corresponding .map/.dat is very likely a
594 // side-car file of the .tab
595 else if ( suffix == "map"_L1 || suffix == "dat"_L1 )
596 {
597 if ( QFile::exists( QDir( info.path() ).filePath( info.baseName() + ".tab" ) ) || QFile::exists( QDir( info.path() ).filePath( info.baseName() + ".TAB" ) ) )
598 return nullptr;
599 }
600 // .dbf and .shx should only appear if .shp is not present
601 else if ( suffix == "dbf"_L1 || suffix == "shx"_L1 )
602 {
603 if ( QFile::exists( QDir( info.path() ).filePath( info.baseName() + ".shp" ) ) || QFile::exists( QDir( info.path() ).filePath( info.baseName() + ".SHP" ) ) )
604 return nullptr;
605 }
606 // skip QGIS style xml files
607 else if ( suffix == "xml"_L1 && QgsStyle::isXmlStyleFile( path ) )
608 {
609 return nullptr;
610 }
611 // GDAL 3.1 Shapefile driver directly handles .shp.zip files
612 else if ( path.endsWith( ".shp.zip"_L1, Qt::CaseInsensitive ) && GDALIdentifyDriverEx( path.toUtf8().constData(), GDAL_OF_VECTOR, nullptr, nullptr ) )
613 {
614 suffix = u"shp.zip"_s;
615 }
616
617 // hide blocklisted URIs, such as .aux.xml files
618 if ( QgsProviderRegistry::instance()->uriIsBlocklisted( path ) )
619 return nullptr;
620
621 QgsSettings settings;
622
623 // should we fast scan only?
624 if ( ( settings.value( u"qgis/scanItemsInBrowser2"_s, "extension" ).toString() == "extension"_L1 )
625 || ( parentItem && settings.value( u"qgis/scanItemsFastScanUris"_s, QStringList() ).toStringList().contains( parentItem->path() ) ) )
626 {
628 }
629
630 QList<QgsProviderSublayerDetails> sublayers;
631 if ( !allowedProviders )
632 {
633 sublayers = QgsProviderRegistry::instance()->querySublayers( path, queryFlags );
634 }
635 else
636 {
637 for ( const QString &provider : *allowedProviders )
638 {
639 if ( QgsProviderMetadata *metadata = QgsProviderRegistry::instance()->providerMetadata( provider ) )
640 {
641 if ( !extraUriParts.empty() )
642 {
643 QVariantMap uriParts = metadata->decodeUri( path );
644 for ( auto it = extraUriParts.constBegin(); it != extraUriParts.constEnd(); ++it )
645 {
646 uriParts.insert( it.key(), it.value() );
647 }
648
649 sublayers.append( metadata->querySublayers( metadata->encodeUri( uriParts ), queryFlags ) );
650 }
651 else
652 {
653 sublayers.append( metadata->querySublayers( path, queryFlags ) );
654 }
655 }
656 }
657 }
658
659 if ( sublayers.size() == 1
661 {
662 QgsProviderSublayerItem *item = new QgsProviderSublayerItem( parentItem, name, sublayers.at( 0 ), path );
664 return item;
665 }
666 else if ( !sublayers.empty() )
667 {
668 QgsFileDataCollectionItem *item = new QgsFileDataCollectionItem( parentItem, name, path, sublayers, extraUriParts );
670 return item;
671 }
672 else
673 {
674 return nullptr;
675 }
676}
677
679{
680 QFileInfo info( path );
681 QString suffix = info.suffix().toLower();
682
683 QStringList dirExtensions = QgsOgrProviderUtils::directoryExtensions();
684 return dirExtensions.contains( suffix );
685}
@ Files
Can provides items which corresponds to files.
Definition qgis.h:1004
@ Directories
Can provides items which corresponds to directories.
Definition qgis.h:1005
@ NotPopulated
Children not yet created.
Definition qgis.h:965
@ Populated
Children created.
Definition qgis.h:967
@ Fertile
Can create children. Even items without this capability may have children, but cannot create them,...
Definition qgis.h:980
@ RefreshChildrenWhenItemIsRefreshed
When the item is refreshed, all its populated children will also be refreshed in turn.
Definition qgis.h:986
@ ItemRepresentsFile
Item's path() directly represents a file on disk.
Definition qgis.h:985
@ Fast
CreateChildren() is fast enough to be run in main thread when refreshing items, most root items (wms,...
Definition qgis.h:981
@ Archive
File archive type (e.g. vsizip).
Definition qgis.h:6102
QFlags< DataItemProviderCapability > DataItemProviderCapabilities
Capabilities for data item providers.
Definition qgis.h:1018
@ FastScan
Indicates that the provider must scan for sublayers using the fastest possible approach – e....
Definition qgis.h:1470
@ ResolveGeometryType
Attempt to resolve the geometry type for vector sublayers.
Definition qgis.h:1471
@ 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:1027
@ Point
Vector point layer.
Definition qgis.h:1031
@ Plugin
Plugin based layer.
Definition qgis.h:1037
@ Line
Vector line layer.
Definition qgis.h:1032
@ TiledScene
Tiled scene layer.
Definition qgis.h:1041
@ Polygon
Vector polygon layer.
Definition qgis.h:1033
@ Vector
Generic vector layer.
Definition qgis.h:1029
@ VectorTile
Vector tile layer.
Definition qgis.h:1039
@ Mesh
Mesh layer.
Definition qgis.h:1038
@ Raster
Raster layer.
Definition qgis.h:1030
@ TableLayer
Vector non-spatial layer.
Definition qgis.h:1034
@ PointCloud
Point cloud layer.
Definition qgis.h:1040
QFlags< SublayerQueryFlag > SublayerQueryFlags
Sublayer query flags.
Definition qgis.h:1477
@ 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:5754
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.