QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
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 "moc_qgsfilebaseddataitemprovider.cpp"
18#include "qgsdataprovider.h"
19#include "qgsproviderregistry.h"
20#include "qgslogger.h"
21#include "qgssettings.h"
22#include "qgsogrproviderutils.h"
23#include "qgsstyle.h"
24#include "qgsgeopackagedataitems.h"
26#include "qgsfieldsitem.h"
27#include "qgsfielddomainsitem.h"
29#include "qgsproviderutils.h"
30#include "qgsprovidermetadata.h"
31#include "qgsgdalutils.h"
32#include <QUrlQuery>
33
34//
35// QgsProviderSublayerItem
36//
37
39 const QgsProviderSublayerDetails &details, const QString &filePath )
40 : QgsLayerItem( parent, name, filePath.isEmpty() ? details.uri() : filePath, details.uri(), layerTypeFromSublayer( details ), details.providerKey() )
41 , mDetails( details )
42{
43 mToolTip = details.uri();
44
45 // no children, except for vector layers, which will show the fields item
47}
48
50{
51 QVector<QgsDataItem *> children;
52
53 if ( mDetails.type() == Qgis::LayerType::Vector )
54 {
55 // sqlite gets special handling because it delegates to the dedicated spatialite provider
56 if ( mDetails.driverName() == QLatin1String( "SQLite" ) )
57 {
58 children.push_back( new QgsFieldsItem( this,
59 path() + QStringLiteral( "/columns/ " ),
60 QStringLiteral( R"(dbname="%1")" ).arg( parent()->path().replace( '"', QLatin1String( R"(\")" ) ) ),
61 QStringLiteral( "spatialite" ), QString(), name() ) );
62 }
63 else if ( mDetails.providerKey() == QLatin1String( "ogr" ) )
64 {
65 // otherwise we use the default OGR database connection approach, which is the generic way to handle this
66 // for all OGR layer types
67 children.push_back( new QgsFieldsItem( this,
68 path() + QStringLiteral( "/columns/ " ),
69 path(),
70 QStringLiteral( "ogr" ), QString(), name() ) );
71
72 std::unique_ptr<QgsAbstractDatabaseProviderConnection> conn( databaseConnection() );
74 {
75 QString relationError;
76 QList< QgsWeakRelation > relations;
77 try
78 {
79 relations = conn->relationships( QString(), mDetails.name() );
80 }
82 {
83 relationError = ex.what();
84 }
85
86 if ( !relations.empty() || !relationError.isEmpty() )
87 {
88 std::unique_ptr< QgsRelationshipsItem > relationsItem = std::make_unique< QgsRelationshipsItem >( this, mPath + "/relations", conn->uri(), QStringLiteral( "ogr" ), QString(), mDetails.name() );
89 // force this item to appear last by setting a maximum string value for the sort key
90 relationsItem->setSortKey( QString( QChar( 0x11FFFF ) ) );
91 children.append( relationsItem.release() );
92 }
93 }
94 }
95 }
96 return children;
97}
98
103
105{
106 if ( parent() )
107 {
109 return connection;
110 }
111
112 if ( mDetails.providerKey() == QLatin1String( "ogr" ) )
113 {
114 if ( QgsProviderMetadata *md = QgsProviderRegistry::instance()->providerMetadata( QStringLiteral( "ogr" ) ) )
115 {
116 QVariantMap parts;
117 parts.insert( QStringLiteral( "path" ), path() );
118 return static_cast<QgsAbstractDatabaseProviderConnection *>( md->createConnection( md->encodeUri( parts ), {} ) );
119 }
120 }
121
122 return nullptr;
123}
124
125Qgis::BrowserLayerType QgsProviderSublayerItem::layerTypeFromSublayer( const QgsProviderSublayerDetails &sublayer )
126{
127 switch ( sublayer.type() )
128 {
130 {
131 switch ( QgsWkbTypes::geometryType( sublayer.wkbType() ) )
132 {
135
138
141
144
147 }
148
149 break;
150 }
153
156
159
162
165
168
171 break;
172 }
174}
175
177{
178 return mDetails.name();
179}
180
181//
182// QgsFileDataCollectionGroupItem
183//
184QgsFileDataCollectionGroupItem::QgsFileDataCollectionGroupItem( QgsDataItem *parent, const QString &groupName, const QString &path )
185 : QgsDataCollectionItem( parent, groupName, path )
186{
188 mIconName = QStringLiteral( "mIconDbSchema.svg" );
189}
190
192{
193 mSublayers.append( sublayer );
194}
195
197{
198 return true;
199}
200
202{
204 res.reserve( mSublayers.size() );
205
206 for ( const QgsProviderSublayerDetails &sublayer : mSublayers )
207 {
208 res << sublayer.toMimeUri();
209 }
210 return res;
211}
212
213//
214// QgsFileDataCollectionItem
215//
216
217QgsFileDataCollectionItem::QgsFileDataCollectionItem( QgsDataItem *parent, const QString &name, const QString &path, const QList<QgsProviderSublayerDetails> &sublayers, const QVariantMap &extraUriParts )
218 : QgsDataCollectionItem( parent, name, path )
219 , mSublayers( sublayers )
220 , mExtraUriParts( extraUriParts )
221{
224 else
226
228 {
229 mIconName = QStringLiteral( "/mIconZip.svg" );
230 }
231}
232
234{
235 QList< QgsProviderSublayerDetails> sublayers;
237 {
238 QSet< QString > providers;
239 for ( const QgsProviderSublayerDetails &details : std::as_const( mSublayers ) )
240 {
241 providers.insert( details.providerKey() );
242 }
243
244 for ( const QString &provider : std::as_const( providers ) )
245 {
247 {
248 if ( !mExtraUriParts.empty() )
249 {
250 QVariantMap uriParts = metadata->decodeUri( path() );
251 for ( auto it = mExtraUriParts.constBegin(); it != mExtraUriParts.constEnd(); ++it )
252 {
253 uriParts.insert( it.key(), it.value() );
254 }
255 const QString updatedUri = metadata->encodeUri( uriParts );
256
257 sublayers.append( metadata->querySublayers( updatedUri.isEmpty() ? path() : updatedUri, Qgis::SublayerQueryFlag::ResolveGeometryType ) );
258 }
259 else
260 {
261 sublayers.append( metadata->querySublayers( path(), Qgis::SublayerQueryFlag::ResolveGeometryType ) );
262 }
263 }
264 }
265 }
266 else if ( mSublayers.empty() )
267 {
269 }
270 else
271 {
272 sublayers = mSublayers;
273 }
274 // only ever use the initial sublayers for first population -- after that we requery when asked to create children,
275 // or the item won't "refresh" and update its sublayers when the actual file changes
276 mSublayers.clear();
277 // remove the fast flag -- after the first population we need to requery the dataset
279
280 QVector<QgsDataItem *> children;
281 children.reserve( sublayers.size() );
282 QMap< QStringList, QgsFileDataCollectionGroupItem * > groupItems;
283 for ( const QgsProviderSublayerDetails &sublayer : std::as_const( sublayers ) )
284 {
285 QgsProviderSublayerItem *item = new QgsProviderSublayerItem( nullptr, sublayer.name(), sublayer, QString() );
286
287 if ( !sublayer.path().isEmpty() )
288 {
289 QStringList currentPath;
290 QStringList remainingPaths = sublayer.path();
291 QgsFileDataCollectionGroupItem *groupItem = nullptr;
292
293 while ( !remainingPaths.empty() )
294 {
295 currentPath << remainingPaths.takeAt( 0 );
296
297 auto it = groupItems.constFind( currentPath );
298 if ( it == groupItems.constEnd() )
299 {
300 QgsFileDataCollectionGroupItem *newGroupItem = new QgsFileDataCollectionGroupItem( this, currentPath.constLast(), path() + '/' + currentPath.join( ',' ) );
302 groupItems.insert( currentPath, newGroupItem );
303 if ( groupItem )
304 groupItem->addChildItem( newGroupItem );
305 else
306 children.append( newGroupItem );
307 groupItem = newGroupItem;
308 }
309 else
310 {
311 groupItem = it.value();
312 }
313
314 if ( groupItem )
315 groupItem->appendSublayer( sublayer );
316 }
317
318 if ( groupItem )
319 groupItem->addChildItem( item );
320 }
321 else
322 {
323 children.append( item );
324 }
325 }
326
327 std::unique_ptr<QgsAbstractDatabaseProviderConnection> conn( databaseConnection() );
328 if ( conn )
329 {
330 mCachedCapabilities = conn->capabilities();
331 mCachedCapabilities2 = conn->capabilities2();
332 mHasCachedCapabilities = true;
333 }
334 if ( conn && ( mCachedCapabilities & QgsAbstractDatabaseProviderConnection::Capability::ListFieldDomains ) )
335 {
336 QString domainError;
337 QStringList fieldDomains;
338 try
339 {
340 fieldDomains = conn->fieldDomainNames();
341 }
343 {
344 domainError = ex.what();
345 }
346
347 if ( !fieldDomains.empty() || !domainError.isEmpty() )
348 {
349 std::unique_ptr< QgsFieldDomainsItem > domainsItem = std::make_unique< QgsFieldDomainsItem >( this, mPath + "/domains", conn->uri(), QStringLiteral( "ogr" ) );
350 // force this item to appear last by setting a maximum string value for the sort key
351 domainsItem->setSortKey( QString( QChar( 0x10FFFF ) ) );
352 children.append( domainsItem.release() );
353 }
354 }
356 {
357 QString relationError;
358 QList< QgsWeakRelation > relations;
359 try
360 {
361 relations = conn->relationships();
362 }
364 {
365 relationError = ex.what();
366 }
367
368 if ( !relations.empty() || !relationError.isEmpty() )
369 {
370 std::unique_ptr< QgsRelationshipsItem > relationsItem = std::make_unique< QgsRelationshipsItem >( this, mPath + "/relations", conn->uri(), QStringLiteral( "ogr" ) );
371 // force this item to appear last by setting a maximum string value for the sort key
372 relationsItem->setSortKey( QString( QChar( 0x11FFFF ) ) );
373 children.append( relationsItem.release() );
374 }
375 }
376
377 return children;
378}
379
381{
382 return true;
383}
384
386{
387 // if we've previously opened a connection for this item, we can use the previously
388 // determined capababilities to return an accurate answer.
389 if ( mHasCachedCapabilities )
391
392 if ( mHasCachedDropSupport )
393 return mCachedSupportsDrop;
394
395 // otherwise, we are limited to VERY VERY cheap calculations only!!
396 // DO NOT UNDER *****ANY***** CIRCUMSTANCES OPEN DATASETS HERE!!!!
397
398 mHasCachedDropSupport = true;
399 if ( !QFileInfo( path() ).isWritable() )
400 {
401 mCachedSupportsDrop = false;
402 return mCachedSupportsDrop;
403 }
404
405 GDALDriverH hDriver = GDALIdentifyDriverEx( path().toUtf8().constData(), GDAL_OF_VECTOR, nullptr, nullptr );
406 if ( !hDriver )
407 {
408 mCachedSupportsDrop = false;
409 return mCachedSupportsDrop;
410 }
411
412 // explicitly blocklist some drivers which we don't want to expose drop support for
413 const QString driverName = GDALGetDriverShortName( hDriver );
414 if ( driverName == QLatin1String( "PDF" )
415 || driverName == QLatin1String( "DXF" ) )
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 = QStringLiteral( "collection" );
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( QStringLiteral( "GDALIdentifyDriverEx error # %1 : %2 on %3" ).arg( CPLGetLastErrorNo() ).arg( CPLGetLastErrorMsg() ).arg( path() ), 2 );
466 return nullptr;
467 }
468
469 const QString driverName = GDALGetDriverShortName( hDriver );
470 if ( driverName == QLatin1String( "PDF" )
471 || driverName == QLatin1String( "DXF" ) )
472 {
473 // unwanted drivers -- it's slow to create connections for these, and we don't really want
474 // to expose database capabilities for them (even though they kind of are database formats)
475 return nullptr;
476 }
477
479 if ( driverName == QLatin1String( "SQLite" ) )
480 {
481 // sqlite gets special handling, as we delegate to the native spatialite provider
482 if ( QgsProviderMetadata *md = QgsProviderRegistry::instance()->providerMetadata( QStringLiteral( "spatialite" ) ) )
483 {
485 uri.setDatabase( path( ) );
486 conn = static_cast<QgsAbstractDatabaseProviderConnection *>( md->createConnection( uri.uri(), {} ) );
487 }
488 }
489 else
490 {
491 // for all other vector types we use the generic OGR provider
492 if ( QgsProviderMetadata *md = QgsProviderRegistry::instance()->providerMetadata( QStringLiteral( "ogr" ) ) )
493 {
494 QVariantMap parts;
495 parts.insert( QStringLiteral( "path" ), path() );
496 conn = static_cast<QgsAbstractDatabaseProviderConnection *>( md->createConnection( md->encodeUri( parts ), {} ) );
497 }
498 }
499
500 if ( conn )
501 {
502 mCachedCapabilities = conn->capabilities();
503 mCachedCapabilities2 = conn->capabilities2();
504 mHasCachedCapabilities = true;
505 }
506
507 return conn;
508}
509
511{
512 if ( mHasCachedCapabilities )
513 return mCachedCapabilities;
514
515 std::unique_ptr<QgsAbstractDatabaseProviderConnection> conn( databaseConnection() );
516 if ( conn )
517 {
518 mCachedCapabilities = conn->capabilities();
519 mCachedCapabilities2 = conn->capabilities2();
520 mHasCachedCapabilities = true;
521 }
522 return mCachedCapabilities;
523}
524
526{
527 if ( mHasCachedCapabilities )
528 return mCachedCapabilities2;
529
530 std::unique_ptr<QgsAbstractDatabaseProviderConnection> conn( databaseConnection() );
531 if ( conn )
532 {
533 mCachedCapabilities = conn->capabilities();
534 mCachedCapabilities2 = conn->capabilities2();
535 mHasCachedCapabilities = true;
536 }
537 return mCachedCapabilities2;
538}
539
540QList<QgsProviderSublayerDetails> QgsFileDataCollectionItem::sublayers() const
541{
542 return mSublayers;
543}
544
545//
546// QgsFileBasedDataItemProvider
547//
548
550{
551 return QStringLiteral( "files" );
552}
553
558
560{
561 return createDataItemForPathPrivate( path, parentItem, nullptr, Qgis::SublayerQueryFlags(), QVariantMap() );
562}
563
564QgsDataItem *QgsFileBasedDataItemProvider::createLayerItemForPath( const QString &path, QgsDataItem *parentItem, const QStringList &allowedProviders, const QVariantMap &extraUriParts, Qgis::SublayerQueryFlags queryFlags )
565{
566 return createDataItemForPathPrivate( path, parentItem, &allowedProviders, queryFlags, extraUriParts );
567}
568
569QgsDataItem *QgsFileBasedDataItemProvider::createDataItemForPathPrivate( const QString &path, QgsDataItem *parentItem, const QStringList *allowedProviders, Qgis::SublayerQueryFlags queryFlags, const QVariantMap &extraUriParts )
570{
571 if ( path.isEmpty() )
572 return nullptr;
573
574 const QFileInfo info( path );
575 QString suffix = info.suffix().toLower();
576 const QString name = info.fileName();
577
578 // special handling for some suffixes
579 if ( suffix.compare( QLatin1String( "gpkg" ), Qt::CaseInsensitive ) == 0 )
580 {
581 // Geopackage is special -- it gets a dedicated collection item type
582 QgsGeoPackageCollectionItem *item = new QgsGeoPackageCollectionItem( parentItem, name, path );
583 item->setCapabilities( item->capabilities2() | Qgis::BrowserItemCapability::ItemRepresentsFile );
584 return item;
585 }
586 else if ( suffix == QLatin1String( "txt" ) )
587 {
588 // never ever show .txt files as datasets in browser -- they are only used for geospatial data in extremely rare cases
589 // and are predominantly just noise in the browser
590 return nullptr;
591 }
592 // If a .tab exists, then the corresponding .map/.dat is very likely a
593 // side-car file of the .tab
594 else if ( suffix == QLatin1String( "map" ) || suffix == QLatin1String( "dat" ) )
595 {
596 if ( QFile::exists( QDir( info.path() ).filePath( info.baseName() + ".tab" ) ) || QFile::exists( QDir( info.path() ).filePath( info.baseName() + ".TAB" ) ) )
597 return nullptr;
598 }
599 // .dbf and .shx should only appear if .shp is not present
600 else if ( suffix == QLatin1String( "dbf" ) || suffix == QLatin1String( "shx" ) )
601 {
602 if ( QFile::exists( QDir( info.path() ).filePath( info.baseName() + ".shp" ) ) || QFile::exists( QDir( info.path() ).filePath( info.baseName() + ".SHP" ) ) )
603 return nullptr;
604 }
605 // skip QGIS style xml files
606 else if ( suffix == QLatin1String( "xml" ) && QgsStyle::isXmlStyleFile( path ) )
607 {
608 return nullptr;
609 }
610 // GDAL 3.1 Shapefile driver directly handles .shp.zip files
611 else if ( path.endsWith( QLatin1String( ".shp.zip" ), Qt::CaseInsensitive ) &&
612 GDALIdentifyDriverEx( path.toUtf8().constData(), GDAL_OF_VECTOR, nullptr, nullptr ) )
613 {
614 suffix = QStringLiteral( "shp.zip" );
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( QStringLiteral( "qgis/scanItemsInBrowser2" ),
625 "extension" ).toString() == QLatin1String( "extension" ) ) ||
626 ( parentItem && settings.value( QStringLiteral( "qgis/scanItemsFastScanUris" ),
627 QStringList() ).toStringList().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
664 )
665 {
666 QgsProviderSublayerItem *item = new QgsProviderSublayerItem( parentItem, name, sublayers.at( 0 ), path );
668 return item;
669 }
670 else if ( !sublayers.empty() )
671 {
672 QgsFileDataCollectionItem *item = new QgsFileDataCollectionItem( parentItem, name, path, sublayers, extraUriParts );
674 return item;
675 }
676 else
677 {
678 return nullptr;
679 }
680}
681
683{
684 QFileInfo info( path );
685 QString suffix = info.suffix().toLower();
686
687 QStringList dirExtensions = QgsOgrProviderUtils::directoryExtensions();
688 return dirExtensions.contains( suffix );
689}
@ 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.