Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] Introduce QgsProfileSourceRegistry #41

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/elevation/qgsprofilesourceregistry.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/






class QgsProfileSourceRegistry
{
%Docstring(signature="appended")
Registry of profile sources used by :py:class:`QgsProfilePlotRenderer`

:py:class:`QgsProfileSourceRegistry` is not usually directly created, but rather accessed through
:py:func:`QgsApplication.profileSourceRegistry()`.

.. versionadded:: 3.38
%End

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

QgsProfileSourceRegistry();
%Docstring
Constructor - creates a registry of profile sources
%End

~QgsProfileSourceRegistry();

QList< QgsAbstractProfileSource * > profileSources() const;
%Docstring
Returns a list of registered profile sources
%End

void registerProfileSource( QgsAbstractProfileSource *source /Transfer/ );
%Docstring
Registers a profile ``source`` and takes ownership of it
%End

void unregisterProfileSource( QgsAbstractProfileSource *source );
%Docstring
Unregisters a profile ``source`` and destroys its instance
%End

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/core/elevation/qgsprofilesourceregistry.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
7 changes: 7 additions & 0 deletions python/PyQt6/core/auto_generated/qgsapplication.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,13 @@ Returns registry of available layer metadata provider implementations.
Returns registry of available external storage implementations.

.. versionadded:: 3.20
%End

static QgsProfileSourceRegistry *profileSourceRegistry() /KeepReference/;
%Docstring
Returns registry of available profile source implementations.

.. versionadded:: 3.38
%End

static QgsLocalizedDataPathRegistry *localizedDataPathRegistry() /KeepReference/;
Expand Down
1 change: 1 addition & 0 deletions python/PyQt6/core/core_auto.sip
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@
%Include auto_generated/elevation/qgsprofilerenderer.sip
%Include auto_generated/elevation/qgsprofilerequest.sip
%Include auto_generated/elevation/qgsprofilesnapping.sip
%Include auto_generated/elevation/qgsprofilesourceregistry.sip
%Include auto_generated/elevation/qgsterrainprovider.sip
%Include auto_generated/externalstorage/qgsexternalstorage.sip
%Include auto_generated/externalstorage/qgsexternalstorageregistry.sip
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/elevation/qgsprofilesourceregistry.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/






class QgsProfileSourceRegistry
{
%Docstring(signature="appended")
Registry of profile sources used by :py:class:`QgsProfilePlotRenderer`

:py:class:`QgsProfileSourceRegistry` is not usually directly created, but rather accessed through
:py:func:`QgsApplication.profileSourceRegistry()`.

.. versionadded:: 3.38
%End

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

QgsProfileSourceRegistry();
%Docstring
Constructor - creates a registry of profile sources
%End

~QgsProfileSourceRegistry();

QList< QgsAbstractProfileSource * > profileSources() const;
%Docstring
Returns a list of registered profile sources
%End

void registerProfileSource( QgsAbstractProfileSource *source /Transfer/ );
%Docstring
Registers a profile ``source`` and takes ownership of it
%End

void unregisterProfileSource( QgsAbstractProfileSource *source );
%Docstring
Unregisters a profile ``source`` and destroys its instance
%End

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/core/elevation/qgsprofilesourceregistry.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
7 changes: 7 additions & 0 deletions python/core/auto_generated/qgsapplication.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,13 @@ Returns registry of available layer metadata provider implementations.
Returns registry of available external storage implementations.

.. versionadded:: 3.20
%End

static QgsProfileSourceRegistry *profileSourceRegistry() /KeepReference/;
%Docstring
Returns registry of available profile source implementations.

.. versionadded:: 3.38
%End

static QgsLocalizedDataPathRegistry *localizedDataPathRegistry() /KeepReference/;
Expand Down
1 change: 1 addition & 0 deletions python/core/core_auto.sip
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@
%Include auto_generated/elevation/qgsprofilerenderer.sip
%Include auto_generated/elevation/qgsprofilerequest.sip
%Include auto_generated/elevation/qgsprofilesnapping.sip
%Include auto_generated/elevation/qgsprofilesourceregistry.sip
%Include auto_generated/elevation/qgsterrainprovider.sip
%Include auto_generated/externalstorage/qgsexternalstorage.sip
%Include auto_generated/externalstorage/qgsexternalstorageregistry.sip
Expand Down
6 changes: 5 additions & 1 deletion src/app/elevation/qgselevationprofilewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#include "qgsprofileexporter.h"
#include "qgsexpressioncontextutils.h"
#include "qgsterrainprovider.h"
#include "qgsprofilesourceregistry.h"

#include <QToolBar>
#include <QProgressBar>
Expand Down Expand Up @@ -890,7 +891,10 @@ void QgsElevationProfileWidget::exportResults( Qgis::ProfileExportType type )

const QList< QgsMapLayer * > layersToGenerate = mCanvas->layers();
QList< QgsAbstractProfileSource * > sources;
sources.reserve( layersToGenerate.size() );
const QList< QgsAbstractProfileSource * > registrySources = QgsApplication::profileSourceRegistry()->profileSources();
sources.reserve( layersToGenerate.size() + registrySources.size() );

sources << registrySources;
for ( QgsMapLayer *layer : layersToGenerate )
{
if ( QgsAbstractProfileSource *source = dynamic_cast< QgsAbstractProfileSource * >( layer ) )
Expand Down
2 changes: 2 additions & 0 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ set(QGIS_CORE_SRCS
elevation/qgsprofilerenderer.cpp
elevation/qgsprofilerequest.cpp
elevation/qgsprofilesnapping.cpp
elevation/qgsprofilesourceregistry.cpp
elevation/qgsterrainprovider.cpp

geocoding/qgsabstractgeocoderlocatorfilter.cpp
Expand Down Expand Up @@ -1410,6 +1411,7 @@ set(QGIS_CORE_HDRS
elevation/qgsprofilerenderer.h
elevation/qgsprofilerequest.h
elevation/qgsprofilesnapping.h
elevation/qgsprofilesourceregistry.h
elevation/qgsterrainprovider.h

externalstorage/qgsexternalstorage.h
Expand Down
45 changes: 45 additions & 0 deletions src/core/elevation/qgsprofilesourceregistry.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/***************************************************************************
qgsprofilesourceregistry.cpp
--------------------------------------
Date : April 2024
Copyright : (C) 2024 by Germán Carrillo
Email : german at opengis dot ch
***************************************************************************
* *
* 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 "qgsprofilesourceregistry.h"

#include "qgsabstractprofilesource.h"

QgsProfileSourceRegistry::QgsProfileSourceRegistry()
{

}

QgsProfileSourceRegistry::~QgsProfileSourceRegistry()
{
qDeleteAll( mSources );
}

QList< QgsAbstractProfileSource * > QgsProfileSourceRegistry::profileSources() const
{
return mSources;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if the registry should return all the sources.
Shouldn't it return a clone of a source if you ask for a given id?

That's the way other registries are working

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took QgsExternalStorageRegistry as a basis, but I guess I should've had a look at other registries as well.

The rationale behind this is that we need to get the full list in order to iterate the sources in QgsElevationProfileCanvas, see https://github.com/gacarrillor/QGIS/pull/41/files#diff-7858eaf011cbfda84a6f705b8e0c0f64b95b113bf9a602d2fe6aa51548495862R848

}

void QgsProfileSourceRegistry::registerProfileSource( QgsAbstractProfileSource *profileSource )
{
if ( !mSources.contains( profileSource ) )
mSources.append( profileSource );
}

void QgsProfileSourceRegistry::unregisterProfileSource( QgsAbstractProfileSource *profileSource )
{
const int index = mSources.indexOf( profileSource );
if ( index >= 0 )
delete mSources.takeAt( index );
}
69 changes: 69 additions & 0 deletions src/core/elevation/qgsprofilesourceregistry.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/***************************************************************************
qgsprofilesourceregistry.h
--------------------------------------
Date : April 2024
Copyright : (C) 2024 by Germán Carrillo
Email : german at opengis dot ch
***************************************************************************
* *
* 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 QGSPROFILESOURCEREGISTRY_H
#define QGSPROFILESOURCEREGISTRY_H

#include "qgis_core.h"
#include "qgis_sip.h"

class QgsAbstractProfileSource;

#include <QList>


/**
* \ingroup core
* \brief Registry of profile sources used by QgsProfilePlotRenderer
*
* QgsProfileSourceRegistry is not usually directly created, but rather accessed through
* QgsApplication::profileSourceRegistry().
*
* \since QGIS 3.38
*/
class CORE_EXPORT QgsProfileSourceRegistry
{
public:

/**
* Constructor - creates a registry of profile sources
*/
QgsProfileSourceRegistry();

/**
* Destructor
*/
~QgsProfileSourceRegistry();

/**
* Returns a list of registered profile sources
*/
QList< QgsAbstractProfileSource * > profileSources() const;

/**
* Registers a profile \a source and takes ownership of it
*/
void registerProfileSource( QgsAbstractProfileSource *source SIP_TRANSFER );

/**
* Unregisters a profile \a source and destroys its instance
*/
void unregisterProfileSource( QgsAbstractProfileSource *source );

private:
QList< QgsAbstractProfileSource * > mSources;
};

#endif // QGSPROFILESOURCEREGISTRY_H
4 changes: 4 additions & 0 deletions src/core/layout/qgslayoutitemelevationprofile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "qgsvectorlayer.h"
#include "qgslayoutrendercontext.h"
#include "qgslayoutreportcontext.h"
#include "qgsprofilesourceregistry.h"

#include <QTimer>

Expand Down Expand Up @@ -673,6 +674,7 @@ void QgsLayoutItemElevationProfile::paint( QPainter *painter, const QStyleOption
rc.setMapToPixel( QgsMapToPixel( mapUnitsPerPixel ) );

QList< QgsAbstractProfileSource * > sources;
sources << QgsApplication::profileSourceRegistry()->profileSources();
for ( const QgsMapLayerRef &layer : std::as_const( mLayers ) )
{
if ( QgsAbstractProfileSource *source = dynamic_cast< QgsAbstractProfileSource * >( layer.get() ) )
Expand Down Expand Up @@ -725,6 +727,7 @@ void QgsLayoutItemElevationProfile::paint( QPainter *painter, const QStyleOption
rc.setMapToPixel( QgsMapToPixel( mapUnitsPerPixel ) );

QList< QgsAbstractProfileSource * > sources;
sources << QgsApplication::profileSourceRegistry()->profileSources();
for ( const QgsMapLayerRef &layer : std::as_const( mLayers ) )
{
if ( QgsAbstractProfileSource *source = dynamic_cast< QgsAbstractProfileSource * >( layer.get() ) )
Expand Down Expand Up @@ -960,6 +963,7 @@ void QgsLayoutItemElevationProfile::recreateCachedImageInBackground()
mPainter.reset( new QPainter( mCacheRenderingImage.get() ) );

QList< QgsAbstractProfileSource * > sources;
sources << QgsApplication::profileSourceRegistry()->profileSources();
for ( const QgsMapLayerRef &layer : std::as_const( mLayers ) )
{
if ( QgsAbstractProfileSource *source = dynamic_cast< QgsAbstractProfileSource * >( layer.get() ) )
Expand Down
12 changes: 12 additions & 0 deletions src/core/qgsapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
#include "qgsgpsconnection.h"
#include "qgssensorregistry.h"
#include "qgssensorthingsutils.h"
#include "qgsprofilesourceregistry.h"

#include "gps/qgsgpsconnectionregistry.h"
#include "processing/qgsprocessingregistry.h"
Expand Down Expand Up @@ -2640,6 +2641,11 @@ QgsExternalStorageRegistry *QgsApplication::externalStorageRegistry()
return members()->mExternalStorageRegistry;
}

QgsProfileSourceRegistry *QgsApplication::profileSourceRegistry()
{
return members()->mProfileSourceRegistry;
}

QgsLocalizedDataPathRegistry *QgsApplication::localizedDataPathRegistry()
{
return members()->mLocalizedDataPathRegistry;
Expand Down Expand Up @@ -2823,6 +2829,11 @@ QgsApplication::ApplicationMembers::ApplicationMembers()
mExternalStorageRegistry = new QgsExternalStorageRegistry();
profiler->end();
}
{
profiler->start( tr( "Setup profile source registry" ) );
mProfileSourceRegistry = new QgsProfileSourceRegistry();
profiler->end();
}
{
profiler->start( tr( "Setup network content cache" ) );
mNetworkContentFetcherRegistry = new QgsNetworkContentFetcherRegistry();
Expand Down Expand Up @@ -2888,6 +2899,7 @@ QgsApplication::ApplicationMembers::~ApplicationMembers()
delete mRecentStyleHandler;
delete mSymbolLayerRegistry;
delete mExternalStorageRegistry;
delete mProfileSourceRegistry;
delete mTaskManager;
delete mNetworkContentFetcherRegistry;
delete mClassificationMethodRegistry;
Expand Down
Loading
Loading