Skip to content
Permalink
Browse files

Add a mechanism for data providers to supply QgsMapLayerConfigWidgetF…

…actory

via their GUI metadata

Allows providers to create layer properties pages, giving us a nice
way to keep provider-specific logic out of the layer properties
classes.
  • Loading branch information
nyalldawson committed Mar 24, 2021
1 parent cd17a85 commit 8c0b98d09550d7a469ab72faaa518557407d5909
@@ -31,7 +31,7 @@ Constructor
:param lyr: Mesh map layer for which properties will be displayed
%End

void addPropertiesPageFactory( QgsMapLayerConfigWidgetFactory *factory );
void addPropertiesPageFactory( const QgsMapLayerConfigWidgetFactory *factory );
%Docstring
Adds properties page from a factory

@@ -84,6 +84,17 @@ Returns source widget providers
Ownership of created providers is passed to the caller.

.. versionadded:: 3.18
%End

virtual QList<const QgsMapLayerConfigWidgetFactory *> mapLayerConfigWidgetFactories();
%Docstring
Returns map layer config widget factories associated with the provider.

.. note::

Ownership of factories remains with the provider.

.. versionadded:: 3.20
%End

QString key() const;
@@ -103,6 +103,15 @@ Returns all source widget providers registered in provider with ``providerKey``
.. versionadded:: 3.18
%End

virtual QList<const QgsMapLayerConfigWidgetFactory *> mapLayerConfigWidgetFactories( QgsMapLayer *layer = 0 );
%Docstring
Returns all map layer config widget factories associated with the registered providers.

The optional ``layer`` argument can be used to only return factories which support the specified layer.

.. versionadded:: 3.20
%End


};

@@ -36,7 +36,7 @@ Constructor
:param fl: windows flag
%End

void addPropertiesPageFactory( QgsMapLayerConfigWidgetFactory *factory );
void addPropertiesPageFactory( const QgsMapLayerConfigWidgetFactory *factory );
%Docstring
Adds a properties page factory to the raster layer properties dialog.

@@ -31,7 +31,7 @@ the Free Software Foundation; either version 2 of the License, or *

QgsVectorLayerProperties( QgsMapCanvas *canvas, QgsMessageBar *messageBar, QgsVectorLayer *lyr = 0, QWidget *parent = 0, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags );

void addPropertiesPageFactory( QgsMapLayerConfigWidgetFactory *factory );
void addPropertiesPageFactory( const QgsMapLayerConfigWidgetFactory *factory );
%Docstring
Adds a properties page factory to the vector layer properties dialog.
%End
@@ -121,7 +121,7 @@ QgsPointCloudLayerProperties::QgsPointCloudLayerProperties( QgsPointCloudLayer *
restoreOptionsBaseUi( title );
}

