diff --git a/python/core/qgsvectordataprovider.sip.in b/python/core/qgsvectordataprovider.sip.in index b5ba3bffd73..1927eafbf84 100644 --- a/python/core/qgsvectordataprovider.sip.in +++ b/python/core/qgsvectordataprovider.sip.in @@ -233,6 +233,13 @@ Providers with the FastTruncate capability will use an optimised method to trunc %End virtual bool cancel(); +%Docstring +Cancels the pending query. + +:return: true if the pending query has been interrupted, false otherwise + +.. versionadded:: 3.2 +%End virtual bool addAttributes( const QList &attributes ); %Docstring diff --git a/python/core/qgsvirtuallayerdefinition.sip.in b/python/core/qgsvirtuallayerdefinition.sip.in index a3a8ff5c644..d38c42e8125 100644 --- a/python/core/qgsvirtuallayerdefinition.sip.in +++ b/python/core/qgsvirtuallayerdefinition.sip.in @@ -151,7 +151,23 @@ Set the name of the field with unique identifiers %End void setPostpone( bool postpone ); +%Docstring +Sets the postpone mode. If ``postpone`` is true, then the loading is +delayed until an explicit reloading of the layer. + +:param postpone: True to delay the loading, false otherwise + +.. versionadded:: 3.2 +%End + bool postpone() const; +%Docstring +Returns the postpone mode. + +:return: True if the loading is delayed, false otherwise. + +.. versionadded:: 3.2 +%End QString geometryField() const; %Docstring diff --git a/python/core/qgsvirtuallayertask.sip b/python/core/qgsvirtuallayertask.sip index efabcba28eb..c1189b815eb 100644 --- a/python/core/qgsvirtuallayertask.sip +++ b/python/core/qgsvirtuallayertask.sip @@ -13,9 +13,10 @@ class QgsVirtualLayerTask : QgsTask { %Docstring -Initializes a virtual layer in a separated task. +Initializes a virtual layer with postpone mode activated and reloads the +data in a separated thread. -.. versionadded:: 3.0 +.. versionadded:: 3.2 %End %TypeHeaderCode @@ -24,16 +25,35 @@ Initializes a virtual layer in a separated task. public: QgsVirtualLayerTask( const QgsVirtualLayerDefinition &definition ); +%Docstring +Constructor. + +:param definition: The definition to use for initializing the virtual layer +%End QgsVectorLayer *layer(); +%Docstring +Returns the underlying virtual layer. +%End QgsVirtualLayerDefinition definition() const; +%Docstring +Returns the virtual layer definition. +%End virtual bool run(); +%Docstring +Reloads the data. + +:return: True if the virtual layer is valid, false otherwise. +%End virtual void cancel(); +%Docstring +Cancels the pending query and the parent task. +%End }; diff --git a/src/core/qgsvectordataprovider.h b/src/core/qgsvectordataprovider.h index a30df6ddb48..4f272e55c26 100644 --- a/src/core/qgsvectordataprovider.h +++ b/src/core/qgsvectordataprovider.h @@ -249,6 +249,11 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider, public QgsFeat */ virtual bool truncate(); + /** + * Cancels the pending query. + * \returns true if the pending query has been interrupted, false otherwise + * \since QGIS 3.2 + */ virtual bool cancel(); /** diff --git a/src/core/qgsvirtuallayerdefinition.h b/src/core/qgsvirtuallayerdefinition.h index 0bdf4f8f042..fb8e2cdcf17 100644 --- a/src/core/qgsvirtuallayerdefinition.h +++ b/src/core/qgsvirtuallayerdefinition.h @@ -131,7 +131,19 @@ class CORE_EXPORT QgsVirtualLayerDefinition //! Set the name of the field with unique identifiers void setUid( const QString &uid ) { mUid = uid; } + /** + * Sets the postpone mode. If \a postpone is true, then the loading is + * delayed until an explicit reloading of the layer. + * \param postpone True to delay the loading, false otherwise + * \since QGIS 3.2 + */ void setPostpone( bool postpone ) { mPostpone = postpone; } + + /** + * Returns the postpone mode. + * \returns True if the loading is delayed, false otherwise. + * \since QGIS 3.2 + */ bool postpone() const { return mPostpone; } //! Get the name of the geometry field. Empty if no geometry field diff --git a/src/core/qgsvirtuallayertask.h b/src/core/qgsvirtuallayertask.h index 790f40f03a2..ac1b644eb47 100644 --- a/src/core/qgsvirtuallayertask.h +++ b/src/core/qgsvirtuallayertask.h @@ -25,9 +25,10 @@ /** * \ingroup core * - * Initializes a virtual layer in a separated task. + * Initializes a virtual layer with postpone mode activated and reloads the + * data in a separated thread. * - * \since QGIS 3.0 + * \since QGIS 3.2 */ class CORE_EXPORT QgsVirtualLayerTask : public QgsTask { @@ -35,14 +36,31 @@ class CORE_EXPORT QgsVirtualLayerTask : public QgsTask public: + /** + * Constructor. + * \param definition The definition to use for initializing the virtual layer + */ QgsVirtualLayerTask( const QgsVirtualLayerDefinition &definition ); + /** + * Returns the underlying virtual layer. + */ QgsVectorLayer *layer(); + /** + * Returns the virtual layer definition. + */ QgsVirtualLayerDefinition definition() const; + /** + * Reloads the data. + * \returns True if the virtual layer is valid, false otherwise. + */ bool run() override; + /** + * Cancels the pending query and the parent task. + */ void cancel() override; private: diff --git a/src/providers/virtual/qgsvirtuallayerprovider.h b/src/providers/virtual/qgsvirtuallayerprovider.h index 9fe22c40c38..52d7cbb969f 100644 --- a/src/providers/virtual/qgsvirtuallayerprovider.h +++ b/src/providers/virtual/qgsvirtuallayerprovider.h @@ -53,8 +53,17 @@ class QgsVirtualLayerProvider: public QgsVectorDataProvider QString description() const override; QgsAttributeList pkAttributeIndexes() const override; QSet dependencies() const override; + + /** + * Interrupts the pending query. + * \since QGIS 3.2 + */ bool cancel() override; + /** + * Reloads the underlying data. + * \since QGIS 3.2 + */ void reloadData() override; private: