Skip to content

Commit

Permalink
move QgsNetworkContentFetcherRegistry::FetchingMode to Qgis (#44397)
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Jul 27, 2021
1 parent 6b993f6 commit 6967406
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 20 deletions.
11 changes: 11 additions & 0 deletions python/core/auto_additions/qgis.py
Expand Up @@ -349,6 +349,17 @@
Qgis.DriveType.__doc__ = 'Drive types\n\n.. versionadded:: 3.20\n\n' + '* ``Unknown``: ' + Qgis.DriveType.Unknown.__doc__ + '\n' + '* ``Invalid``: ' + Qgis.DriveType.Invalid.__doc__ + '\n' + '* ``Removable``: ' + Qgis.DriveType.Removable.__doc__ + '\n' + '* ``Fixed``: ' + Qgis.DriveType.Fixed.__doc__ + '\n' + '* ``Remote``: ' + Qgis.DriveType.Remote.__doc__ + '\n' + '* ``CdRom``: ' + Qgis.DriveType.CdRom.__doc__ + '\n' + '* ``RamDisk``: ' + Qgis.DriveType.RamDisk.__doc__
# --
Qgis.DriveType.baseClass = Qgis
QgsNetworkContentFetcherRegistry.FetchingMode = Qgis.FetchingMode
# monkey patching scoped based enum
QgsNetworkContentFetcherRegistry.DownloadLater = Qgis.FetchingMode.FetchLater
QgsNetworkContentFetcherRegistry.DownloadLater.is_monkey_patched = True
QgsNetworkContentFetcherRegistry.DownloadLater.__doc__ = "Do not start immediately the fetching"
QgsNetworkContentFetcherRegistry.DownloadImmediately = Qgis.FetchingMode.FetchImmediately
QgsNetworkContentFetcherRegistry.DownloadImmediately.is_monkey_patched = True
QgsNetworkContentFetcherRegistry.DownloadImmediately.__doc__ = "The fetching will start immediately"
Qgis.FetchingMode.__doc__ = 'Enum to determine when a fetching operation would begin\n\n.. versionadded:: 3.22\n\n' + '* ``DownloadLater``: ' + Qgis.FetchingMode.FetchLater.__doc__ + '\n' + '* ``DownloadImmediately``: ' + Qgis.FetchingMode.FetchImmediately.__doc__
# --
Qgis.FetchingMode.baseClass = Qgis
# monkey patching scoped based enum
Qgis.UnplacedLabelVisibility.FollowEngineSetting.__doc__ = "Respect the label engine setting"
Qgis.UnplacedLabelVisibility.NeverShow.__doc__ = "Never show unplaced labels, regardless of the engine setting"
Expand Down

This file was deleted.

Expand Up @@ -95,11 +95,6 @@ remote files during QGIS application running.
#include "qgsnetworkcontentfetcherregistry.h"
%End
public:
enum FetchingMode
{
DownloadLater,
DownloadImmediately,
};

explicit QgsNetworkContentFetcherRegistry();
%Docstring
Expand All @@ -108,7 +103,7 @@ Create the registry for temporary downloaded files

~QgsNetworkContentFetcherRegistry();

const QgsFetchedContent *fetch( const QString &url, FetchingMode fetchingMode = DownloadLater );
const QgsFetchedContent *fetch( const QString &url, Qgis::FetchingMode fetchingMode = Qgis::FetchingMode::FetchLater );
%Docstring
Initialize a download for the given URL

Expand Down
6 changes: 6 additions & 0 deletions python/core/auto_generated/qgis.sip.in
Expand Up @@ -261,6 +261,12 @@ The development version
RamDisk,
};

enum class FetchingMode
{
FetchLater,
FetchImmediately,
};