void QgsPointCloudLayerProperties::addPropertiesPageFactory( QgsMapLayerConfigWidgetFactory *factory )
void QgsPointCloudLayerProperties::addPropertiesPageFactory( const QgsMapLayerConfigWidgetFactory *factory )
{
if ( !factory->supportsLayer( mLayer ) || !factory->supportLayerPropertiesDialog() )
{
@@ -95,7 +95,7 @@ class QgsPointCloudLayerProperties : public QgsOptionsDialogBase, private Ui::Qg
QgsPointCloudLayerProperties( QgsPointCloudLayer *lyr, QgsMapCanvas *canvas, QgsMessageBar *messageBar, QWidget *parent = nullptr, Qt::WindowFlags = QgsGuiUtils::ModalDialogFlags );


void addPropertiesPageFactory( QgsMapLayerConfigWidgetFactory *factory );
void addPropertiesPageFactory( const QgsMapLayerConfigWidgetFactory *factory );

private slots:
void apply();
return; //don't show properties of embedded layers
}

// collect factories from registered data providers
QList<const QgsMapLayerConfigWidgetFactory *> providerFactories = QgsGui::providerGuiRegistry()->mapLayerConfigWidgetFactories( mapLayer );
providerFactories.append( mMapLayerPanelFactories );

switch ( mapLayer->type() )
{
case QgsMapLayerType::RasterLayer:
{
QgsRasterLayerProperties *rasterLayerPropertiesDialog = new QgsRasterLayerProperties( mapLayer, mMapCanvas, this );

for ( QgsMapLayerConfigWidgetFactory *factory : std::as_const( mMapLayerPanelFactories ) )
for ( const QgsMapLayerConfigWidgetFactory *factory : std::as_const( providerFactories ) )
{
rasterLayerPropertiesDialog->addPropertiesPageFactory( factory );
}
{
QgsMeshLayerProperties meshLayerPropertiesDialog( mapLayer, mMapCanvas, this );

for ( QgsMapLayerConfigWidgetFactory *factory : std::as_const( mMapLayerPanelFactories ) )
for ( const QgsMapLayerConfigWidgetFactory *factory : std::as_const( providerFactories ) )
{
meshLayerPropertiesDialog.addPropertiesPageFactory( factory );
}
saveAsFile( clone.get() );
}
} );
for ( QgsMapLayerConfigWidgetFactory *factory : std::as_const( mMapLayerPanelFactories ) )
for ( const QgsMapLayerConfigWidgetFactory *factory : std::as_const( providerFactories ) )
{
vectorLayerPropertiesDialog->addPropertiesPageFactory( factory );
}
else
pointCloudLayerPropertiesDialog.restoreLastPage();

for ( QgsMapLayerConfigWidgetFactory *factory : std::as_const( mMapLayerPanelFactories ) )
for ( const QgsMapLayerConfigWidgetFactory *factory : std::as_const( providerFactories ) )
{
pointCloudLayerPropertiesDialog.addPropertiesPageFactory( factory );
}
@@ -2578,7 +2578,7 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
QgsGeoreferencerMainWindow *mGeoreferencer = nullptr;
#endif

QList<QgsMapLayerConfigWidgetFactory *> mMapLayerPanelFactories;
QList<const QgsMapLayerConfigWidgetFactory *> mMapLayerPanelFactories;
QList<QPointer<QgsOptionsWidgetFactory>> mOptionsWidgetFactories;
QList<QPointer<QgsOptionsWidgetFactory>> mProjectPropertiesWidgetFactories;

@@ -60,7 +60,7 @@
#endif


QgsLayerStylingWidget::QgsLayerStylingWidget( QgsMapCanvas *canvas, QgsMessageBar *messageBar, const QList<QgsMapLayerConfigWidgetFactory *> &pages, QWidget *parent )
QgsLayerStylingWidget::QgsLayerStylingWidget( QgsMapCanvas *canvas, QgsMessageBar *messageBar, const QList<const QgsMapLayerConfigWidgetFactory *> &pages, QWidget *parent )
: QWidget( parent )
, mNotSupportedPage( 0 )
, mLayerPage( 1 )
@@ -117,7 +117,7 @@ QgsLayerStylingWidget::~QgsLayerStylingWidget()
delete mStyleManagerFactory;
}

void QgsLayerStylingWidget::setPageFactories( const QList<QgsMapLayerConfigWidgetFactory *> &factories )
void QgsLayerStylingWidget::setPageFactories( const QList<const QgsMapLayerConfigWidgetFactory *> &factories )
{
mPageFactories = factories;
// Always append the style manager factory at the bottom of the list
@@ -97,11 +97,11 @@ class APP_EXPORT QgsLayerStylingWidget : public QWidget, private Ui::QgsLayerSty
Symbology3D,
};

QgsLayerStylingWidget( QgsMapCanvas *canvas, QgsMessageBar *messageBar, const QList<QgsMapLayerConfigWidgetFactory *> &pages, QWidget *parent = nullptr );
QgsLayerStylingWidget( QgsMapCanvas *canvas, QgsMessageBar *messageBar, const QList<const QgsMapLayerConfigWidgetFactory *> &pages, QWidget *parent = nullptr );
~QgsLayerStylingWidget() override;
QgsMapLayer *layer() { return mCurrentLayer; }

