QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
qgsvirtuallayertask.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsvirtuallayertask.cpp - description
3 -------------------
4 begin : Jan 19, 2018
5 copyright : (C) 2017 by Paul Blottiere
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
18#include "qgsvirtuallayertask.h"
19#include "moc_qgsvirtuallayertask.cpp"
20#include "qgslogger.h"
21#include "qgsvectorlayer.h"
22
24 : mDefinition( definition )
25{
26 mDefinition.setLazy( true );
28 mLayer = std::make_unique<QgsVectorLayer>( mDefinition.toString(), QStringLiteral( "layer" ), QLatin1String( "virtual" ), options );
29}
30
32{
33 bool rc = false;
34 try
35 {
36 mLayer->reload(); // blocking call because the loading is postponed
37 rc = mLayer->isValid();
38 }
39 catch ( std::exception &e )
40 {
41 QgsDebugError( QStringLiteral( "Reload error: %1" ).arg( e.what() ) );
42 setExceptionText( e.what() );
43 rc = false;
44 }
45 return rc;
46}
47
49{
50 return mDefinition;
51}
52
54{
55 return mLayer.get();
56}
57
59{
60 return mLayer.release();
61}
62
64{
65 mLayer->dataProvider()->cancelReload();
67}
68
70{
71 return mExceptionText;
72}
73
74void QgsVirtualLayerTask::setExceptionText( const QString &exceptionText )
75{
76 mExceptionText = exceptionText;
77}
Contains information about the context in which a coordinate transform is executed.
virtual void cancel()
Notifies the task that it should terminate.
Represents a vector layer which manages a vector based data sets.
Class to manipulate the definition of a virtual layer.
void setLazy(bool lazy)
Sets the lazy mode.
QString toString() const
Convert into a QString that can be read by the virtual layer provider.
QgsVectorLayer * takeLayer()
Returns the underlying virtual layer and ownership.
QString exceptionText() const
Returns the exception text or an empty string if no exceptions were raised.
void cancel() override
Cancels the pending query and the parent task.
bool run() override
Reloads the data.
QgsVectorLayer * layer()
Returns the underlying virtual layer.
QgsVirtualLayerDefinition definition() const
Returns the virtual layer definition.
QgsVirtualLayerTask(const QgsVirtualLayerDefinition &definition)
Constructor.
void setExceptionText(const QString &exceptionText)
Sets the exceptionText.
#define QgsDebugError(str)
Definition qgslogger.h:38
Setting options for loading vector layers.