QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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
20#include "qgslogger.h"
21#include "qgsvectorlayer.h"
22
23#include "moc_qgsvirtuallayertask.cpp"
24
26 : mDefinition( definition )
27{
28 mDefinition.setLazy( true );
30 mLayer = std::make_unique<QgsVectorLayer>( mDefinition.toString(), QStringLiteral( "layer" ), QLatin1String( "virtual" ), options );
31}
32
34{
35 bool rc = false;
36 try
37 {
38 mLayer->reload(); // blocking call because the loading is postponed
39 rc = mLayer->isValid();
40 }
41 catch ( std::exception &e )
42 {
43 QgsDebugError( QStringLiteral( "Reload error: %1" ).arg( e.what() ) );
44 setExceptionText( e.what() );
45 rc = false;
46 }
47 return rc;
48}
49
51{
52 return mDefinition;
53}
54
56{
57 return mLayer.get();
58}
59
61{
62 return mLayer.release();
63}
64
70
72{
73 return mExceptionText;
74}
75
77{
78 mExceptionText = exceptionText;
79}
Contains information about the context in which a coordinate transform is executed.
virtual void cancel()
Notifies the task that it should terminate.
virtual bool cancelReload()
Cancels the current reloading of data.
Represents a vector layer which manages a vector based dataset.
QgsVectorDataProvider * dataProvider() final
Returns the layer's data provider, it may be nullptr.
Manipulates the definition of a virtual layer.
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:57
Setting options for loading vector layers.