QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 
24 QgsProviderSublayerTask::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 
31 QList<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 }
QgsProviderSublayerTask::run
bool run() override
Performs the task's operation.
Definition: qgsprovidersublayertask.cpp:39
qgsreadwritelocker.h
QgsReadWriteLocker::Read
@ Read
Lock for read.
Definition: qgsreadwritelocker.h:75
QgsProviderRegistry::querySublayers
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...
Definition: qgsproviderregistry.cpp:958
QgsProviderSublayerTask::~QgsProviderSublayerTask
~QgsProviderSublayerTask() override
QgsProviderSublayerTask::QgsProviderSublayerTask
QgsProviderSublayerTask(const QString &uri, bool includeSystemTables=false)
Constructor for QgsProviderSublayerTask, which retrieves sublayer details for the specified uri.
Definition: qgsprovidersublayertask.cpp:24
QgsReadWriteLocker
The QgsReadWriteLocker class is a convenience class that simplifies locking and unlocking QReadWriteL...
Definition: qgsreadwritelocker.h:40
QgsProviderSublayerTask::cancel
void cancel() override
Notifies the task that it should terminate.
Definition: qgsprovidersublayertask.cpp:55
QgsTask::cancel
virtual void cancel()
Notifies the task that it should terminate.
Definition: qgstaskmanager.cpp:91
qgsproviderregistry.h
QgsReadWriteLocker::Write
@ Write
Lock for write.
Definition: qgsreadwritelocker.h:76
Qgis::SublayerQueryFlag::CountFeatures
@ CountFeatures
Count features in vector sublayers.
QgsProviderSublayerTask::results
QList< QgsProviderSublayerDetails > results() const
Returns the sublayer details as calculated by the task.
Definition: qgsprovidersublayertask.cpp:31
qgsprovidersublayertask.h
Qgis::SublayerQueryFlag::ResolveGeometryType
@ ResolveGeometryType
Attempt to resolve the geometry type for vector sublayers.
qgsprovidersublayerdetails.h
QgsTask::flags
Flags flags() const
Returns the flags associated with the task.
Definition: qgstaskmanager.h:94
qgsfeedback.h
QgsProviderRegistry::instance
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
Definition: qgsproviderregistry.cpp:73
Qgis::SublayerQueryFlag::IncludeSystemTables
@ IncludeSystemTables
Include system or internal tables (these are not included by default)
QgsTask
Abstract base class for long running background tasks. Tasks can be controlled directly,...
Definition: qgstaskmanager.h:54