Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add QgsProviderUtils with a method for determining whether a list
of sublayer details is incomplete and requires a more in-depth scan
- Loading branch information
1 parent
b742b8f
commit 1355b39
Showing
7 changed files
with
195 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
python/core/auto_generated/providers/qgsproviderutils.sip.in
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/core/providers/qgsproviderutils.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ | ||
|
||
|
||
|
||
class QgsProviderUtils | ||
{ | ||
%Docstring(signature="appended") | ||
|
||
Contains utility functions for working with data providers. | ||
|
||
.. versionadded:: 3.22 | ||
%End | ||
|
||
%TypeHeaderCode | ||
#include "qgsproviderutils.h" | ||
%End | ||
public: | ||
|
||
static bool sublayerDetailsAreIncomplete( const QList< QgsProviderSublayerDetails > &details ); | ||
%Docstring | ||
Returns ``True`` if the sublayer ``details`` are incomplete, and require a more in-depth | ||
scan. | ||
|
||
For instance, if the details contain any vector sublayers with unknown geometry types | ||
then a query with the Qgis.SublayerQueryFlag.ResolveGeometryType flag is required. | ||
%End | ||
|
||
}; | ||
|
||
|
||
|
||
|
||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/core/providers/qgsproviderutils.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/*************************************************************************** | ||
qgsproviderutils.cpp | ||
---------------------------- | ||
begin : June 2021 | ||
copyright : (C) 2021 by Nyall Dawson | ||
email : nyall dot dawson at gmail dot com | ||
***************************************************************************/ | ||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgsproviderutils.h" | ||
#include "qgsprovidersublayerdetails.h" | ||
|
||
bool QgsProviderUtils::sublayerDetailsAreIncomplete( const QList<QgsProviderSublayerDetails> &details ) | ||
{ | ||
for ( const QgsProviderSublayerDetails &sublayer : details ) | ||
{ | ||
switch ( sublayer.type() ) | ||
{ | ||
case QgsMapLayerType::VectorLayer: | ||
if ( sublayer.wkbType() == QgsWkbTypes::Unknown ) | ||
return true; | ||
break; | ||
|
||
case QgsMapLayerType::RasterLayer: | ||
case QgsMapLayerType::PluginLayer: | ||
case QgsMapLayerType::MeshLayer: | ||
case QgsMapLayerType::VectorTileLayer: | ||
case QgsMapLayerType::AnnotationLayer: | ||
case QgsMapLayerType::PointCloudLayer: | ||
break; | ||
} | ||
} | ||
|
||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/*************************************************************************** | ||
qgsproviderutils.h | ||
---------------------------- | ||
begin : June 2021 | ||
copyright : (C) 2021 by Nyall Dawson | ||
email : nyall dot dawson at gmail dot com | ||
***************************************************************************/ | ||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
#ifndef QGSPROVIDERUTILS_H | ||
#define QGSPROVIDERUTILS_H | ||
|
||
#include "qgis_core.h" | ||
#include "qgis.h" | ||
#include <QList> | ||
|
||
class QgsProviderSublayerDetails; | ||
|
||
/** | ||
* \class QgsProviderUtils | ||
* \ingroup core | ||
* | ||
* \brief Contains utility functions for working with data providers. | ||
* | ||
* \since QGIS 3.22 | ||
*/ | ||
class CORE_EXPORT QgsProviderUtils | ||
{ | ||
public: | ||
|
||
/** | ||
* Returns TRUE if the sublayer \a details are incomplete, and require a more in-depth | ||
* scan. | ||
* | ||
* For instance, if the details contain any vector sublayers with unknown geometry types | ||
* then a query with the Qgis::SublayerQueryFlag::ResolveGeometryType flag is required. | ||
*/ | ||
static bool sublayerDetailsAreIncomplete( const QList< QgsProviderSublayerDetails > &details ); | ||
|
||
}; | ||
|
||
#endif //QGSPROVIDERUTILS_H | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# -*- coding: utf-8 -*- | ||
"""QGIS Unit tests for QgsProviderUtils. | ||
.. note:: This program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 2 of the License, or | ||
(at your option) any later version. | ||
""" | ||
__author__ = 'Nyall Dawson' | ||
__date__ = '30/06/2021' | ||
__copyright__ = 'Copyright 2021, The QGIS Project' | ||
|
||
from qgis.core import ( | ||
Qgis, | ||
QgsWkbTypes, | ||
QgsProviderRegistry, | ||
QgsProviderUtils | ||
) | ||
|
||
from qgis.testing import ( | ||
unittest, | ||
start_app | ||
) | ||
from utilities import unitTestDataPath | ||
|
||
app = start_app() | ||
|
||
|
||
class TestQgsProviderUtils(unittest.TestCase): | ||
|
||
def test_sublayerDetailsAreIncomplete(self): | ||
""" | ||
Test sublayerDetailsAreIncomplete | ||
""" | ||
uri = unitTestDataPath() + '/mixed_types.TAB' | ||
|
||
# surface scan only | ||
sublayers = QgsProviderRegistry.instance().querySublayers(uri) | ||
self.assertEqual(len(sublayers), 1) | ||
self.assertEqual(sublayers[0].wkbType(), QgsWkbTypes.Unknown) | ||
|
||
# need to resolve geometry types for complete details about this uri! | ||
self.assertTrue(QgsProviderUtils.sublayerDetailsAreIncomplete(sublayers)) | ||
|
||
# retry with retrieving geometry types | ||
sublayers = QgsProviderRegistry.instance().querySublayers(uri, Qgis.SublayerQueryFlag.ResolveGeometryType) | ||
# now we have all the details | ||
self.assertEqual(len(sublayers), 3) | ||
self.assertFalse(QgsProviderUtils.sublayerDetailsAreIncomplete(sublayers)) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |