Skip to content
Permalink
Browse files
Create QgsProviderSublayerTask for retrieving sublayer details in a t…
…hread

This can sometimes take a looooong time, so it's worth doing in the
background
  • Loading branch information
nyalldawson committed Jul 1, 2021
1 parent 0404dca commit 7c6afc0761b6973a06bcb0a0e9c6fdb1fc6769b0
@@ -0,0 +1,53 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/providers/qgsprovidersublayertask.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/





class QgsProviderSublayerTask : QgsTask
{
%Docstring(signature="appended")

A :py:class:`QgsTask` which retrieves sublayer details for a URI.

.. versionadded:: 3.22
%End

%TypeHeaderCode
#include "qgsprovidersublayertask.h"
%End
public:

QgsProviderSublayerTask( const QString &uri );
%Docstring
Constructor for QgsProviderSublayerTask, which retrieves sublayer details for the
specified ``uri``.
%End

~QgsProviderSublayerTask();

QList<QgsProviderSublayerDetails> results() const;
%Docstring
Return the sublayer details as calculated by the task.
%End

virtual bool run();

virtual void cancel();


};

/************************************************************************
* This file has been generated automatically from *
* *
* src/core/providers/qgsprovidersublayertask.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -515,6 +515,7 @@
%Include auto_generated/providers/qgsprovidermetadata.sip
%Include auto_generated/providers/qgsproviderregistry.sip
%Include auto_generated/providers/qgsprovidersublayerdetails.sip
%Include auto_generated/providers/qgsprovidersublayertask.sip
%Include auto_generated/providers/arcgis/qgsarcgisportalutils.sip
%Include auto_generated/providers/arcgis/qgsarcgisrestutils.sip
%Include auto_generated/providers/memory/qgsmemoryproviderutils.sip
@@ -233,6 +233,7 @@ set(QGIS_CORE_SRCS
providers/qgsprovidermetadata.cpp
providers/qgsproviderregistry.cpp
providers/qgsprovidersublayerdetails.cpp
providers/qgsprovidersublayertask.cpp

providers/arcgis/qgsarcgisportalutils.cpp
providers/arcgis/qgsarcgisrestquery.cpp
@@ -1522,6 +1523,7 @@ set(QGIS_CORE_HDRS
providers/qgsprovidermetadata.h
providers/qgsproviderregistry.h
providers/qgsprovidersublayerdetails.h
providers/qgsprovidersublayertask.h

providers/arcgis/qgsarcgisportalutils.h
providers/arcgis/qgsarcgisrestquery.h
@@ -0,0 +1,50 @@
/***************************************************************************
qgsprovidersublayertask.cpp
----------------------
begin : June 2021
copyright : (C) 2021 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgsprovidersublayertask.h"
#include "qgsfeedback.h"
#include "qgsproviderregistry.h"
#include "qgsprovidersublayerdetails.h"

QgsProviderSublayerTask::QgsProviderSublayerTask( const QString &uri )
: QgsTask( tr( "Retrieving layers" ), QgsTask::CanCancel | QgsTask::CancelWithoutPrompt )
, mUri( uri )
{
}

QList<QgsProviderSublayerDetails> QgsProviderSublayerTask::results() const
{
return mResults;
}

QgsProviderSublayerTask::~QgsProviderSublayerTask() = default;

bool QgsProviderSublayerTask::run()
{
mFeedback = std::make_unique< QgsFeedback >();

mResults = QgsProviderRegistry::instance()->querySublayers( mUri, Qgis::SublayerQueryFlag::ResolveGeometryType | Qgis::SublayerQueryFlag::CountFeatures, mFeedback.get() );
return true;
}

void QgsProviderSublayerTask::cancel()
{
if ( mFeedback )
mFeedback->cancel();

QgsTask::cancel();
}
@@ -0,0 +1,66 @@
/***************************************************************************
qgsprovidersublayertask.h
----------------------
begin : June 2021
copyright : (C) 2021 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSPROVIDERSUBLAYERTASKTASK_H
#define QGSPROVIDERSUBLAYERTASKTASK_H

#include "qgstaskmanager.h"
#include <memory>

class QgsFeedback;
class QgsProviderSublayerDetails;

/**
* \ingroup core
*
* \brief A QgsTask which retrieves sublayer details for a URI.
*
* \since QGIS 3.22
*/
class CORE_EXPORT QgsProviderSublayerTask : public QgsTask
{
Q_OBJECT

public:

/**
* Constructor for QgsProviderSublayerTask, which retrieves sublayer details for the
* specified \a uri.
*/
QgsProviderSublayerTask( const QString &uri );

~QgsProviderSublayerTask() override;

/**
* Return the sublayer details as calculated by the task.
*/
QList<QgsProviderSublayerDetails> results() const;

bool run() override;
void cancel() override;

private:

QString mUri;

std::unique_ptr< QgsFeedback > mFeedback;

QList<QgsProviderSublayerDetails> mResults;

};

#endif // QGSPROVIDERSUBLAYERTASKTASK_H

0 comments on commit 7c6afc0

Please sign in to comment.