enum class UnplacedLabelVisibility
{
FollowEngineSetting,
Expand Down
4 changes: 2 additions & 2 deletions src/core/editform/qgseditformconfig.cpp
Expand Up @@ -217,7 +217,7 @@ void QgsEditFormConfig::setUiForm( const QString &ui )
if ( !ui.isEmpty() && !QUrl::fromUserInput( ui ).isLocalFile() )
{
// any existing download will not be restarted!
QgsApplication::instance()->networkContentFetcherRegistry()->fetch( ui, QgsNetworkContentFetcherRegistry::DownloadImmediately );
QgsApplication::instance()->networkContentFetcherRegistry()->fetch( ui, Qgis::FetchingMode::FetchImmediately );
}

if ( ui.isEmpty() )
Expand Down Expand Up @@ -323,7 +323,7 @@ void QgsEditFormConfig::setInitFilePath( const QString &filePath )
if ( !filePath.isEmpty() && !QUrl::fromUserInput( filePath ).isLocalFile() )
{
// any existing download will not be restarted!
QgsApplication::instance()->networkContentFetcherRegistry()->fetch( filePath, QgsNetworkContentFetcherRegistry::DownloadImmediately );
QgsApplication::instance()->networkContentFetcherRegistry()->fetch( filePath, Qgis::FetchingMode::FetchImmediately );
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/core/network/qgsnetworkcontentfetcherregistry.cpp
Expand Up @@ -31,7 +31,7 @@ QgsNetworkContentFetcherRegistry::~QgsNetworkContentFetcherRegistry()
mFileRegistry.clear();
}

const QgsFetchedContent *QgsNetworkContentFetcherRegistry::fetch( const QString &url, const FetchingMode fetchingMode )
const QgsFetchedContent *QgsNetworkContentFetcherRegistry::fetch( const QString &url, const Qgis::FetchingMode fetchingMode )
{

if ( mFileRegistry.contains( url ) )
Expand All @@ -43,7 +43,7 @@ const QgsFetchedContent *QgsNetworkContentFetcherRegistry::fetch( const QString

mFileRegistry.insert( url, content );

if ( fetchingMode == DownloadImmediately )
if ( fetchingMode == Qgis::FetchingMode::FetchImmediately )
content->download();


Expand Down
9 changes: 1 addition & 8 deletions src/core/network/qgsnetworkcontentfetcherregistry.h
Expand Up @@ -124,13 +124,6 @@ class CORE_EXPORT QgsNetworkContentFetcherRegistry : public QObject
{
Q_OBJECT
public:
//! Enum to determine when the download should start
enum FetchingMode
{
DownloadLater, //!< Do not start immediately the download to properly connect the fetched signal
DownloadImmediately, //!< The download will start immediately, not need to run QgsFecthedContent::download()
};
Q_ENUM( FetchingMode )

//! Create the registry for temporary downloaded files
explicit QgsNetworkContentFetcherRegistry() = default;
Expand All @@ -143,7 +136,7 @@ class CORE_EXPORT QgsNetworkContentFetcherRegistry : public QObject
* \param fetchingMode defines if the download will start immediately or shall be manually triggered
* \note If the download starts immediately, it will not redownload any already fetched or currently fetching file.
*/
const QgsFetchedContent *fetch( const QString &url, FetchingMode fetchingMode = DownloadLater );
const QgsFetchedContent *fetch( const QString &url, Qgis::FetchingMode fetchingMode = Qgis::FetchingMode::FetchLater );

#ifndef SIP_RUN

Expand Down
11 changes: 11 additions & 0 deletions src/core/qgis.h
Expand Up @@ -380,6 +380,17 @@ class CORE_EXPORT Qgis
};
Q_ENUM( DriveType )

/**
* Enum to determine when a fetching operation would begin
* \since QGIS 3.22
*/
enum class FetchingMode SIP_MONKEYPATCH_SCOPEENUM_UNNEST( QgsNetworkContentFetcherRegistry, FetchingMode ) : int
{
FetchLater SIP_MONKEYPATCH_COMPAT_NAME( DownloadLater ), //!< Do not start immediately the fetching
FetchImmediately SIP_MONKEYPATCH_COMPAT_NAME( DownloadImmediately ), //!< The fetching will start immediately
};
Q_ENUM( FetchingMode )

/**
* Unplaced label visibility.
*
Expand Down

0 comments on commit 6967406

Please sign in to comment.