1 /***************************************************************************
2     qgspointcloudelevationpropertieswidget.cpp
3     ---------------------
4     begin                : December 2020
5     copyright            : (C) 2020 by Nyall Dawson
6     email                : nyall dot dawson at gmail dot com
7  ***************************************************************************
8  *                                                                         *
9  *   This program is free software; you can redistribute it and/or modify  *
10  *   it under the terms of the GNU General Public License as published by  *
11  *   the Free Software Foundation; either version 2 of the License, or     *
12  *   (at your option) any later version.                                   *
13  *                                                                         *
14  ***************************************************************************/
15 
16 #include "qgspointcloudelevationpropertieswidget.h"
17 #include "qgspointcloudrendererpropertieswidget.h"
18 #include "qgsstyle.h"
19 #include "qgsapplication.h"
20 #include "qgsmaplayer.h"
21 #include "qgspointcloudlayer.h"
22 #include "qgspointcloudlayerelevationproperties.h"
23 
QgsPointCloudElevationPropertiesWidget(QgsPointCloudLayer * layer,QgsMapCanvas * canvas,QWidget * parent)24 QgsPointCloudElevationPropertiesWidget::QgsPointCloudElevationPropertiesWidget( QgsPointCloudLayer *layer, QgsMapCanvas *canvas, QWidget *parent )
25   : QgsMapLayerConfigWidget( layer, canvas, parent )
26 {
27   setupUi( this );
28 
29   mOffsetZSpinBox->setClearValue( 0 );
30   mScaleZSpinBox->setClearValue( 1 );
31 
32   syncToLayer( layer );
33 
34   connect( mOffsetZSpinBox, qOverload<double >( &QDoubleSpinBox::valueChanged ), this, &QgsPointCloudElevationPropertiesWidget::onChanged );
35   connect( mScaleZSpinBox, qOverload<double >( &QDoubleSpinBox::valueChanged ), this, &QgsPointCloudElevationPropertiesWidget::onChanged );
36   connect( mShifPointCloudZAxisButton, &QPushButton::clicked, this, &QgsPointCloudElevationPropertiesWidget::shiftPointCloudZAxis );
37 }
38 
syncToLayer(QgsMapLayer * layer)39 void QgsPointCloudElevationPropertiesWidget::syncToLayer( QgsMapLayer *layer )
40 {
41   mLayer = qobject_cast< QgsPointCloudLayer * >( layer );
42   if ( !mLayer )
43     return;
44 
45   mBlockUpdates = true;
46   mOffsetZSpinBox->setValue( static_cast< const QgsPointCloudLayerElevationProperties * >( mLayer->elevationProperties() )->zOffset() );
47   mScaleZSpinBox->setValue( static_cast< const QgsPointCloudLayerElevationProperties * >( mLayer->elevationProperties() )->zScale() );
48   mBlockUpdates = false;
49 }
50 
apply()51 void QgsPointCloudElevationPropertiesWidget::apply()
52 {
53   if ( !mLayer )
54     return;
55 
56   static_cast< QgsPointCloudLayerElevationProperties * >( mLayer->elevationProperties() )->setZOffset( mOffsetZSpinBox->value() );
57   static_cast< QgsPointCloudLayerElevationProperties * >( mLayer->elevationProperties() )->setZScale( mScaleZSpinBox->value() );
58   mLayer->trigger3DUpdate();
59 }
60 
onChanged()61 void QgsPointCloudElevationPropertiesWidget::onChanged()
62 {
63   if ( !mBlockUpdates )
64     emit widgetChanged();
65 }
66 
shiftPointCloudZAxis()67 void QgsPointCloudElevationPropertiesWidget::shiftPointCloudZAxis()
68 {
69   const QgsDoubleRange range = mLayer->elevationProperties()->calculateZRange( mLayer );
70   if ( !range.isEmpty() )
71   {
72     mOffsetZSpinBox->setValue( -range.lower() + mOffsetZSpinBox->value() );
73   }
74 }
75 
76 //
77 // QgsPointCloudElevationPropertiesWidgetFactory
78 //
79 
QgsPointCloudElevationPropertiesWidgetFactory(QObject * parent)80 QgsPointCloudElevationPropertiesWidgetFactory::QgsPointCloudElevationPropertiesWidgetFactory( QObject *parent )
81   : QObject( parent )
82 {
83   setIcon( QgsApplication::getThemeIcon( QStringLiteral( "propertyicons/elevationscale.svg" ) ) );
84   setTitle( tr( "Elevation" ) );
85 }
86 
createWidget(QgsMapLayer * layer,QgsMapCanvas * canvas,bool,QWidget * parent) const87 QgsMapLayerConfigWidget *QgsPointCloudElevationPropertiesWidgetFactory::createWidget( QgsMapLayer *layer, QgsMapCanvas *canvas, bool, QWidget *parent ) const
88 {
89   return new QgsPointCloudElevationPropertiesWidget( qobject_cast< QgsPointCloudLayer * >( layer ), canvas, parent );
90 }
91 
supportLayerPropertiesDialog() const92 bool QgsPointCloudElevationPropertiesWidgetFactory::supportLayerPropertiesDialog() const
93 {
94   return true;
95 }
96 
supportsStyleDock() const97 bool QgsPointCloudElevationPropertiesWidgetFactory::supportsStyleDock() const
98 {
99   return true;
100 }
101 
supportsLayer(QgsMapLayer * layer) const102 bool QgsPointCloudElevationPropertiesWidgetFactory::supportsLayer( QgsMapLayer *layer ) const
103 {
104   return layer->type() == QgsMapLayerType::PointCloudLayer;
105 }
106 
layerPropertiesPagePositionHint() const107 QString QgsPointCloudElevationPropertiesWidgetFactory::layerPropertiesPagePositionHint() const
108 {
109   return QStringLiteral( "mOptsPage_Metadata" );
110 }
111 
112