void setPageFactories( const QList<QgsMapLayerConfigWidgetFactory *> &factories );
void setPageFactories( const QList<const QgsMapLayerConfigWidgetFactory *> &factories );

/**
* Sets whether updates of the styling widget are blocked. This can be called to prevent
@@ -154,7 +154,7 @@ class APP_EXPORT QgsLayerStylingWidget : public QWidget, private Ui::QgsLayerSty
QgsRendererMeshPropertiesWidget *mMeshStyleWidget = nullptr;
QgsVectorTileBasicRendererWidget *mVectorTileStyleWidget = nullptr;
QgsVectorTileBasicLabelingWidget *mVectorTileLabelingWidget = nullptr;
QList<QgsMapLayerConfigWidgetFactory *> mPageFactories;
QList<const QgsMapLayerConfigWidgetFactory *> mPageFactories;
QMap<int, QgsMapLayerConfigWidgetFactory *> mUserPages;
QgsLayerStyleManagerWidgetFactory *mStyleManagerFactory = nullptr;
};
@@ -155,7 +155,7 @@ QgsMeshLayerProperties::QgsMeshLayerProperties( QgsMapLayer *lyr, QgsMapCanvas *
restoreOptionsBaseUi( title );
}

void QgsMeshLayerProperties::addPropertiesPageFactory( QgsMapLayerConfigWidgetFactory *factory )
void QgsMeshLayerProperties::addPropertiesPageFactory( const QgsMapLayerConfigWidgetFactory *factory )
{
if ( !factory->supportsLayer( mMeshLayer ) || !factory->supportLayerPropertiesDialog() )
{
@@ -57,7 +57,7 @@ class GUI_EXPORT QgsMeshLayerProperties : public QgsOptionsDialogBase, private U
*
* \since QGIS 3.16
*/
void addPropertiesPageFactory( QgsMapLayerConfigWidgetFactory *factory );
void addPropertiesPageFactory( const QgsMapLayerConfigWidgetFactory *factory );

protected slots:
void optionsStackedWidget_CurrentChanged( int index ) override SIP_SKIP ;
@@ -52,6 +52,11 @@ QList<QgsProviderSourceWidgetProvider *> QgsProviderGuiMetadata::sourceWidgetPro
return QList<QgsProviderSourceWidgetProvider *>();
}

QList< const QgsMapLayerConfigWidgetFactory *> QgsProviderGuiMetadata::mapLayerConfigWidgetFactories()
{
return QList<const QgsMapLayerConfigWidgetFactory *>();
}

QString QgsProviderGuiMetadata::key() const
{
return mKey;
@@ -29,6 +29,7 @@ class QgsSourceSelectProvider;
class QgsProjectStorageGuiProvider;
class QgsSubsetStringEditorProvider;
class QgsProviderSourceWidgetProvider;
class QgsMapLayerConfigWidgetFactory;

/**
* \ingroup gui
@@ -85,6 +86,14 @@ class GUI_EXPORT QgsProviderGuiMetadata
*/
virtual QList<QgsProviderSourceWidgetProvider *> sourceWidgetProviders() SIP_FACTORY;

/**
* Returns map layer config widget factories associated with the provider.
*
* \note Ownership of factories remains with the provider.
* \since QGIS 3.20
*/
virtual QList<const QgsMapLayerConfigWidgetFactory *> mapLayerConfigWidgetFactories();

//! Returns unique provider key
QString key() const;

@@ -26,6 +26,7 @@
#include "qgsogrguiprovider.h"
#include "qgsvectortileproviderguimetadata.h"
#include "qgspointcloudproviderguimetadata.h"
#include "qgsmaplayerconfigwidgetfactory.h"

#ifdef HAVE_EPT
#include "qgseptproviderguimetadata.h"
@@ -229,6 +230,21 @@ QList<QgsProviderSourceWidgetProvider *> QgsProviderGuiRegistry::sourceWidgetPro
return QList<QgsProviderSourceWidgetProvider *>();
}

