Skip to content

Commit

Permalink
Add shell for 2d renderer config to layer styling dock
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 16, 2020
1 parent 0557160 commit 1758ca1
Show file tree
Hide file tree
Showing 16 changed files with 153 additions and 13 deletions.
Expand Up @@ -10,7 +10,7 @@



class QgsPointCloudRendererPropertiesWidget : QgsPanelWidget
class QgsPointCloudRendererPropertiesWidget : QgsMapLayerConfigWidget
{
%Docstring
A generic widget for setting the 2D renderer for a point cloud layer.
Expand All @@ -33,6 +33,12 @@ Constructor for QgsPointCloudRendererPropertiesWidget, associated with the speci
Sets the ``context`` in which the widget is shown, e.g., the associated map canvas and expression contexts.
%End

virtual void syncToLayer( QgsMapLayer *layer );

public slots:

virtual void apply();

};


Expand Down
Expand Up @@ -27,7 +27,7 @@ Constructor for QgsPointCloudRendererWidget, associated with the
specified ``layer`` and ``style`` database.
%End

virtual QgsPointCloudRenderer *renderer() /Factory/ = 0;
virtual QgsPointCloudRenderer *renderer() = 0 /Factory/;
%Docstring
Returns a new instance of a renderer as defined by the settings in the widget.

Expand Down
1 change: 1 addition & 0 deletions python/gui/gui_auto.sip
Expand Up @@ -335,6 +335,7 @@
%Include auto_generated/numericformats/qgsnumericformatwidget.sip
%Include auto_generated/numericformats/qgsnumericformatguiregistry.sip
%Include auto_generated/pointcloud/qgspointcloudrendererwidget.sip
%Include auto_generated/pointcloud/qgspointcloudrendererpropertieswidget.sip
%Include auto_generated/processing/qgsprocessingaggregatewidgets.sip
%Include auto_generated/processing/qgsprocessingalgorithmconfigurationwidget.sip
%Include auto_generated/processing/qgsprocessingalgorithmdialogbase.sip
Expand Down
1 change: 1 addition & 0 deletions src/app/CMakeLists.txt
Expand Up @@ -117,6 +117,7 @@ set(QGIS_APP_SRCS
decorations/qgsdecorationgriddialog.cpp

pointcloud/qgspointcloudlayerproperties.cpp
pointcloud/qgspointcloudlayerstylewidget.cpp

vectortile/qgsvectortilelayerproperties.cpp

Expand Down
21 changes: 21 additions & 0 deletions src/app/pointcloud/qgspointcloudlayerproperties.cpp
Expand Up @@ -25,6 +25,8 @@
#include "qgsapplication.h"
#include "qgsmetadatawidget.h"
#include "qgsmaplayerloadstyledialog.h"
#include "qgsmaplayerconfigwidgetfactory.h"
#include "qgsmaplayerconfigwidget.h"
#include <QFileDialog>
#include <QMenu>
#include <QMessageBox>
Expand Down Expand Up @@ -102,6 +104,25 @@ QgsPointCloudLayerProperties::QgsPointCloudLayerProperties( QgsPointCloudLayer *
restoreOptionsBaseUi( title );
}

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

QgsMapLayerConfigWidget *page = factory->createWidget( mLayer, mMapCanvas, false, this );
mConfigWidgets << 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 );

page->syncToLayer( mLayer );
}

#include "qgspointcloudrenderer.h"

void QgsPointCloudLayerProperties::apply()
Expand Down
8 changes: 7 additions & 1 deletion src/app/pointcloud/qgspointcloudlayerproperties.h
Expand Up @@ -27,14 +27,17 @@ class QgsMapCanvas;
class QgsMessageBar;
class QgsPointCloudLayer;
class QgsMetadataWidget;

class QgsMapLayerConfigWidgetFactory;
class QgsMapLayerConfigWidget;

class QgsPointCloudLayerProperties : public QgsOptionsDialogBase, private Ui::QgsPointCloudLayerPropertiesBase
{
Q_OBJECT
public:
QgsPointCloudLayerProperties( QgsPointCloudLayer *lyr, QgsMapCanvas *canvas, QgsMessageBar *messageBar, QWidget *parent = nullptr, Qt::WindowFlags = QgsGuiUtils::ModalDialogFlags );

void addPropertiesPageFactory( QgsMapLayerConfigWidgetFactory *factory );

private slots:
void apply();
void onCancel();
Expand Down Expand Up @@ -73,6 +76,9 @@ class QgsPointCloudLayerProperties : public QgsOptionsDialogBase, private Ui::Qg
* was loaded but dialog is canceled.
*/
QgsMapLayerStyle mOldStyle;

QList<QgsMapLayerConfigWidget *> mConfigWidgets;

};

