QGIS API Documentation 4.1.0-Master (3b8ef1f72a3)
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"
33#include "qgsstyle.h"
34
35#include <QString>
36#include <QUrlQuery>
37
38#include "moc_qgsfilebaseddataitemprovider.cpp"
39
40using namespace Qt::StringLiterals;
41
42//
43// QgsProviderSublayerItem
44//
45
47 : QgsLayerItem( parent, name, filePath.isEmpty() ? details.uri() : filePath, details.uri(), layerTypeFromSublayer( details ), details.providerKey() )
48 , mDetails( details )
49{
50 mToolTip = details.uri();
51
52 // no children, except for vector layers, which will show the fields item
54}
55
57{
58 QVector<QgsDataItem *> children;
59
60 if ( mDetails.type() == Qgis::LayerType::Vector )
61 {
62 // sqlite gets special handling because it delegates to the dedicated spatialite provider
63 if ( mDetails.driverName() == "SQLite"_L1 )
64 {
65 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() ) );
66 }
67 else if ( mDetails.providerKey() == "ogr"_L1 )
68 {
69 // otherwise we use the default OGR database connection approach, which is the generic way to handle this
70 // for all OGR layer types
71 children.push_back( new QgsFieldsItem( this, path() + u"/columns/ "_s, path(), u"ogr"_s, QString(), name() ) );
72
73 std::unique_ptr<QgsAbstractDatabaseProviderConnection> conn( databaseConnection() );
75 {
76 QString relationError;
77 QList< QgsWeakRelation > relations;
78 try
79 {
80 relations = conn->relationships( QString(), mDetails.name() );
81 }
83 {
84 relationError = ex.what();
85 }
86
87 if ( !relations.empty() || !relationError.isEmpty() )
88 {
89 auto relationsItem = std::make_unique< QgsRelationshipsItem >( this, mPath + "/relations", conn->uri(), u"ogr"_s, QString(), mDetails.name() );
90 // force this item to appear last by setting a maximum string value for the sort key
91 relationsItem->setSortKey( QString( QChar( 0x11FFFF ) ) );
92 children.append( relationsItem.release() );
93 }
94 }
95 }
96 }
97 return children;
98}
99
104
106{
107 if ( parent() )
108 {
110 return connection;
111 }
112
113 if ( mDetails.providerKey() == "ogr"_L1 )
114 {
115 if ( QgsProviderMetadata *md = QgsProviderRegistry::instance()->providerMetadata( u"ogr"_s ) )
116 {
117 QVariantMap parts;
118 parts.insert( u"path"_s, path() );
119 return static_cast<QgsAbstractDatabaseProviderConnection *>( md->createConnection( md->encodeUri( parts ), {} ) );
120 }
121 }
122
123 return nullptr;
124}
125
126Qgis::BrowserLayerType QgsProviderSublayerItem::layerTypeFromSublayer( const QgsProviderSublayerDetails &sublayer )
127{
128 switch ( sublayer.type() )
129 {
131 {
132 switch ( QgsWkbTypes::geometryType( sublayer.wkbType() ) )
133 {
136
139
142
145
148 }
149
150 break;
151 }
154
157
160
163
166
169
172 break;
173 }
175}
176
178{
179 return mDetails.name();
180}
181
182//
183// QgsFileDataCollectionGroupItem
184//
191
193{
194 mSublayers.append( sublayer );
195}
196
198{
199 return true;
200}
201
203{
205 res.reserve( mSublayers.size() );
206
207 for ( const QgsProviderSublayerDetails &sublayer : mSublayers )
208 {
209 res << sublayer.toMimeUri();
210 }
211 return res;
212}
213
214//
215// QgsFileDataCollectionItem
216//
217
218QgsFileDataCollectionItem::QgsFileDataCollectionItem( QgsDataItem *parent, const QString &name, const QString &path, const QList<QgsProviderSublayerDetails> &sublayers, const QVariantMap &extraUriParts )
220 , mSublayers( sublayers )
221 , mExtraUriParts( extraUriParts )
222{
225 else
227
229 {
230 mIconName = u"/mIconZip.svg"_s;
231 }
232}
233
235{
236 QList< QgsProviderSublayerDetails> sublayers;
238 {
239 QSet< QString > providers;
240 for ( const QgsProviderSublayerDetails &details : std::as_const( mSublayers ) )
241 {
242 providers.insert( details.providerKey() );
243 }
244
245 for ( const QString &provider : std::as_const( providers ) )
246 {
247 if ( QgsProviderMetadata *metadata = QgsProviderRegistry::instance()->providerMetadata( provider ) )
248 {
249 if ( !mExtraUriParts.empty() )
250 {
251 QVariantMap uriParts = metadata->decodeUri( path() );
252 for ( auto it = mExtraUriParts.constBegin(); it != mExtraUriParts.constEnd(); ++it )
253 {
254 uriParts.insert( it.key(), it.value() );
255 }
256 const QString updatedUri = metadata->encodeUri( uriParts );
257
258 sublayers.append( metadata->querySublayers( updatedUri.isEmpty() ? path() : updatedUri, Qgis::SublayerQueryFlag::ResolveGeometryType ) );
259 }
260 else
261 {
262 sublayers.append( metadata->querySublayers( path(), Qgis::SublayerQueryFlag::ResolveGeometryType ) );
263 }
264 }
265 }
266 }
267 else if ( mSublayers.empty() )
268 {
270 }
271 else
272 {
273 sublayers = mSublayers;
274 }
275 // only ever use the initial sublayers for first population -- after that we requery when asked to create children,
276 // or the item won't "refresh" and update its sublayers when the actual file changes
277 mSublayers.clear();
278 // remove the fast flag -- after the first population we need to requery the dataset
280
281 QVector<QgsDataItem *> children;
282 children.reserve( sublayers.size() );
283 QMap< QStringList, QgsFileDataCollectionGroupItem * > groupItems;
284 for ( const QgsProviderSublayerDetails &sublayer : std::as_const( sublayers ) )
285 {
286 QgsProviderSublayerItem *item = new QgsProviderSublayerItem( nullptr, sublayer.name(), sublayer, QString() );
287
288 if ( !sublayer.path().isEmpty() )
289 {
290 QStringList currentPath;
291 QStringList remainingPaths = sublayer.path();
292 QgsFileDataCollectionGroupItem *groupItem = nullptr;
293
294 while ( !remainingPaths.empty() )
295 {
296 currentPath << remainingPaths.takeAt( 0 );
297
298 auto it = groupItems.constFind( currentPath );
299 if ( it == groupItems.constEnd() )
300 {
301 QgsFileDataCollectionGroupItem *newGroupItem = new QgsFileDataCollectionGroupItem( this, currentPath.constLast(), path() + '/' + currentPath.join( ',' ) );
303 groupItems.insert( currentPath, newGroupItem );
304 if ( groupItem )
305 groupItem->addChildItem( newGroupItem );
306 else
307 children.append( newGroupItem );
308 groupItem = newGroupItem;
309 }
310 else
311 {
312 groupItem = it.value();
313 }
314
315 if ( groupItem )
316 groupItem->appendSublayer( sublayer );
317 }
318
319 if ( groupItem )
320 groupItem->addChildItem( item );
321 }
322 else
323 {
324 children.append( item );
325 }
326 }
327
328 std::unique_ptr<QgsAbstractDatabaseProviderConnection> conn( databaseConnection() );
329 if ( conn )
330 {
331 mCachedCapabilities = conn->capabilities();
332 mCachedCapabilities2 = conn->capabilities2();
333 mHasCachedCapabilities = true;
334 }
335 if ( conn && ( mCachedCapabilities & QgsAbstractDatabaseProviderConnection::Capability::ListFieldDomains ) )
336 {
337 QString domainError;
338 QStringList fieldDomains;
339 try
340 {
341 fieldDomains = conn->fieldDomainNames();
342 }
344 {
345 domainError = ex.what();
346 }
347
348 if ( !fieldDomains.empty() || !domainError.isEmpty() )
349 {
350 auto domainsItem = std::make_unique< QgsFieldDomainsItem >( this, mPath + "/domains", conn->uri(), u"ogr"_s );
351 // force this item to appear last by setting a maximum string value for the sort key
352 domainsItem->setSortKey( QString( QChar( 0xFFFF ) ) );
353 children.append( domainsItem.release() );
354 }
355 }
357 {
358 QString relationError;
359 QList< QgsWeakRelation > relations;
360 try
361 {
362 relations = conn->relationships();
363 }
365 {
366 relationError = ex.what();
367 }
368
369 if ( !relations.empty() || !relationError.isEmpty() )
370 {
371 auto relationsItem = std::make_unique< QgsRelationshipsItem >( this, mPath + "/relations", conn->uri(), u"ogr"_s );
372 // force this item to appear last by setting a maximum string value for the sort key
373 relationsItem->setSortKey( QString( QChar( 0x11FFFF ) ) );
374 children.append( relationsItem.release() );
375 }
376 }
377
378 return children;
379}
380
382{
383 return true;
384}
385
387{
388 // if we've previously opened a connection for this item, we can use the previously
389 // determined capababilities to return an accurate answer.
390 if ( mHasCachedCapabilities )
392
393 if ( mHasCachedDropSupport )
394 return mCachedSupportsDrop;
395
396 // otherwise, we are limited to VERY VERY cheap calculations only!!
397 // DO NOT UNDER *****ANY***** CIRCUMSTANCES OPEN DATASETS HERE!!!!
398
399 mHasCachedDropSupport = true;
400 if ( !QFileInfo( path() ).isWritable() )
401 {
402 mCachedSupportsDrop = false;
403 return mCachedSupportsDrop;
404 }
405
406 GDALDriverH hDriver = GDALIdentifyDriverEx( path().toUtf8().constData(), GDAL_OF_VECTOR, nullptr, nullptr );
407 if ( !hDriver )
408 {
409 mCachedSupportsDrop = false;
410 return mCachedSupportsDrop;
411 }
412
413 // explicitly blocklist some drivers which we don't want to expose drop support for
414 const QString driverName = GDALGetDriverShortName( hDriver );
415 if ( driverName == "PDF"_L1 || driverName == "DXF"_L1 )
416 {
417 mCachedSupportsDrop = false;
418 return mCachedSupportsDrop;
419 }
420
421 // DO NOT UNDER *****ANY***** CIRCUMSTANCES OPEN DATASETS HERE!!!!
422#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION( 3, 4, 0 )
423 const bool isSingleTableDriver = !GDALGetMetadataItem( hDriver, GDAL_DCAP_MULTIPLE_VECTOR_LAYERS, nullptr );
424#else
425 const QFileInfo pathInfo( path() );
426 const QString suffix = pathInfo.suffix().toLower();
427 const bool isSingleTableDriver = !QgsGdalUtils::multiLayerFileExtensions().contains( suffix );
428#endif
429
430 if ( isSingleTableDriver )
431 {
432 mCachedSupportsDrop = false;
433 return mCachedSupportsDrop;
434 }
435
436 // DO NOT UNDER *****ANY***** CIRCUMSTANCES OPEN DATASETS HERE!!!!
437 mCachedSupportsDrop = true;
438 return mCachedSupportsDrop;
439}
440
442{
443 QgsMimeDataUtils::Uri collectionUri;
444 collectionUri.uri = path();
445 collectionUri.layerType = u"collection"_s;
446 collectionUri.filePath = path();
447 return { collectionUri };
448}
449
451{
452 // test that file is valid with OGR
453 if ( OGRGetDriverCount() == 0 )
454 {
455 OGRRegisterAll();
456 }
457 // do not print errors, but write to debug
458 CPLPushErrorHandler( CPLQuietErrorHandler );
459 CPLErrorReset();
460 GDALDriverH hDriver = GDALIdentifyDriverEx( path().toUtf8().constData(), GDAL_OF_VECTOR, nullptr, nullptr );
461 CPLPopErrorHandler();
462
463 if ( !hDriver )
464 {
465 QgsDebugMsgLevel( u"GDALIdentifyDriverEx error # %1 : %2 on %3"_s.arg( CPLGetLastErrorNo() ).arg( CPLGetLastErrorMsg() ).arg( path() ), 2 );
466 return nullptr;
467 }
468
469 const QString driverName = GDALGetDriverShortName( hDriver );
470 if ( driverName == "PDF"_L1 || driverName == "DXF"_L1 )
471 {
472 // unwanted drivers -- it's slow to create connections for these, and we don't really want
473 // to expose database capabilities for them (even though they kind of are database formats)
474 return nullptr;
475 }
476
478 if ( driverName == "SQLite"_L1 )
479 {
480 // sqlite gets special handling, as we delegate to the native spatialite provider
481 if ( QgsProviderMetadata *md = QgsProviderRegistry::instance()->providerMetadata( u"spatialite"_s ) )
482 {
484 uri.setDatabase( path() );
485 conn = static_cast<QgsAbstractDatabaseProviderConnection *>( md->createConnection( uri.uri(), {} ) );
486 }
487 }
488 else
489 {
490 // for all other vector types we use the generic OGR provider
491 if ( QgsProviderMetadata *md = QgsProviderRegistry::instance()->providerMetadata( u"ogr"_s ) )
492 {
493 QVariantMap parts;
494 parts.insert( u"path"_s, path() );
495 conn = static_cast<QgsAbstractDatabaseProviderConnection *>( md->createConnection( md->encodeUri( parts ), {} ) );
496 }
497 }
498
499 if ( conn )
500 {
501 mCachedCapabilities = conn->capabilities();
502 mCachedCapabilities2 = conn->capabilities2();
503 mHasCachedCapabilities = true;
504 }
505
506 return conn;
507}
508
510{
511 if ( mHasCachedCapabilities )
512 return mCachedCapabilities;
513
514 std::unique_ptr<QgsAbstractDatabaseProviderConnection> conn( databaseConnection() );
515 if ( conn )
516 {
517 mCachedCapabilities = conn->capabilities();
518 mCachedCapabilities2 = conn->capabilities2();
519 mHasCachedCapabilities = true;
520 }
521 return mCachedCapabilities;
522}
523
525{
526 if ( mHasCachedCapabilities )
527 return mCachedCapabilities2;
528
529 std::unique_ptr<QgsAbstractDatabaseProviderConnection> conn( databaseConnection() );
530 if ( conn )
531 {
532 mCachedCapabilities = conn->capabilities();
533 mCachedCapabilities2 = conn->capabilities2();
534 mHasCachedCapabilities = true;
535 }
536 return mCachedCapabilities2;
537}
538
539QList<QgsProviderSublayerDetails> QgsFileDataCollectionItem::sublayers() const
540{
541 return mSublayers;
542}
543
544//
545// QgsFileBasedDataItemProvider
546//
547
549{
550 return u"files"_s;
551}
552
557
559{
560 return createDataItemForPathPrivate( path, parentItem, nullptr, Qgis::SublayerQueryFlags(), QVariantMap() );
561}
562
564 const QString &path, QgsDataItem *parentItem, const QStringList &allowedProviders, const QVariantMap &extraUriParts, Qgis::SublayerQueryFlags queryFlags
565)
566{
567 return createDataItemForPathPrivate( path, parentItem, &allowedProviders, queryFlags, extraUriParts );
568}
569
570QgsDataItem *QgsFileBasedDataItemProvider::createDataItemForPathPrivate(
571 const QString &path, QgsDataItem *parentItem, const QStringList *allowedProviders, Qgis::SublayerQueryFlags queryFlags, const QVariantMap &extraUriParts
572)
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( "gpkg"_L1, 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 == "txt"_L1 )
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 == "map"_L1 || suffix == "dat"_L1 )
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 == "dbf"_L1 || suffix == "shx"_L1 )
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 == "xml"_L1 && QgsStyle::isXmlStyleFile( path ) )
610 {
611 return nullptr;
612 }
613 // GDAL 3.1 Shapefile driver directly handles .shp.zip files
614 else if ( path.endsWith( ".shp.zip"_L1, Qt::CaseInsensitive ) && GDALIdentifyDriverEx( path.toUtf8().constData(), GDAL_OF_VECTOR, nullptr, nullptr ) )
615 {
616 suffix = u"shp.zip"_s;
617 }
618
619 // hide blocklisted URIs, such as .aux.xml files
620 if ( QgsProviderRegistry::instance()->uriIsBlocklisted( path ) )
621 return nullptr;
622
623 QgsSettings settings;
624
625 // should we fast scan only?
626 if ( ( settings.value( u"qgis/scanItemsInBrowser2"_s, "extension" ).toString() == "extension"_L1 )
627 || ( 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:1044
@ Directories
Can provides items which corresponds to directories.
Definition qgis.h:1045
@ NotPopulated
Children not yet created.
Definition qgis.h:986
@ Populated
Children created.
Definition qgis.h:988
@ Fertile
Can create children. Even items without this capability may have children, but cannot create them,...
Definition qgis.h:1001
@ RefreshChildrenWhenItemIsRefreshed
When the item is refreshed, all its populated children will also be refreshed in turn.
Definition qgis.h:1007
@ ItemRepresentsFile
Item's path() directly represents a file on disk.
Definition qgis.h:1006
@ Fast
CreateChildren() is fast enough to be run in main thread when refreshing items, most root items (wms,...
Definition qgis.h:1002
@ Archive
File archive type (e.g. vsizip).
Definition qgis.h:6201
QFlags< DataItemProviderCapability > DataItemProviderCapabilities
Capabilities for data item providers.
Definition qgis.h:1058
@ FastScan
Indicates that the provider must scan for sublayers using the fastest possible approach – e....
Definition qgis.h:1510
@ ResolveGeometryType
Attempt to resolve the geometry type for vector sublayers.
Definition qgis.h:1511
@ 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:1067
@ Point
Vector point layer.
Definition qgis.h:1071
@ Plugin
Plugin based layer.
Definition qgis.h:1077
@ Line
Vector line layer.
Definition qgis.h:1072
@ TiledScene
Tiled scene layer.
Definition qgis.h:1081
@ Polygon
Vector polygon layer.
Definition qgis.h:1073
@ Vector
Generic vector layer.
Definition qgis.h:1069
@ VectorTile
Vector tile layer.
Definition qgis.h:1079
@ Mesh
Mesh layer.
Definition qgis.h:1078
@ Raster
Raster layer.
Definition qgis.h:1070
@ TableLayer
Vector non-spatial layer.
Definition qgis.h:1074
@ PointCloud
Point cloud layer.
Definition qgis.h:1080
QFlags< SublayerQueryFlag > SublayerQueryFlags
Sublayer query flags.
Definition qgis.h:1517
@ 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:5853
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.
T value(const QString &dynamicKeyPart=QString()) const
Returns settings value.
static const QgsSettingsEntryStringList * settingsScanItemsFastScanUris
Settings entry for fast scan URIs in browser.
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.