QGIS API Documentation 4.1.0-Master (376402f9aeb)
Loading...
Searching...
No Matches
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 ***************************************************************************/
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
29using namespace Qt::StringLiterals;
30
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
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
62{
63 return mDataProvider.release();
64}
QFlags< DataProviderReadFlag > DataProviderReadFlags
Flags which control data provider construction.
Definition qgis.h:512
Abstract base class for spatial data provider implementations.
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
void providerCreated(bool isValid, const QString &layerId)
Emitted when a provider is created with isValid set to True when the provider is valid.
QgsRunnableProviderCreator(const QString &layerId, QString const &providerKey, QString const &dataSource, const QgsDataProvider::ProviderOptions &options, Qgis::DataProviderReadFlags flags)
Constructor.
QgsDataProvider * dataProvider()
Returns the created data provider.
Scoped object for logging of the runtime for a single operation or group of operations.
Scoped object for setting the current thread name.
static QString threadDescription(QThread *thread)
Returns a descriptive identifier for a thread.
#define QgsDebugMsgLevel(str, level)
Definition qgslogger.h:63
Setting options for creating vector data providers.