Skip to content

Commit

Permalink
Add enum ActionStart
Browse files Browse the repository at this point in the history
  • Loading branch information
troopa81 committed Jul 30, 2021
1 parent 014a4aa commit 56acee9
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 60 deletions.
20 changes: 7 additions & 13 deletions python/core/auto_additions/qgis.py
Expand Up @@ -349,17 +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
QgsNetworkContentFetcherRegistry.FetchingMode = Qgis.ActionStart
# monkey patching scoped based enum
QgsNetworkContentFetcherRegistry.DownloadLater = Qgis.FetchingMode.FetchLater
QgsNetworkContentFetcherRegistry.DownloadLater = Qgis.ActionStart.Deferred
QgsNetworkContentFetcherRegistry.DownloadLater.is_monkey_patched = True
QgsNetworkContentFetcherRegistry.DownloadLater.__doc__ = "Do not start immediately the fetching"
QgsNetworkContentFetcherRegistry.DownloadImmediately = Qgis.FetchingMode.FetchImmediately
QgsNetworkContentFetcherRegistry.DownloadLater.__doc__ = "Do not start immediately the action"
QgsNetworkContentFetcherRegistry.DownloadImmediately = Qgis.ActionStart.Immediate
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__
QgsNetworkContentFetcherRegistry.DownloadImmediately.__doc__ = "Action will start immediately"
Qgis.ActionStart.__doc__ = 'Enum to determine when an operation would begin\n\n.. versionadded:: 3.22\n\n' + '* ``DownloadLater``: ' + Qgis.ActionStart.Deferred.__doc__ + '\n' + '* ``DownloadImmediately``: ' + Qgis.ActionStart.Immediate.__doc__
# --
Qgis.FetchingMode.baseClass = Qgis
Qgis.ActionStart.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 Expand Up @@ -513,9 +513,3 @@
Qgis.ContentStatus.__doc__ = 'Status for fetched or stored content\n\n.. versionadded:: 3.22\n\n' + '* ``NotStarted``: ' + Qgis.ContentStatus.NotStarted.__doc__ + '\n' + '* ``OnGoing``: ' + Qgis.ContentStatus.OnGoing.__doc__ + '\n' + '* ``Finished``: ' + Qgis.ContentStatus.Finished.__doc__ + '\n' + '* ``Failed``: ' + Qgis.ContentStatus.Failed.__doc__ + '\n' + '* ``Canceled``: ' + Qgis.ContentStatus.Canceled.__doc__
# --
Qgis.ContentStatus.baseClass = Qgis
# monkey patching scoped based enum
Qgis.ExternalStorageContentMode.StartLater.__doc__ = "Do not start immediately to fetch/store to properly connect the fetched/stored signal"
Qgis.ExternalStorageContentMode.StartImmediately.__doc__ = "Fetching/Storing will start immediately, not need to run fetch/store method"
Qgis.ExternalStorageContentMode.__doc__ = 'Status for fetched or stored content\n\n.. versionadded:: 3.22\n\n' + '* ``StartLater``: ' + Qgis.ExternalStorageContentMode.StartLater.__doc__ + '\n' + '* ``StartImmediately``: ' + Qgis.ExternalStorageContentMode.StartImmediately.__doc__
# --
Qgis.ExternalStorageContentMode.baseClass = Qgis
Expand Up @@ -31,15 +31,15 @@ and registered in :py:class:`QgsExternalStorageRegistry`.
Unique identifier of the external storage type.
%End

QgsExternalStorageStoredContent *store( const QString &filePath, const QString &url, const QString &authCfg = QString(), Qgis::ExternalStorageContentMode storingMode = Qgis::ExternalStorageContentMode::StartLater ) const /Factory/;
QgsExternalStorageStoredContent *store( const QString &filePath, const QString &url, const QString &authCfg = QString(), Qgis::ActionStart storingMode = Qgis::ActionStart::Deferred ) const /Factory/;
%Docstring
Stores file ``filePath`` to the ``url`` for this project external storage.
Storing process is run in background.
Returns a :py:class:`QgsExternalStorageStoredContent` to follow the status of the stored resource.

