Skip to content

Commit

Permalink
add support for plugin dialogs raster layer properties
Browse files Browse the repository at this point in the history
  • Loading branch information
Samweli authored and nyalldawson committed Feb 16, 2021
1 parent 36d7a8e commit a388376
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
Expand Up @@ -34,6 +34,11 @@ Constructor
:param canvas: the :py:class:`QgsMapCanvas` instance
:param parent: the parent of this widget
:param fl: windows flag
%End

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

protected slots:
Expand Down
6 changes: 6 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -16230,6 +16230,12 @@ void QgisApp::showLayerProperties( QgsMapLayer *mapLayer, const QString &page )
case QgsMapLayerType::RasterLayer:
{
QgsRasterLayerProperties *rasterLayerPropertiesDialog = new QgsRasterLayerProperties( mapLayer, mMapCanvas, this );

for ( QgsMapLayerConfigWidgetFactory *factory : qgis::as_const( mMapLayerPanelFactories ) )
{
rasterLayerPropertiesDialog->addPropertiesPageFactory( factory );
}

if ( !page.isEmpty() )
rasterLayerPropertiesDialog->setCurrentPage( page );

Expand Down
25 changes: 25 additions & 0 deletions src/gui/raster/qgsrasterlayerproperties.cpp
Expand Up @@ -63,6 +63,7 @@
#include "qgsproviderregistry.h"
#include "qgsrasterlayertemporalproperties.h"
#include "qgsdoublevalidator.h"
#include "qgsmaplayerconfigwidgetfactory.h"

#include "qgsrasterlayertemporalpropertieswidget.h"
#include "qgsprojecttimesettings.h"
Expand Down Expand Up @@ -545,6 +546,23 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer *lyr, QgsMapCanv
mOptsPage_Server->setProperty( "helpPage", QStringLiteral( "working_with_raster/raster_properties.html#server-properties" ) );
}

void QgsRasterLayerProperties::addPropertiesPageFactory( QgsMapLayerConfigWidgetFactory *factory )
{
if ( !factory->supportsLayer( mRasterLayer ) || !factory->supportLayerPropertiesDialog() )
{
return;
}

QgsMapLayerConfigWidget *page = factory->createWidget( mRasterLayer, nullptr, false, this );
mLayerPropertiesPages << page;

const QString beforePage = factory->layerPropertiesPagePositionHint();
if ( beforePage.isEmpty() )
addPage( factory->title(), factory->title(), factory->icon(), page );
else
insertPage( factory->title(), factory->title(), factory->icon(), page, beforePage );
}

void QgsRasterLayerProperties::setupTransparencyTable( int nBands )
{
tableTransparency->clear();
Expand Down Expand Up @@ -930,6 +948,13 @@ void QgsRasterLayerProperties::sync()
mLegendConfigEmbeddedWidget->setLayer( mRasterLayer );

mTemporalWidget->syncToLayer();

const auto constMLayerPropertiesPages = mLayerPropertiesPages;
for ( QgsMapLayerConfigWidget *page : constMLayerPropertiesPages )
{
page->syncToLayer( mRasterLayer );
}

}

void QgsRasterLayerProperties::apply()
Expand Down
8 changes: 8 additions & 0 deletions src/gui/raster/qgsrasterlayerproperties.h
Expand Up @@ -41,6 +41,8 @@ class QgsRasterHistogramWidget;
class QgsRasterLayerTemporalPropertiesWidget;
class QgsWebView;
class QgsProviderSourceWidget;
class QgsMapLayerConfigWidgetFactory;
class QgsMapLayerConfigWidget;


/**
Expand Down Expand Up @@ -77,6 +79,9 @@ class GUI_EXPORT QgsRasterLayerProperties : public QgsOptionsDialogBase, private
*/
QgsRasterLayerProperties( QgsMapLayer *lyr, QgsMapCanvas *canvas, QWidget *parent = nullptr, Qt::WindowFlags = QgsGuiUtils::ModalDialogFlags );

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

protected slots:
//! \brief auto slot executed when the active page in the main widget stack is changed
void optionsStackedWidget_CurrentChanged( int index ) override SIP_SKIP ;
Expand Down Expand Up @@ -191,6 +196,9 @@ class GUI_EXPORT QgsRasterLayerProperties : public QgsOptionsDialogBase, private
QAction *mActionLoadMetadata = nullptr;
QAction *mActionSaveMetadataAs = nullptr;

//! A list of additional pages provided by plugins
QList<QgsMapLayerConfigWidget *> mLayerPropertiesPages;

//! \brief A constant that signals property not used
const QString TRSTRING_NOT_SET;

Expand Down

0 comments on commit a388376

Please sign in to comment.