#endif // QGSPOINTCLOUDLAYERPROPERTIES_H
53 changes: 53 additions & 0 deletions src/app/pointcloud/qgspointcloudlayerstylewidget.cpp
@@ -0,0 +1,53 @@
/***************************************************************************
qgspointcloudlayerstylewidget.cpp
---------------------
begin : November 2020
copyright : (C) 2020 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************
* *
* 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 "qgspointcloudlayerstylewidget.h"
#include "qgspointcloudrendererpropertieswidget.h"
#include "qgsstyle.h"
#include "qgsapplication.h"
#include "qgsmaplayer.h"
#include "qgspointcloudlayer.h"

QgsPointCloudRendererWidgetFactory::QgsPointCloudRendererWidgetFactory( QObject *parent )
: QObject( parent )
{
setIcon( QgsApplication::getThemeIcon( QStringLiteral( "propertyicons/symbology.svg" ) ) );
setTitle( tr( "Symbology" ) );
}

QgsMapLayerConfigWidget *QgsPointCloudRendererWidgetFactory::createWidget( QgsMapLayer *layer, QgsMapCanvas *, bool, QWidget *parent ) const
{
return new QgsPointCloudRendererPropertiesWidget( qobject_cast< QgsPointCloudLayer * >( layer ), QgsStyle::defaultStyle(), parent );
}

bool QgsPointCloudRendererWidgetFactory::supportLayerPropertiesDialog() const
{
return true;
}

bool QgsPointCloudRendererWidgetFactory::supportsStyleDock() const
{
return true;
}

bool QgsPointCloudRendererWidgetFactory::supportsLayer( QgsMapLayer *layer ) const
{
return layer->type() == QgsMapLayerType::PointCloudLayer;
}

QString QgsPointCloudRendererWidgetFactory::layerPropertiesPagePositionHint() const
{
return QStringLiteral( "mOptsPage_Metadata" );
}
37 changes: 37 additions & 0 deletions src/app/pointcloud/qgspointcloudlayerstylewidget.h
@@ -0,0 +1,37 @@
/***************************************************************************
qgspointcloudlayerstylewidget.h
---------------------
begin : November 2020
copyright : (C) 2020 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************
* *
* 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 QGSPOINTCLOUDLAYERSTYLEWIDGET_H
#define QGSPOINTCLOUDLAYERSTYLEWIDGET_H

#include "qgsmaplayerconfigwidget.h"
#include "qgsmaplayerconfigwidgetfactory.h"

class QgsPointCloudRendererWidgetFactory : public QObject, public QgsMapLayerConfigWidgetFactory
{
Q_OBJECT
public:
explicit QgsPointCloudRendererWidgetFactory( QObject *parent = nullptr );

QgsMapLayerConfigWidget *createWidget( QgsMapLayer *layer, QgsMapCanvas *canvas, bool dockWidget, QWidget *parent ) const override;
bool supportLayerPropertiesDialog() const override;
bool supportsStyleDock() const override;
bool supportsLayer( QgsMapLayer *layer ) const override;
QString layerPropertiesPagePositionHint() const override;
};



#endif // QGSPOINTCLOUDLAYERSTYLEWIDGET_H
9 changes: 9 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -398,6 +398,8 @@ Q_GUI_EXPORT extern int qt_defaultDpiX();
#include "qgssublayersdialog.h"
#include "ogr/qgsvectorlayersaveasdialog.h"

#include "pointcloud/qgspointcloudlayerstylewidget.h"

#ifdef ENABLE_MODELTEST
#include "modeltest.h"
#endif
Expand Down Expand Up @@ -1338,6 +1340,8 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
registerMapLayerPropertiesFactory( new QgsMeshLayer3DRendererWidgetFactory( this ) );
#endif

registerMapLayerPropertiesFactory( new QgsPointCloudRendererWidgetFactory( this ) );

activateDeactivateLayerRelatedActions( nullptr ); // after members were created

connect( QgsGui::mapLayerActionRegistry(), &QgsMapLayerActionRegistry::changed, this, &QgisApp::refreshActionFeatureAction );
Expand Down Expand Up @@ -16260,6 +16264,11 @@ void QgisApp::showLayerProperties( QgsMapLayer *mapLayer, const QString &page )
if ( !page.isEmpty() )
pointCloudLayerPropertiesDialog.setCurrentPage( page );

for ( QgsMapLayerConfigWidgetFactory *factory : qgis::as_const( mMapLayerPanelFactories ) )
{
pointCloudLayerPropertiesDialog.addPropertiesPageFactory( factory );
}

mMapStyleWidget->blockUpdates( true );
if ( pointCloudLayerPropertiesDialog.exec() )
{
Expand Down
6 changes: 1 addition & 5 deletions src/app/qgslayerstylingwidget.cpp
Expand Up @@ -676,11 +676,7 @@ void QgsLayerStylingWidget::updateCurrentWidgetLayer()

case QgsMapLayerType::PointCloudLayer:
{
QgsPointCloudLayer *pcLayer = qobject_cast<QgsPointCloudLayer *>( mCurrentLayer );
( void )pcLayer;

//TODO
mStackedWidget->setCurrentIndex( mNotSupportedPage );
// everything is handled by factories for this layer type!
break;
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/pointcloud/qgspointcloudrenderer.cpp
Expand Up @@ -109,7 +109,7 @@ QgsPointCloudRenderer *QgsDummyPointCloudRenderer::clone() const
res->mZMin = zMin();
res->mZMax = zMax();
res->mPenWidth = penWidth();
res->mColorRamp.reset( colorRamp()->clone() );
res->mColorRamp.reset( colorRamp() ? colorRamp()->clone() : QgsStyle::defaultStyle()->colorRamp( QStringLiteral( "Viridis" ) ) );
res->mAttribute = attribute();

return res.release();
Expand Down
1 change: 1 addition & 0 deletions src/core/qgsmaplayerproxymodel.cpp
Expand Up @@ -53,6 +53,7 @@ bool QgsMapLayerProxyModel::layerMatchesFilters( const QgsMapLayer *layer, const
( filters.testFlag( VectorLayer ) && layer->type() == QgsMapLayerType::VectorLayer ) ||
( filters.testFlag( MeshLayer ) && layer->type() == QgsMapLayerType::MeshLayer ) ||
( filters.testFlag( VectorTileLayer ) && layer->type() == QgsMapLayerType::VectorTileLayer ) ||
( filters.testFlag( PointCloudLayer ) && layer->type() == QgsMapLayerType::PointCloudLayer ) ||
( filters.testFlag( PluginLayer ) && layer->type() == QgsMapLayerType::PluginLayer ) )
return true;

Expand Down
2 changes: 2 additions & 0 deletions src/gui/CMakeLists.txt
Expand Up @@ -288,6 +288,7 @@ set(QGIS_GUI_SRCS
ogr/qgsvectorlayersaveasdialog.cpp

pointcloud/qgspointcloudrendererwidget.cpp
pointcloud/qgspointcloudrendererpropertieswidget.cpp

processing/qgsprocessingaggregatewidgets.cpp
processing/qgsprocessingaggregatewidgetwrapper.cpp
Expand Down Expand Up @@ -1059,6 +1060,7 @@ set(QGIS_GUI_HDRS
ogr/qgsvectorlayersaveasdialog.h

pointcloud/qgspointcloudrendererwidget.h
pointcloud/qgspointcloudrendererpropertieswidget.h

processing/qgsprocessingaggregatewidgets.h
processing/qgsprocessingaggregatewidgetwrapper.h
Expand Down
4 changes: 2 additions & 2 deletions src/gui/pointcloud/qgspointcloudrendererpropertieswidget.cpp
Expand Up @@ -18,6 +18,7 @@
#include "qgsapplication.h"
#include "qgssymbolwidgetcontext.h"
#include "qgspointcloudrendererwidget.h"
#include "qgspointcloudlayer.h"

static bool _initRenderer( const QString &name, QgsPointCloudRendererWidgetFunc f, const QString &iconName = QString() )
{
Expand Down Expand Up @@ -52,10 +53,9 @@ static void _initRendererWidgetFunctions()
}

QgsPointCloudRendererPropertiesWidget::QgsPointCloudRendererPropertiesWidget( QgsPointCloudLayer *layer, QgsStyle *style, QWidget *parent )
: QgsPanelWidget( parent )
: QgsMapLayerConfigWidget( layer, nullptr, parent )
, mLayer( layer )
, mStyle( style )

{
setupUi( this );
mLayerRenderingGroupBox->setSettingGroup( QStringLiteral( "layerRenderingGroupBox" ) );
Expand Down
9 changes: 8 additions & 1 deletion src/gui/pointcloud/qgspointcloudrendererpropertieswidget.h
Expand Up @@ -20,6 +20,7 @@
#include "qgis_gui.h"

#include "ui_qgspointcloudrendererpropsdialogbase.h"
#include "qgsmaplayerconfigwidget.h"

class QgsPointCloudLayer;
class QgsStyle;
Expand All @@ -34,7 +35,7 @@ class QgsMessageBar;
*
* \since QGIS 3.18
*/
class GUI_EXPORT QgsPointCloudRendererPropertiesWidget : public QgsPanelWidget, private Ui::QgsPointCloudRendererPropsDialogBase
class GUI_EXPORT QgsPointCloudRendererPropertiesWidget : public QgsMapLayerConfigWidget, private Ui::QgsPointCloudRendererPropsDialogBase
{
Q_OBJECT

Expand All @@ -50,6 +51,12 @@ class GUI_EXPORT QgsPointCloudRendererPropertiesWidget : public QgsPanelWidget,
*/
void setContext( const QgsSymbolWidgetContext &context );

void syncToLayer( QgsMapLayer *layer ) override { Q_UNUSED( layer ) }

public slots:

void apply() override {}

private:

QgsPointCloudLayer *mLayer = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/pointcloud/qgspointcloudrendererwidget.h
Expand Up @@ -49,7 +49,7 @@ class GUI_EXPORT QgsPointCloudRendererWidget : public QgsPanelWidget
*
* Caller takes ownership of the returned object.
*/
virtual QgsPointCloudRenderer *renderer() SIP_FACTORY = 0;
virtual QgsPointCloudRenderer *renderer() = 0 SIP_FACTORY;

/**
* Sets the \a context in which the renderer widget is shown, e.g., the associated map canvas and expression contexts.
Expand Down

0 comments on commit 1758ca1

Please sign in to comment.