``storingMode`` defines if the download will start immediately or shall be manually triggered
calling :py:func:`QgsExternalStorageStoredContent.store()`. User should use
Qgis.ExternalStorageContentMode.StartLater if he needs to connect the :py:func:`~QgsExternalStorage.stored` signal.
Qgis.ActionStart.Deferred if he needs to connect the :py:func:`~QgsExternalStorage.stored` signal.

After using this method, user wait for :py:func:`QgsExternalStorageStoredContent.stored()`,
:py:func:`QgsExternalStorageStoredContent.errorOccurred()` or :py:func:`QgsExternalStorageStoredContent.canceled()` signals.
Expand All @@ -49,15 +49,15 @@ It's possible to give ``authCfg`` authentication configuration id in case its ne
Caller takes ownership of the returned symbol.
%End

QgsExternalStorageFetchedContent *fetch( const QString &url, const QString &authCfg = QString(), Qgis::ExternalStorageContentMode fetchingMode = Qgis::ExternalStorageContentMode::StartLater ) const /Factory/;
QgsExternalStorageFetchedContent *fetch( const QString &url, const QString &authCfg = QString(), Qgis::ActionStart fetchingMode = Qgis::ActionStart::Deferred ) const /Factory/;
%Docstring
Fetches file from ``url`` for this project external storage.
Fetching process is run in background.
Returns a :py:class:`QgsExternalStorageFetchedContent` to follow the status of the fetched resource.

``fetchingMode`` defines if the download will start immediately or shall be manually triggered
calling :py:func:`QgsExternalStorageFetchedContent.fetch()`. User should use
Qgis.ExternalStorageContentMode.StartLater if he needs to connect the :py:func:`~QgsExternalStorage.fetched` signal.
Qgis.ActionStart.Deferred if he needs to connect the :py:func:`~QgsExternalStorage.fetched` signal.

After using this method, user should wait for :py:func:`QgsExternalStorageStoredContent.fetched()`,
:py:func:`QgsExternalStorageStoredContent.errorOccurred()` or :py:func:`QgsExternalStorageStoredContent.canceled()` signals.
Expand Down
Expand Up @@ -103,7 +103,7 @@ Create the registry for temporary downloaded files

~QgsNetworkContentFetcherRegistry();

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

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

enum class FetchingMode
enum class ActionStart
{
FetchLater,
FetchImmediately,
Deferred,
Immediate,
};

enum class UnplacedLabelVisibility
Expand Down Expand Up @@ -378,12 +378,6 @@ The development version
Canceled,
};

enum class ExternalStorageContentMode
{
StartLater,
StartImmediately,
};

static const double DEFAULT_SEARCH_RADIUS_MM;

static const float DEFAULT_MAPTOPIXEL_THRESHOLD;
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, Qgis::FetchingMode::FetchImmediately );
QgsApplication::instance()->networkContentFetcherRegistry()->fetch( ui, Qgis::ActionStart::Immediate );
}

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, Qgis::FetchingMode::FetchImmediately );
QgsApplication::instance()->networkContentFetcherRegistry()->fetch( filePath, Qgis::ActionStart::Immediate );
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/core/externalstorage/qgsexternalstorage.cpp
Expand Up @@ -32,19 +32,19 @@ const QString &QgsExternalStorageContent::errorString() const
return mErrorString;
};

QgsExternalStorageStoredContent *QgsExternalStorage::store( const QString &filePath, const QString &url, const QString &authCfg, Qgis::ExternalStorageContentMode storingMode ) const
QgsExternalStorageStoredContent *QgsExternalStorage::store( const QString &filePath, const QString &url, const QString &authCfg, Qgis::ActionStart storingMode ) const
{
QgsExternalStorageStoredContent *content = doStore( filePath, url, authCfg );
if ( storingMode == Qgis::ExternalStorageContentMode::StartImmediately )
if ( storingMode == Qgis::ActionStart::Immediate )
content->store();

return content;
}

