mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-08 00:05:09 -04:00
New class QgsScopedProxyProgressTask, which makes it easy
to create proxy progress tasks and have their lifetime managed automatically.
This commit is contained in:
parent
54f4eefc45
commit
2a12c6feeb
@ -52,6 +52,36 @@ This method is safe to call from the main thread.
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class QgsScopedProxyProgressTask
|
||||||
|
{
|
||||||
|
%Docstring
|
||||||
|
|
||||||
|
Scoped :py:class:`QgsScopedProxyProgressTask`, which automatically adds the proxy task
|
||||||
|
to the application task manager on construction and finalizes the task
|
||||||
|
when it goes out of scope.
|
||||||
|
|
||||||
|
.. versionadded:: 3.4
|
||||||
|
%End
|
||||||
|
|
||||||
|
%TypeHeaderCode
|
||||||
|
#include "qgsproxyprogresstask.h"
|
||||||
|
%End
|
||||||
|
public:
|
||||||
|
|
||||||
|
QgsScopedProxyProgressTask( const QString &description );
|
||||||
|
%Docstring
|
||||||
|
Constructor for QgsScopedProxyProgressTask, with the specified ``description``.
|
||||||
|
%End
|
||||||
|
|
||||||
|
~QgsScopedProxyProgressTask();
|
||||||
|
|
||||||
|
void setProgress( double progress );
|
||||||
|
%Docstring
|
||||||
|
Sets the ``progress`` (from 0 to 100) for the proxied operation.
|
||||||
|
%End
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* This file has been generated automatically from *
|
* This file has been generated automatically from *
|
||||||
* *
|
* *
|
||||||
|
@ -1712,8 +1712,7 @@ void QgisApp::handleDropUriList( const QgsMimeDataUtils::UriList &lst )
|
|||||||
// added all layers, and only emit the signal once for the final layer added
|
// added all layers, and only emit the signal once for the final layer added
|
||||||
mBlockActiveLayerChanged = true;
|
mBlockActiveLayerChanged = true;
|
||||||
|
|
||||||
QgsProxyProgressTask *proxyTask = new QgsProxyProgressTask( tr( "Loading layers" ) );
|
QgsScopedProxyProgressTask task( tr( "Loading layers" ) );
|
||||||
QgsApplication::taskManager()->addTask( proxyTask );
|
|
||||||
|
|
||||||
// insert items in reverse order as each one is inserted on top of previous one
|
// insert items in reverse order as each one is inserted on top of previous one
|
||||||
int count = 0;
|
int count = 0;
|
||||||
@ -1756,11 +1755,9 @@ void QgisApp::handleDropUriList( const QgsMimeDataUtils::UriList &lst )
|
|||||||
openFile( u.uri, QStringLiteral( "project" ) );
|
openFile( u.uri, QStringLiteral( "project" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
proxyTask->setProxyProgress( 100.0 * static_cast< double >( count ) / lst.size() );
|
task.setProgress( 100.0 * static_cast< double >( count ) / lst.size() );
|
||||||
}
|
}
|
||||||
|
|
||||||
proxyTask->finalize( true );
|
|
||||||
|
|
||||||
mBlockActiveLayerChanged = false;
|
mBlockActiveLayerChanged = false;
|
||||||
emit activeLayerChanged( activeLayer() );
|
emit activeLayerChanged( activeLayer() );
|
||||||
}
|
}
|
||||||
|
@ -41,3 +41,23 @@ void QgsProxyProgressTask::setProxyProgress( double progress )
|
|||||||
{
|
{
|
||||||
QMetaObject::invokeMethod( this, "setProgress", Qt::AutoConnection, Q_ARG( double, progress ) );
|
QMetaObject::invokeMethod( this, "setProgress", Qt::AutoConnection, Q_ARG( double, progress ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// QgsScopedProxyProgressTask
|
||||||
|
//
|
||||||
|
|
||||||
|
QgsScopedProxyProgressTask::QgsScopedProxyProgressTask( const QString &description )
|
||||||
|
: mTask( new QgsProxyProgressTask( description ) )
|
||||||
|
{
|
||||||
|
QgsApplication::taskManager()->addTask( mTask );
|
||||||
|
}
|
||||||
|
|
||||||
|
QgsScopedProxyProgressTask::~QgsScopedProxyProgressTask()
|
||||||
|
{
|
||||||
|
mTask->finalize( true );
|
||||||
|
}
|
||||||
|
|
||||||
|
void QgsScopedProxyProgressTask::setProgress( double progress )
|
||||||
|
{
|
||||||
|
mTask->setProxyProgress( progress );
|
||||||
|
}
|
||||||
|
@ -69,4 +69,35 @@ class CORE_EXPORT QgsProxyProgressTask : public QgsTask
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \ingroup core
|
||||||
|
*
|
||||||
|
* Scoped QgsScopedProxyProgressTask, which automatically adds the proxy task
|
||||||
|
* to the application task manager on construction and finalizes the task
|
||||||
|
* when it goes out of scope.
|
||||||
|
*
|
||||||
|
* \since QGIS 3.4
|
||||||
|
*/
|
||||||
|
class CORE_EXPORT QgsScopedProxyProgressTask
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for QgsScopedProxyProgressTask, with the specified \a description.
|
||||||
|
*/
|
||||||
|
QgsScopedProxyProgressTask( const QString &description );
|
||||||
|
|
||||||
|
~QgsScopedProxyProgressTask();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the \a progress (from 0 to 100) for the proxied operation.
|
||||||
|
*/
|
||||||
|
void setProgress( double progress );
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
QgsProxyProgressTask *mTask = nullptr;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
#endif // QGSPROXYPROGRESSTASK_H
|
#endif // QGSPROXYPROGRESSTASK_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user