QGIS API Documentation 3.41.0-Master (3440c17df1d)
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 "moc_qgsprovidersublayertask.cpp"
20#include "qgsfeedback.h"
21#include "qgsprovidermetadata.h"
22#include "qgsproviderregistry.h"
24#include "qgsreadwritelocker.h"
25
26QgsProviderSublayerTask::QgsProviderSublayerTask( const QString &uri, bool includeSystemTables )
27 : QgsTask( tr( "Retrieving layers" ), QgsTask::CanCancel | QgsTask::CancelWithoutPrompt | QgsTask::Silent )
28 , mUri( uri )
29 , mIncludeSystemTables( includeSystemTables )
30{
31}
32
33QgsProviderSublayerTask::QgsProviderSublayerTask( const QString &uri, const QString &providerKey, bool includeSystemTables )
34 : QgsTask( tr( "Retrieving layers" ), QgsTask::CanCancel | QgsTask::CancelWithoutPrompt | QgsTask::Silent )
35 , mUri( uri )
36 , mProviderKey( providerKey )
37 , mIncludeSystemTables( includeSystemTables )
38{
39}
40
41QList<QgsProviderSublayerDetails> QgsProviderSublayerTask::results() const
42{
43 const QgsReadWriteLocker locker( mLock, QgsReadWriteLocker::Read );
44 return mResults;
45}
46
48
50{
51 mFeedback = std::make_unique< QgsFeedback >();
52
54 if ( mIncludeSystemTables )
56
57 QList<QgsProviderSublayerDetails> res;
58 if ( mProviderKey.isEmpty() )
59 res = QgsProviderRegistry::instance()->querySublayers( mUri, flags, mFeedback.get() );
60 else
61 {
63 if ( provider )
64 res = provider->querySublayers( mUri, flags, mFeedback.get() );
65 }
66
67 const QgsReadWriteLocker locker( mLock, QgsReadWriteLocker::Write );
68 mResults = res;
69
70 return true;
71}
72
74{
75 if ( mFeedback )
76 mFeedback->cancel();
77
79}
@ 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:1309
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.