QgsExternalStorageFetchedContent *QgsExternalStorage::fetch( const QString &url, const QString &authCfg, Qgis::ExternalStorageContentMode fetchingMode ) const
QgsExternalStorageFetchedContent *QgsExternalStorage::fetch( const QString &url, const QString &authCfg, Qgis::ActionStart fetchingMode ) const
{
QgsExternalStorageFetchedContent *content = doFetch( url, authCfg );
if ( fetchingMode == Qgis::ExternalStorageContentMode::StartImmediately )
if ( fetchingMode == Qgis::ActionStart::Immediate )
content->fetch();

return content;
Expand Down
8 changes: 4 additions & 4 deletions src/core/externalstorage/qgsexternalstorage.h
Expand Up @@ -54,7 +54,7 @@ class CORE_EXPORT QgsExternalStorage
*
* \a storingMode defines if the download will start immediately or shall be manually triggered
* calling QgsExternalStorageStoredContent::store(). User should use
* Qgis::ExternalStorageContentMode::StartLater if he needs to connect the stored() signal.
* Qgis::ActionStart::Deferred if he needs to connect the stored() signal.
*
* After using this method, user wait for QgsExternalStorageStoredContent::stored(),
* QgsExternalStorageStoredContent::errorOccurred() or QgsExternalStorageStoredContent::canceled() signals.
Expand All @@ -63,7 +63,7 @@ class CORE_EXPORT QgsExternalStorage
*
* Caller takes ownership of the returned symbol.
*/
QgsExternalStorageStoredContent *store( const QString &filePath, const QString &url, const QString &authCfg = QString(), Qgis::ExternalStorageContentMode storingMode = Qgis::ExternalStorageContentMode::StartLater ) const SIP_FACTORY;
QgsExternalStorageStoredContent *store( const QString &filePath, const QString &url, const QString &authCfg = QString(), Qgis::ActionStart storingMode = Qgis::ActionStart::Deferred ) const SIP_FACTORY;

/**
* Fetches file from \a url for this project external storage.
Expand All @@ -72,14 +72,14 @@ class CORE_EXPORT QgsExternalStorage
*
* \a fetchingMode defines if the download will start immediately or shall be manually triggered
* calling QgsExternalStorageFetchedContent::fetch(). User should use
* Qgis::ExternalStorageContentMode::StartLater if he needs to connect the fetched() signal.
* Qgis::ActionStart::Deferred if he needs to connect the fetched() signal.
*
* After using this method, user should wait for QgsExternalStorageStoredContent::fetched(),
* QgsExternalStorageStoredContent::errorOccurred() or QgsExternalStorageStoredContent::canceled() signals.
*
* It's possible to give \a authCfg authentication configuration id in case its needed.
*/
QgsExternalStorageFetchedContent *fetch( const QString &url, const QString &authCfg = QString(), Qgis::ExternalStorageContentMode fetchingMode = Qgis::ExternalStorageContentMode::StartLater ) const SIP_FACTORY;
QgsExternalStorageFetchedContent *fetch( const QString &url, const QString &authCfg = QString(), Qgis::ActionStart fetchingMode = Qgis::ActionStart::Deferred ) const SIP_FACTORY;

protected:

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 Qgis::FetchingMode fetchingMode )
const QgsFetchedContent *QgsNetworkContentFetcherRegistry::fetch( const QString &url, const Qgis::ActionStart fetchingMode )
{

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

mFileRegistry.insert( url, content );

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


Expand Down
2 changes: 1 addition & 1 deletion src/core/network/qgsnetworkcontentfetcherregistry.h
Expand Up @@ -136,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, Qgis::FetchingMode fetchingMode = Qgis::FetchingMode::FetchLater );
const QgsFetchedContent *fetch( const QString &url, Qgis::ActionStart fetchingMode = Qgis::ActionStart::Deferred );

#ifndef SIP_RUN

