QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
core
providers
qgsrunnableprovidercreator.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgsrunnableprovidercreator.cpp - QgsRunnableProviderCreator
3
4
---------------------
5
begin : 20.3.2023
6
copyright : (C) 2023 by Vincent Cloarec
7
email : vcloarec at gmail dot com
8
***************************************************************************
9
* *
10
* This program is free software; you can redistribute it and/or modify *
11
* it under the terms of the GNU General Public License as published by *
12
* the Free Software Foundation; either version 2 of the License, or *
13
* (at your option) any later version. *
14
* *
15
***************************************************************************/
16
#include "
qgsrunnableprovidercreator.h
"
17
18
#include "
qgslogger.h
"
19
#include "
qgsproviderregistry.h
"
20
#include "
qgsruntimeprofiler.h
"
21
#include "
qgsthreadingutils.h
"
22
23
#include <QDebug>
24
#include <QString>
25
#include <QThread>
26
27
#include "moc_qgsrunnableprovidercreator.cpp"
28
29
using namespace
Qt::StringLiterals;
30
31
QgsRunnableProviderCreator::QgsRunnableProviderCreator
(
32
const
QString &layerId,
const
QString &providerKey,
const
QString &dataSource,
const
QgsDataProvider::ProviderOptions
&options,
Qgis::DataProviderReadFlags
flags
33
)
34
: mLayerId( layerId )
35
, mProviderKey( providerKey )
36
, mDataSource( dataSource )
37
, mOptions( options )
38
, mFlags( flags )
39
{
40
setAutoDelete(
false
);
41
}
42
43
void
QgsRunnableProviderCreator::run
()
44
{
45
QgsScopedThreadName
threadName( u
"pcreate:%1"
_s.arg( mProviderKey ) );
46
QgsDebugMsgLevel
( u
"Creating provider in parallel for %1: %2 - %3 in thread %4"
_s.arg( mLayerId, mProviderKey, mDataSource,
QgsThreadingUtils::threadDescription
( QThread::currentThread() ) ), 2 );
47
48
// should use thread-local profiler
49
QgsScopedRuntimeProfile
profile(
"Create data providers/"
+ mLayerId, u
"projectload"
_s );
50
mDataProvider.reset(
QgsProviderRegistry::instance
()->createProvider( mProviderKey, mDataSource, mOptions, mFlags ) );
51
52
QgsDebugMsgLevel
( u
"Created provider for %1: %2 - %3 belongs to thread %4"
_s.arg( mLayerId, mProviderKey, mDataSource,
QgsThreadingUtils::threadDescription
( mDataProvider->thread() ) ), 2 );
53
54
// detach from thread, so that the creator of QgsRunnableProviderCreator can "pull" the data provider
55
// (we can't push it to a thread here, because we don't know what the target thread for the owner will be)
56
mDataProvider->moveToThread(
nullptr
);
57
58
emit
providerCreated
( mDataProvider->isValid(), mLayerId );
59
}
60
61
QgsDataProvider
*
QgsRunnableProviderCreator::dataProvider
()
62
{
63
return
mDataProvider.release();
64
}
Qgis::DataProviderReadFlags
QFlags< DataProviderReadFlag > DataProviderReadFlags
Flags which control data provider construction.
Definition
qgis.h:532
QgsDataProvider
Abstract base class for spatial data provider implementations.
Definition
qgsdataprovider.h:44
QgsProviderRegistry::instance
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
Definition
qgsproviderregistry.cpp:86
QgsRunnableProviderCreator::providerCreated
void providerCreated(bool isValid, const QString &layerId)
Emitted when a provider is created with isValid set to True when the provider is valid.
QgsRunnableProviderCreator::run
void run() override
Definition
qgsrunnableprovidercreator.cpp:43
QgsRunnableProviderCreator::QgsRunnableProviderCreator
QgsRunnableProviderCreator(const QString &layerId, QString const &providerKey, QString const &dataSource, const QgsDataProvider::ProviderOptions &options, Qgis::DataProviderReadFlags flags)
Constructor.
Definition
qgsrunnableprovidercreator.cpp:31
QgsRunnableProviderCreator::dataProvider
QgsDataProvider * dataProvider()
Returns the created data provider.
Definition
qgsrunnableprovidercreator.cpp:61
QgsScopedRuntimeProfile
Scoped object for logging of the runtime for a single operation or group of operations.
Definition
qgsruntimeprofiler.h:359
QgsScopedThreadName
Scoped object for setting the current thread name.
Definition
qgsthreadingutils.h:382
QgsThreadingUtils::threadDescription
static QString threadDescription(QThread *thread)
Returns a descriptive identifier for a thread.
Definition
qgsthreadingutils.cpp:28
qgslogger.h
QgsDebugMsgLevel
#define QgsDebugMsgLevel(str, level)
Definition
qgslogger.h:80
qgsproviderregistry.h
qgsrunnableprovidercreator.h
qgsruntimeprofiler.h
qgsthreadingutils.h
QgsDataProvider::ProviderOptions
Setting options for creating vector data providers.
Definition
qgsdataprovider.h:97
Generated on
for QGIS API Documentation by
1.17.0