QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
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 "qgsproviderregistry.h"
22#include "qgsreadwritelocker.h"
23
24QgsProviderSublayerTask::QgsProviderSublayerTask( const QString &uri, bool includeSystemTables )
25 : QgsTask( tr( "Retrieving layers" ), QgsTask::CanCancel | QgsTask::CancelWithoutPrompt | QgsTask::Silent )
26 , mUri( uri )
27 , mIncludeSystemTables( includeSystemTables )
28{
29}
30
31QList<QgsProviderSublayerDetails> QgsProviderSublayerTask::results() const
32{
33 const QgsReadWriteLocker locker( mLock, QgsReadWriteLocker::Read );
34 return mResults;
35}
36
38
40{
41 mFeedback = std::make_unique< QgsFeedback >();
42
44 if ( mIncludeSystemTables )
46
47 const QList<QgsProviderSublayerDetails> res = QgsProviderRegistry::instance()->querySublayers( mUri, flags, mFeedback.get() );
48
49 const QgsReadWriteLocker locker( mLock, QgsReadWriteLocker::Write );
50 mResults = res;
51
52 return true;
53}
54
56{
57 if ( mFeedback )
58 mFeedback->cancel();
59
61}
@ 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.
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.
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.
@ Read
Lock for read.
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.