Expand Down
21 changes: 5 additions & 16 deletions src/core/qgis.h
Expand Up @@ -381,15 +381,15 @@ class CORE_EXPORT Qgis
Q_ENUM( DriveType )

/**
* Enum to determine when a fetching operation would begin
* Enum to determine when an operation would begin
* \since QGIS 3.22
*/
enum class FetchingMode SIP_MONKEYPATCH_SCOPEENUM_UNNEST( QgsNetworkContentFetcherRegistry, FetchingMode ) : int
enum class ActionStart 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
Deferred SIP_MONKEYPATCH_COMPAT_NAME( DownloadLater ), //!< Do not start immediately the action
Immediate SIP_MONKEYPATCH_COMPAT_NAME( DownloadImmediately ), //!< Action will start immediately
};
Q_ENUM( FetchingMode )
Q_ENUM( ActionStart )

/**
* Unplaced label visibility.
Expand Down Expand Up @@ -547,17 +547,6 @@ class CORE_EXPORT Qgis
};
Q_ENUM( ContentStatus )

/*
* Status for fetched or stored content
* \since QGIS 3.22
*/
enum class ExternalStorageContentMode : int
{
StartLater, //!< Do not start immediately to fetch/store to properly connect the fetched/stored signal
StartImmediately, //!< Fetching/Storing will start immediately, not need to run fetch/store method
};
Q_ENUM( ExternalStorageContentMode )

/**
* Babel GPS format capabilities.
*
Expand Down
8 changes: 4 additions & 4 deletions tests/src/python/test_qgsexternalstorage_base.py
Expand Up @@ -188,7 +188,7 @@ def testStoreFetchFileImmediately(self):

# store
url = self.url + "/" + os.path.basename(f.name)
storedContent = self.storage.store(f.name, url, self.auth_config.id(), Qgis.ExternalStorageContentMode.StartImmediately)
storedContent = self.storage.store(f.name, url, self.auth_config.id(), Qgis.ActionStart.Immediate)
self.assertTrue(storedContent)
self.assertEqual(storedContent.status(), Qgis.ContentStatus.OnGoing)

Expand All @@ -208,7 +208,7 @@ def testStoreFetchFileImmediately(self):
self.assertEqual(spyProgressChanged[-1][0], 100)

# fetch
fetchedContent = self.storage.fetch(self.url + "/" + os.path.basename(f.name), self.auth_config.id(), Qgis.ExternalStorageContentMode.StartImmediately)
fetchedContent = self.storage.fetch(self.url + "/" + os.path.basename(f.name), self.auth_config.id(), Qgis.ActionStart.Immediate)
self.assertTrue(fetchedContent)

# Some external storage (SimpleCopy) doesn't actually need to retrieve the resource
Expand All @@ -233,7 +233,7 @@ def testStoreFetchFileImmediately(self):
self.assertEqual(os.path.splitext(fetchedContent.filePath())[1], '.txt')

# fetch again, should be cached
fetchedContent = self.storage.fetch(self.url + "/" + os.path.basename(f.name), self.auth_config.id(), Qgis.ExternalStorageContentMode.StartImmediately)
fetchedContent = self.storage.fetch(self.url + "/" + os.path.basename(f.name), self.auth_config.id(), Qgis.ActionStart.Immediate)
self.assertTrue(fetchedContent)
self.assertEqual(fetchedContent.status(), Qgis.ContentStatus.Finished)

Expand All @@ -243,7 +243,7 @@ def testStoreFetchFileImmediately(self):
self.assertEqual(os.path.splitext(fetchedContent.filePath())[1], '.txt')

# fetch bad url
fetchedContent = self.storage.fetch(self.url + "/error", self.auth_config.id(), Qgis.ExternalStorageContentMode.StartImmediately)
fetchedContent = self.storage.fetch(self.url + "/error", self.auth_config.id(), Qgis.ActionStart.Immediate)
self.assertTrue(fetchedContent)

# Some external storage (SimpleCopy) doesn't actually need to retrieve the resource
Expand Down

0 comments on commit 56acee9

Please sign in to comment.