QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgsproviderutils.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsproviderutils.cpp
3  ----------------------------
4  begin : June 2021
5  copyright : (C) 2021 by Nyall Dawson
6  email : nyall dot dawson at gmail dot com
7  ***************************************************************************/
8 /***************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
16 
17 #include "qgsproviderutils.h"
19 
20 #include <QFileInfo>
21 
22 bool QgsProviderUtils::sublayerDetailsAreIncomplete( const QList<QgsProviderSublayerDetails> &details, SublayerCompletenessFlags flags )
23 {
24  const bool ignoreUnknownGeometryTypes = flags & SublayerCompletenessFlag::IgnoreUnknownGeometryType;
25  const bool ignoreUnknownFeatureCount = flags & SublayerCompletenessFlag::IgnoreUnknownFeatureCount;
26 
27  for ( const QgsProviderSublayerDetails &sublayer : details )
28  {
29  switch ( sublayer.type() )
30  {
32  if ( sublayer.skippedContainerScan()
33  || ( !ignoreUnknownGeometryTypes && sublayer.wkbType() == QgsWkbTypes::Unknown )
34  || ( !ignoreUnknownFeatureCount &&
35  ( sublayer.featureCount() == static_cast< long long >( Qgis::FeatureCountState::Uncounted )
36  || sublayer.featureCount() == static_cast< long long >( Qgis::FeatureCountState::UnknownCount ) ) ) )
37  return true;
38  break;
39 
47  break;
48  }
49  }
50 
51  return false;
52 }
53 
54 QString QgsProviderUtils::suggestLayerNameFromFilePath( const QString &path )
55 {
56  const QFileInfo info( path );
57  // default to base name of file
58  QString name = info.completeBaseName();
59 
60  // special handling for .adf files -- use directory as base name, not the unhelpful .adf file name
61  if ( info.suffix().compare( QLatin1String( "adf" ), Qt::CaseInsensitive ) == 0 )
62  {
63  const QString dirName = info.path();
64  name = QFileInfo( dirName ).completeBaseName();
65  }
66  // special handling for ept.json files -- use directory as base name
67  else if ( info.fileName().compare( QLatin1String( "ept.json" ), Qt::CaseInsensitive ) == 0 )
68  {
69  const QString dirName = info.path();
70  name = QFileInfo( dirName ).completeBaseName();
71  }
72 
73  return name;
74 }
Qgis::FeatureCountState::UnknownCount
@ UnknownCount
Provider returned an unknown feature count.
QgsMapLayerType::MeshLayer
@ MeshLayer
Mesh layer. Added in QGIS 3.2.
QgsMapLayerType::VectorLayer
@ VectorLayer
Vector layer.
QgsMapLayerType::AnnotationLayer
@ AnnotationLayer
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
QgsProviderUtils::sublayerDetailsAreIncomplete
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.
Definition: qgsproviderutils.cpp:22
QgsProviderUtils::suggestLayerNameFromFilePath
static QString suggestLayerNameFromFilePath(const QString &path)
Suggests a suitable layer name given only a file path.
Definition: qgsproviderutils.cpp:54
QgsWkbTypes::Unknown
@ Unknown
Definition: qgswkbtypes.h:71
QgsMapLayerType::GroupLayer
@ GroupLayer
Composite group layer. Added in QGIS 3.24.
QgsMapLayerType::RasterLayer
@ RasterLayer
Raster layer.
QgsProviderSublayerDetails
Contains details about a sub layer available from a dataset.
Definition: qgsprovidersublayerdetails.h:44
QgsProviderUtils::SublayerCompletenessFlag::IgnoreUnknownFeatureCount
@ IgnoreUnknownFeatureCount
Indicates that an unknown feature count should not be considered as incomplete.
qgsproviderutils.h
QgsProviderUtils::SublayerCompletenessFlag::IgnoreUnknownGeometryType
@ IgnoreUnknownGeometryType
Indicates that an unknown geometry type should not be considered as incomplete.
QgsMapLayerType::VectorTileLayer
@ VectorTileLayer
Vector tile layer. Added in QGIS 3.14.
Qgis::FeatureCountState::Uncounted
@ Uncounted
Feature count not yet computed.
qgsprovidersublayerdetails.h
QgsMapLayerType::PointCloudLayer
@ PointCloudLayer
Point cloud layer. Added in QGIS 3.18.
QgsMapLayerType::PluginLayer
@ PluginLayer
Plugin based layer.