QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
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#include "qgsdataprovider.h"
18#include "qgsproviderregistry.h"
19#include "qgslogger.h"
20#include "qgssettings.h"
21#include "qgsogrproviderutils.h"
22#include "qgsstyle.h"
23#include "qgsgeopackagedataitems.h"
25#include "qgsfieldsitem.h"
26#include "qgsfielddomainsitem.h"
28#include "qgsproviderutils.h"
29#include "qgsprovidermetadata.h"
30#include "qgsgdalutils.h"
31#include <QUrlQuery>
32
33//
34// QgsProviderSublayerItem
35//
36
38 const QgsProviderSublayerDetails &details, const QString &filePath )
39 : QgsLayerItem( parent, name, filePath.isEmpty() ? details.uri() : filePath, details.uri(), layerTypeFromSublayer( details ), details.providerKey() )
40 , mDetails( details )
41{
42 mToolTip = details.uri();
43
44 // no children, except for vector layers, which will show the fields item
46}
47
49{
50 QVector<QgsDataItem *> children;
51
52 if ( mDetails.type() == Qgis::LayerType::Vector )
53 {
54 // sqlite gets special handling because it delegates to the dedicated spatialite provider
55 if ( mDetails.driverName() == QLatin1String( "SQLite" ) )
56 {
57 children.push_back( new QgsFieldsItem( this,
58 path() + QStringLiteral( "/columns/ " ),
59 QStringLiteral( R"(dbname="%1")" ).arg( parent()->path().replace( '"', QLatin1String( R"(\")" ) ) ),
60 QStringLiteral( "spatialite" ), QString(), name() ) );
61 }
62 else if ( mDetails.providerKey() == QLatin1String( "ogr" ) )
63 {
64 // otherwise we use the default OGR database connection approach, which is the generic way to handle this
65 // for all OGR layer types
66 children.push_back( new QgsFieldsItem( this,
67 path() + QStringLiteral( "/columns/ " ),
68 path(),
69 QStringLiteral( "ogr" ), 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 std::unique_ptr< QgsRelationshipsItem > relationsItem = std::make_unique< QgsRelationshipsItem >( this, mPath + "/relations", conn->uri(), QStringLiteral( "ogr" ), 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() == QLatin1String( "ogr" ) )
112 {
113 if ( QgsProviderMetadata *md = QgsProviderRegistry::instance()->providerMetadata( QStringLiteral( "ogr" ) ) )
114 {
115 QVariantMap parts;
116 parts.insert( QStringLiteral( "path" ), 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//
183QgsFileDataCollectionGroupItem::QgsFileDataCollectionGroupItem( QgsDataItem *parent, const QString &groupName, const QString &path )
184 : QgsDataCollectionItem( parent, groupName, path )
185{
187 mIconName = QStringLiteral( "mIconDbSchema.svg" );
188}
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 )
217 : QgsDataCollectionItem( parent, name, path )
218 , mSublayers( sublayers )
219 , mExtraUriParts( extraUriParts )
220{
223 else
225
227 {
228 mIconName = QStringLiteral( "/mIconZip.svg" );
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 {
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 std::unique_ptr< QgsFieldDomainsItem > domainsItem = std::make_unique< QgsFieldDomainsItem >( this, mPath + "/domains", conn->uri(), QStringLiteral( "ogr" ) );
349 // force this item to appear last by setting a maximum string value for the sort key
350 domainsItem->setSortKey( QString( QChar( 0x10FFFF ) ) );
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 std::unique_ptr< QgsRelationshipsItem > relationsItem = std::make_unique< QgsRelationshipsItem >( this, mPath + "/relations", conn->uri(), QStringLiteral( "ogr" ) );
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 == QLatin1String( "PDF" )
414 || driverName == QLatin1String( "DXF" ) )
415 {
416 mCachedSupportsDrop = false;
417 return mCachedSupportsDrop;
418 }
419
420 // DO NOT UNDER *****ANY***** CIRCUMSTANCES OPEN DATASETS HERE!!!!
421#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3,4,0)
422 const bool isSingleTableDriver = !GDALGetMetadataItem( hDriver, GDAL_DCAP_MULTIPLE_VECTOR_LAYERS, nullptr );
423#else
424 const QFileInfo pathInfo( path() );
425 const QString suffix = pathInfo.suffix().toLower();
426 const bool isSingleTableDriver = !QgsGdalUtils::multiLayerFileExtensions().contains( suffix );
427#endif
428
429 if ( isSingleTableDriver )
430 {
431 mCachedSupportsDrop = false;
432 return mCachedSupportsDrop;
433 }
434
435 // DO NOT UNDER *****ANY***** CIRCUMSTANCES OPEN DATASETS HERE!!!!
436 mCachedSupportsDrop = true;
437 return mCachedSupportsDrop;
438}
439
441{
442 QgsMimeDataUtils::Uri collectionUri;
443 collectionUri.uri = path();
444 collectionUri.layerType = QStringLiteral( "collection" );
445 collectionUri.filePath = path();
446 return { collectionUri };
447}
448
450{
451 // test that file is valid with OGR
452 if ( OGRGetDriverCount() == 0 )
453 {
454 OGRRegisterAll();
455 }
456 // do not print errors, but write to debug
457 CPLPushErrorHandler( CPLQuietErrorHandler );
458 CPLErrorReset();
459 GDALDriverH hDriver = GDALIdentifyDriverEx( path().toUtf8().constData(), GDAL_OF_VECTOR, nullptr, nullptr );
460 CPLPopErrorHandler();
461
462 if ( ! hDriver )
463 {
464 QgsDebugMsgLevel( QStringLiteral( "GDALIdentifyDriverEx error # %1 : %2 on %3" ).arg( CPLGetLastErrorNo() ).arg( CPLGetLastErrorMsg() ).arg( path() ), 2 );
465 return nullptr;
466 }
467
468 const QString driverName = GDALGetDriverShortName( hDriver );
469 if ( driverName == QLatin1String( "PDF" )
470 || driverName == QLatin1String( "DXF" ) )
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 == QLatin1String( "SQLite" ) )
479 {
480 // sqlite gets special handling, as we delegate to the native spatialite provider
481 if ( QgsProviderMetadata *md = QgsProviderRegistry::instance()->providerMetadata( QStringLiteral( "spatialite" ) ) )
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( QStringLiteral( "ogr" ) ) )
492 {
493 QVariantMap parts;
494 parts.insert( QStringLiteral( "path" ), 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 QStringLiteral( "files" );
551}
552
557
559{
560 return createDataItemForPathPrivate( path, parentItem, nullptr, Qgis::SublayerQueryFlags(), QVariantMap() );
561}
562
563QgsDataItem *QgsFileBasedDataItemProvider::createLayerItemForPath( const QString &path, QgsDataItem *parentItem, const QStringList &allowedProviders, const QVariantMap &extraUriParts, Qgis::SublayerQueryFlags queryFlags )
564{
565 return createDataItemForPathPrivate( path, parentItem, &allowedProviders, queryFlags, extraUriParts );
566}
567
568QgsDataItem *QgsFileBasedDataItemProvider::createDataItemForPathPrivate( const QString &path, QgsDataItem *parentItem, const QStringList *allowedProviders, Qgis::SublayerQueryFlags queryFlags, const QVariantMap &extraUriParts )
569{
570 if ( path.isEmpty() )
571 return nullptr;
572
573 const QFileInfo info( path );
574 QString suffix = info.suffix().toLower();
575 const QString name = info.fileName();
576
577 // special handling for some suffixes
578 if ( suffix.compare( QLatin1String( "gpkg" ), Qt::CaseInsensitive ) == 0 )
579 {
580 // Geopackage is special -- it gets a dedicated collection item type
581 QgsGeoPackageCollectionItem *item = new QgsGeoPackageCollectionItem( parentItem, name, path );
582 item->setCapabilities( item->capabilities2() | Qgis::BrowserItemCapability::ItemRepresentsFile );
583 return item;
584 }
585 else if ( suffix == QLatin1String( "txt" ) )
586 {
587 // never ever show .txt files as datasets in browser -- they are only used for geospatial data in extremely rare cases
588 // and are predominantly just noise in the browser
589 return nullptr;
590 }
591 // If a .tab exists, then the corresponding .map/.dat is very likely a
592 // side-car file of the .tab
593 else if ( suffix == QLatin1String( "map" ) || suffix == QLatin1String( "dat" ) )
594 {
595 if ( QFile::exists( QDir( info.path() ).filePath( info.baseName() + ".tab" ) ) || QFile::exists( QDir( info.path() ).filePath( info.baseName() + ".TAB" ) ) )
596 return nullptr;
597 }
598 // .dbf and .shx should only appear if .shp is not present
599 else if ( suffix == QLatin1String( "dbf" ) || suffix == QLatin1String( "shx" ) )
600 {
601 if ( QFile::exists( QDir( info.path() ).filePath( info.baseName() + ".shp" ) ) || QFile::exists( QDir( info.path() ).filePath( info.baseName() + ".SHP" ) ) )
602 return nullptr;
603 }
604 // skip QGIS style xml files
605 else if ( suffix == QLatin1String( "xml" ) && QgsStyle::isXmlStyleFile( path ) )
606 {
607 return nullptr;
608 }
609 // GDAL 3.1 Shapefile driver directly handles .shp.zip files
610 else if ( path.endsWith( QLatin1String( ".shp.zip" ), Qt::CaseInsensitive ) &&
611 GDALIdentifyDriverEx( path.toUtf8().constData(), GDAL_OF_VECTOR, nullptr, nullptr ) )
612 {
613 suffix = QStringLiteral( "shp.zip" );
614 }
615
616 // hide blocklisted URIs, such as .aux.xml files
617 if ( QgsProviderRegistry::instance()->uriIsBlocklisted( path ) )
618 return nullptr;
619
620 QgsSettings settings;
621
622 // should we fast scan only?
623 if ( ( settings.value( QStringLiteral( "qgis/scanItemsInBrowser2" ),
624 "extension" ).toString() == QLatin1String( "extension" ) ) ||
625 ( parentItem && settings.value( QStringLiteral( "qgis/scanItemsFastScanUris" ),
626 QStringList() ).toStringList().contains( parentItem->path() ) ) )
627 {
629 }
630
631 QList<QgsProviderSublayerDetails> sublayers;
632 if ( !allowedProviders )
633 {
634 sublayers = QgsProviderRegistry::instance()->querySublayers( path, queryFlags );
635 }
636 else
637 {
638 for ( const QString &provider : *allowedProviders )
639 {
640 if ( QgsProviderMetadata *metadata = QgsProviderRegistry::instance()->providerMetadata( provider ) )
641 {
642 if ( !extraUriParts.empty() )
643 {
644 QVariantMap uriParts = metadata->decodeUri( path );
645 for ( auto it = extraUriParts.constBegin(); it != extraUriParts.constEnd(); ++it )
646 {
647 uriParts.insert( it.key(), it.value() );
648 }
649
650 sublayers.append( metadata->querySublayers( metadata->encodeUri( uriParts ), queryFlags ) );
651 }
652 else
653 {
654 sublayers.append( metadata->querySublayers( path, queryFlags ) );
655 }
656 }
657 }
658 }
659
660 if ( sublayers.size() == 1
663 )
664 {
665 QgsProviderSublayerItem *item = new QgsProviderSublayerItem( parentItem, name, sublayers.at( 0 ), path );
667 return item;
668 }
669 else if ( !sublayers.empty() )
670 {
671 QgsFileDataCollectionItem *item = new QgsFileDataCollectionItem( parentItem, name, path, sublayers, extraUriParts );
673 return item;
674 }
675 else
676 {
677 return nullptr;
678 }
679}
680
682{
683 QFileInfo info( path );
684 QString suffix = info.suffix().toLower();
685
686 QStringList dirExtensions = QgsOgrProviderUtils::directoryExtensions();
687 return dirExtensions.contains( suffix );
688}
@ Files
Can provides items which corresponds to files.
@ Directories
Can provides items which corresponds to directories.
@ NotPopulated
Children not yet created.
@ Populated
Children created.
@ Fertile
Can create children. Even items without this capability may have children, but cannot create them,...
@ RefreshChildrenWhenItemIsRefreshed
When the item is refreshed, all its populated children will also be refreshed in turn.
@ ItemRepresentsFile
Item's path() directly represents a file on disk.
@ Fast
CreateChildren() is fast enough to be run in main thread when refreshing items, most root items (wms,...
@ Archive
File archive type (e.g. vsizip)
QFlags< DataItemProviderCapability > DataItemProviderCapabilities
Capabilities for data item providers.
Definition qgis.h:926
@ FastScan
Indicates that the provider must scan for sublayers using the fastest possible approach – e....
@ ResolveGeometryType
Attempt to resolve the geometry type for vector sublayers.
@ Polygon
Polygons.
@ Unknown
Unknown types.
@ Null
No geometry.
BrowserLayerType
Browser item layer types.
Definition qgis.h:935
@ Point
Vector point layer.
@ Plugin
Plugin based layer.
@ Line
Vector line layer.
@ TiledScene
Tiled scene layer.
@ Polygon
Vector polygon layer.
@ Vector
Generic vector layer.
@ VectorTile
Vector tile layer.
@ Raster
Raster layer.
@ TableLayer
Vector non-spatial layer.
@ PointCloud
Point cloud layer.
QFlags< SublayerQueryFlag > SublayerQueryFlags
Sublayer query flags.
Definition qgis.h:1309
@ Group
Composite group layer. Added in QGIS 3.24.
@ Plugin
Plugin based layer.
@ TiledScene
Tiled scene layer. Added in QGIS 3.34.
@ Annotation
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
@ Vector
Vector layer.
@ VectorTile
Vector tile layer. Added in QGIS 3.14.
@ Mesh
Mesh layer. Added in QGIS 3.2.
@ Raster
Raster layer.
@ PointCloud
Point cloud layer. Added in QGIS 3.18.
QFlags< DatabaseProviderConnectionCapability2 > DatabaseProviderConnectionCapabilities2
Definition qgis.h:5015
The QgsAbstractDatabaseProviderConnection class provides common functionality for DB based connection...
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.
A Collection: logical collection of layers or subcollections, e.g.
Base class for all items in the model.
Definition qgsdataitem.h:46
QString mToolTip
QString mPath
QVector< QgsDataItem * > children() const
Qgis::BrowserItemCapabilities mCapabilities
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.
virtual Qgis::BrowserItemCapabilities capabilities2() const
Returns the capabilities for the data item.
Class for storing the component parts of a RDBMS 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 collection of field items with some internal logic to retrieve the fields and a the vector layer in...
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.
A data collection item for file based data collections (e.g.
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 ...
Item that represents a layer that can be opened with one of the providers.
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.
QgsProviderMetadata * providerMetadata(const QString &providerKey) const
Returns metadata of the provider or nullptr if not found.
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 driverName() const
Returns the layer's driver name.
QString providerKey() const
Returns the associated data provider key.
QString name() const
Returns the layer's name.
A generic data item for file based layers.
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.
This class is a composition of two QSettings instances:
Definition qgssettings.h:64
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:39
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.