QList<const QgsMapLayerConfigWidgetFactory *> QgsProviderGuiRegistry::mapLayerConfigWidgetFactories( QgsMapLayer *layer )
{
QList<const QgsMapLayerConfigWidgetFactory *> res;
for ( GuiProviders::const_iterator it = mProviders.begin(); it != mProviders.end(); ++it )
{
const QList<const QgsMapLayerConfigWidgetFactory *> providerFactories = ( *it ).second->mapLayerConfigWidgetFactories();
for ( const QgsMapLayerConfigWidgetFactory *factory : providerFactories )
{
if ( !layer || factory->supportsLayer( layer ) )
res << factory;
}
}
return res;
}

QStringList QgsProviderGuiRegistry::providerList() const
{
QStringList lst;
@@ -35,6 +35,8 @@ class QgsSourceSelectProvider;
class QgsProjectStorageGuiProvider;
class QgsSubsetStringEditorProvider;
class QgsProviderSourceWidgetProvider;
class QgsMapLayerConfigWidgetFactory;
class QgsMapLayer;

/**
* \ingroup gui
@@ -102,6 +104,15 @@ class GUI_EXPORT QgsProviderGuiRegistry
*/
virtual QList<QgsProviderSourceWidgetProvider *> sourceWidgetProviders( const QString &providerKey ) SIP_FACTORY;

/**
* Returns all map layer config widget factories associated with the registered providers.
*
* The optional \a layer argument can be used to only return factories which support the specified layer.
*
* \since QGIS 3.20
*/
virtual QList<const QgsMapLayerConfigWidgetFactory *> mapLayerConfigWidgetFactories( QgsMapLayer *layer = nullptr );

//! Type for data provider metadata associative container
SIP_SKIP typedef std::map<QString, QgsProviderGuiMetadata *> GuiProviders;

@@ -542,7 +542,7 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer *lyr, QgsMapCanv
mOptsPage_Server->setProperty( "helpPage", QStringLiteral( "working_with_raster/raster_properties.html#server-properties" ) );
}

void QgsRasterLayerProperties::addPropertiesPageFactory( QgsMapLayerConfigWidgetFactory *factory )
void QgsRasterLayerProperties::addPropertiesPageFactory( const QgsMapLayerConfigWidgetFactory *factory )
{
if ( !factory->supportsLayer( mRasterLayer ) || !factory->supportLayerPropertiesDialog() )
{
@@ -83,7 +83,7 @@ class GUI_EXPORT QgsRasterLayerProperties : public QgsOptionsDialogBase, private
* Adds a properties page factory to the raster layer properties dialog.
* \since QGIS 3.18
*/
void addPropertiesPageFactory( QgsMapLayerConfigWidgetFactory *factory );
void addPropertiesPageFactory( const QgsMapLayerConfigWidgetFactory *factory );

protected slots:
//! \brief auto slot executed when the active page in the main widget stack is changed
@@ -463,7 +463,7 @@ void QgsVectorLayerProperties::toggleEditing()
setPbnQueryBuilderEnabled();
}

void QgsVectorLayerProperties::addPropertiesPageFactory( QgsMapLayerConfigWidgetFactory *factory )
void QgsVectorLayerProperties::addPropertiesPageFactory( const QgsMapLayerConfigWidgetFactory *factory )
{
if ( !factory->supportsLayer( mLayer ) || !factory->supportLayerPropertiesDialog() )
{
@@ -70,7 +70,7 @@ class GUI_EXPORT QgsVectorLayerProperties : public QgsOptionsDialogBase, private
QgsVectorLayerProperties( QgsMapCanvas *canvas, QgsMessageBar *messageBar, QgsVectorLayer *lyr = nullptr, QWidget *parent = nullptr, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags );

//! Adds a properties page factory to the vector layer properties dialog.
void addPropertiesPageFactory( QgsMapLayerConfigWidgetFactory *factory );
void addPropertiesPageFactory( const QgsMapLayerConfigWidgetFactory *factory );

protected slots:
void optionsStackedWidget_CurrentChanged( int index ) override SIP_SKIP;

0 comments on commit 8c0b98d

Please sign in to comment.