QGIS API Documentation 3.38.0-Grenoble (exported)
Loading...
Searching...
No Matches
qgsprovidersublayertask.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsprovidersublayertask.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 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
19#include "qgsfeedback.h"
20#include "qgsprovidermetadata.h"
21#include "qgsproviderregistry.h"
23#include "qgsreadwritelocker.h"
24
25QgsProviderSublayerTask::QgsProviderSublayerTask( const QString &uri, bool includeSystemTables )
26 : QgsTask( tr( "Retrieving layers" ), QgsTask::CanCancel | QgsTask::CancelWithoutPrompt | QgsTask::Silent )
27 , mUri( uri )
28 , mIncludeSystemTables( includeSystemTables )
29{
30}
31
32QgsProviderSublayerTask::QgsProviderSublayerTask( const QString &uri, const QString &providerKey, bool includeSystemTables )
33 : QgsTask( tr( "Retrieving layers" ), QgsTask::CanCancel | QgsTask::CancelWithoutPrompt | QgsTask::Silent )
34 , mUri( uri )
35 , mProviderKey( providerKey )
36 , mIncludeSystemTables( includeSystemTables )
37{
38}
39
40QList<QgsProviderSublayerDetails> QgsProviderSublayerTask::results() const
41{
42 const QgsReadWriteLocker locker( mLock, QgsReadWriteLocker::Read );
43 return mResults;
44}
45
47
49{
50 mFeedback = std::make_unique< QgsFeedback >();
51
53 if ( mIncludeSystemTables )
55
56 QList<QgsProviderSublayerDetails> res;
57 if ( mProviderKey.isEmpty() )
58 res = QgsProviderRegistry::instance()->querySublayers( mUri, flags, mFeedback.get() );
59 else
60 {
62 if ( provider )
63 res = provider->querySublayers( mUri, flags, mFeedback.get() );
64 }
65
66 const QgsReadWriteLocker locker( mLock, QgsReadWriteLocker::Write );
67 mResults = res;
68
69 return true;
70}
71
73{
74 if ( mFeedback )
75 mFeedback->cancel();
76
78}
@ IncludeSystemTables
Include system or internal tables (these are not included by default)
@ CountFeatures
Count features in vector sublayers.
@ ResolveGeometryType
Attempt to resolve the geometry type for vector sublayers.
QFlags< SublayerQueryFlag > SublayerQueryFlags
Sublayer query flags.
Definition qgis.h:1129
Holds data provider key, description, and associated shared library file or function pointer informat...
virtual 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...
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.
QList< QgsProviderSublayerDetails > results() const
Returns the sublayer details as calculated by the task.
void cancel() override
Notifies the task that it should terminate.
QgsProviderSublayerTask(const QString &uri, bool includeSystemTables=false)
Constructor for QgsProviderSublayerTask, which retrieves sublayer details for the specified uri.
~QgsProviderSublayerTask() override
bool run() override
Performs the task's operation.
The QgsReadWriteLocker class is a convenience class that simplifies locking and unlocking QReadWriteL...
@ Write
Lock for write.
Abstract base class for long running background tasks.
Flags flags() const
Returns the flags associated with the task.
virtual void cancel()
Notifies the task that it should terminate.