Remake overview vpc options

This commit is contained in:
Withalion 2024-12-12 13:17:43 +01:00 committed by Martin Dobias
parent efa8912b0b
commit 1d3f3bbb21
12 changed files with 147 additions and 46 deletions

View File

@ -11088,6 +11088,21 @@ Qgis.MouseHandlesAction.__doc__ = """Action to be performed by the mouse handles
# --
Qgis.MouseHandlesAction.baseClass = Qgis
# monkey patching scoped based enum
Qgis.PointCloudZoomOutBehavior.Extent.__doc__ = ""
Qgis.PointCloudZoomOutBehavior.Overview.__doc__ = ""
Qgis.PointCloudZoomOutBehavior.Both.__doc__ = ""
Qgis.PointCloudZoomOutBehavior.__doc__ = """Point cloud zoom out options
.. versionadded:: 3.42
* ``Extent``:
* ``Overview``:
* ``Both``:
"""
# --
Qgis.PointCloudZoomOutBehavior.baseClass = Qgis
# monkey patching scoped based enum
Qgis.MeshRangeLimit.NotSet.__doc__ = "User defined"
Qgis.MeshRangeLimit.MinimumMaximum.__doc__ = "Real min-max values"
Qgis.MeshRangeLimit.__doc__ = """Describes the limits used to compute mesh ranges (min/max values).

View File

@ -578,16 +578,16 @@ Returns the text format renderer is using for rendering labels
.. versionadded:: 3.42
%End
void setShowExtends( const bool show );
void setZoomOutBehavior( const Qgis::PointCloudZoomOutBehavior behavior );
%Docstring
Set whether the renderer should render point cloud extends instead of overview when zoomed out
Sets the renderer behavior when zoomed out
.. versionadded:: 3.42
%End
bool showExtends() const;
Qgis::PointCloudZoomOutBehavior zoomOutBehavior() const;
%Docstring
Returns whether the renderer renders point cloud extends instead of overview when zoomed out
Returns the renderer behavior when zoomed out
.. versionadded:: 3.42
%End

View File

@ -3249,6 +3249,13 @@ The development version
UpdatedCanvas,
};
enum class PointCloudZoomOutBehavior /BaseType=IntEnum/
{
Extent,
Overview,
Both
};
enum class PointCloudAccessType /BaseType=IntEnum/
{
Local,

View File

@ -578,16 +578,16 @@ Returns the text format renderer is using for rendering labels
.. versionadded:: 3.42
%End
void setShowExtends( const bool show );
void setZoomOutBehavior( const Qgis::PointCloudZoomOutBehavior behavior );
%Docstring
Set whether the renderer should render point cloud extends instead of overview when zoomed out
Sets the renderer behavior when zoomed out
.. versionadded:: 3.42
%End
bool showExtends() const;
Qgis::PointCloudZoomOutBehavior zoomOutBehavior() const;
%Docstring
Returns whether the renderer renders point cloud extends instead of overview when zoomed out
Returns the renderer behavior when zoomed out
.. versionadded:: 3.42
%End

View File

@ -3249,6 +3249,13 @@ The development version
UpdatedCanvas,
};
enum class PointCloudZoomOutBehavior
{
Extent,
Overview,
Both
};
enum class PointCloudAccessType
{
Local,

View File

@ -199,6 +199,7 @@ bool QgsPointCloudLayerRenderer::render()
}
else
{
// we can be sure this won't fail as we are rendering virtual point clouds in this branch
const QgsVirtualPointCloudProvider &vpcProvider = dynamic_cast<QgsVirtualPointCloudProvider &>( *mLayer->dataProvider() );
QVector< QgsPointCloudSubIndex > visibleIndexes;
for ( const auto &si : mSubIndexes )
@ -208,31 +209,37 @@ bool QgsPointCloudLayerRenderer::render()
visibleIndexes.append( si );
}
}
// if the overview of virtual point cloud exists and user hasn't requested point cloud extends we render overview,
// when we are zoomed out
const bool zoomedOut = renderExtent.width() > vpcProvider.averageSubIndexWidth() &&
renderExtent.height() > vpcProvider.averageSubIndexHeight();
// if the overview of virtual point cloud exists, and we are zoomed out, we render just overview
if ( vpcProvider.overview() != nullptr &&
!mRenderer->showExtends() &&
renderExtent.width() > vpcProvider.averageSubIndexWidth() &&
renderExtent.height() > vpcProvider.averageSubIndexHeight() )
mRenderer->zoomOutBehavior() == Qgis::PointCloudZoomOutBehavior::Overview &&
zoomedOut )
{
renderIndex( vpcProvider.overview() );
}
else
{
// if the overview of virtual point cloud exists, and we are zoomed out, but we want both overview and extents,
// we render overview
if ( vpcProvider.overview() != nullptr &&
mRenderer->zoomOutBehavior() == Qgis::PointCloudZoomOutBehavior::Both &&
zoomedOut )
{
renderIndex( vpcProvider.overview() );
}
mSubIndexExtentRenderer->startRender( context );
for ( const auto &si : visibleIndexes )
{
if ( canceled )
break;
QgsPointCloudIndex pc = si.index();
if ( ( !pc || !pc.isValid() || mRenderer->showExtends() ) &&
renderExtent.width() > vpcProvider.averageSubIndexWidth() &&
renderExtent.height() > vpcProvider.averageSubIndexHeight() )
QgsPointCloudIndex pc = si.index();
// if the index of point cloud is invalid, or we are zoomed out and want extents, we render the point cloud extent
if ( !pc || !pc.isValid() || ( ( mRenderer->zoomOutBehavior() == Qgis::PointCloudZoomOutBehavior::Extent || mRenderer->zoomOutBehavior() == Qgis::PointCloudZoomOutBehavior::Both ) &&
zoomedOut ) )
{
mSubIndexExtentRenderer->renderExtent( si.polygonBounds(), context );
// render the label of point cloud tile
if ( mSubIndexExtentRenderer->showLabels() )
{
mSubIndexExtentRenderer->renderLabel(
@ -241,6 +248,7 @@ bool QgsPointCloudLayerRenderer::render()
context );
}
}
// else we just render the visible point cloud
else
{
canceled = !renderIndex( pc );

View File

@ -25,6 +25,7 @@
#include "qgslogger.h"
#include "qgscircle.h"
#include "qgsunittypes.h"
#include "qgsvirtualpointcloudprovider.h"
#include <QThread>
#include <QPointer>
@ -68,7 +69,7 @@ QgsPointCloudRenderer::QgsPointCloudRenderer()
settings.setEnabled( true );
settings.setSize( 1 );
textFormat.setBuffer( settings );
mLabelTextFormat = ( textFormat );
mLabelTextFormat = textFormat;
}
QgsPointCloudRenderer *QgsPointCloudRenderer::load( QDomElement &element, const QgsReadWriteContext &context )
@ -218,7 +219,7 @@ void QgsPointCloudRenderer::copyCommonProperties( QgsPointCloudRenderer *destina
destination->setShowLabels( mShowLabels );
destination->setLabelTextFormat( mLabelTextFormat );
destination->setShowExtends( mShowExtends );
destination->setZoomOutBehavior( mZoomOutBehavior );
}
void QgsPointCloudRenderer::restoreCommonProperties( const QDomElement &element, const QgsReadWriteContext &context )
@ -243,7 +244,7 @@ void QgsPointCloudRenderer::restoreCommonProperties( const QDomElement &element,
mLabelTextFormat = QgsTextFormat();
mLabelTextFormat.readXml( element.firstChildElement( QStringLiteral( "text-style" ) ), context );
}
mShowExtends = element.attribute( QStringLiteral( "showExtends" ), QStringLiteral( "0" ) ).toInt();
mZoomOutBehavior = static_cast<Qgis::PointCloudZoomOutBehavior>( element.attribute( QStringLiteral( "zoomOutBehavior" ), QStringLiteral( "0" ) ).toInt() );
}
void QgsPointCloudRenderer::saveCommonProperties( QDomElement &element, const QgsReadWriteContext &context ) const
@ -269,7 +270,7 @@ void QgsPointCloudRenderer::saveCommonProperties( QDomElement &element, const Qg
QDomDocument doc = element.ownerDocument();
element.appendChild( mLabelTextFormat.writeXml( doc, context ) );
}
element.setAttribute( QStringLiteral( "showExtends" ), QString::number( mShowExtends ) );
element.setAttribute( QStringLiteral( "zoomOutBehavior" ), QString::number( static_cast<int>( mZoomOutBehavior ) ) );
}
Qgis::PointCloudSymbol QgsPointCloudRenderer::pointSymbol() const

View File

@ -702,16 +702,16 @@ class CORE_EXPORT QgsPointCloudRenderer
QgsTextFormat labelTextFormat() const { return mLabelTextFormat; }
/**
* Set whether the renderer should render point cloud extends instead of overview when zoomed out
* Sets the renderer behavior when zoomed out
* \since QGIS 3.42
*/
void setShowExtends( const bool show ) { mShowExtends = show; }
void setZoomOutBehavior( const Qgis::PointCloudZoomOutBehavior behavior ) { mZoomOutBehavior = behavior; }
/**
* Returns whether the renderer renders point cloud extends instead of overview when zoomed out
* Returns the renderer behavior when zoomed out
* \since QGIS 3.42
*/
bool showExtends() const { return mShowExtends; }
Qgis::PointCloudZoomOutBehavior zoomOutBehavior() const { return mZoomOutBehavior; }
protected:
@ -855,7 +855,7 @@ class CORE_EXPORT QgsPointCloudRenderer
bool mShowLabels = false;
QgsTextFormat mLabelTextFormat;
bool mShowExtends = false;
Qgis::PointCloudZoomOutBehavior mZoomOutBehavior = Qgis::PointCloudZoomOutBehavior::Extent;
};
#endif // QGSPOINTCLOUDRENDERER_H

View File

@ -538,7 +538,12 @@ QgsPointCloudRenderer *QgsVirtualPointCloudProvider::createRenderer( const QVari
if ( mAttributes.indexOf( QLatin1String( "Classification" ) ) >= 0 )
{
return new QgsPointCloudClassifiedRenderer( QStringLiteral( "Classification" ), QgsPointCloudClassifiedRenderer::defaultCategories() );
QgsPointCloudClassifiedRenderer *newRenderer = new QgsPointCloudClassifiedRenderer( QStringLiteral( "Classification" ), QgsPointCloudClassifiedRenderer::defaultCategories() );
if ( mOverview != nullptr )
{
newRenderer->setZoomOutBehavior( Qgis::PointCloudZoomOutBehavior::Overview );
}
return newRenderer;
}
return new QgsPointCloudExtentRenderer();

View File

@ -5734,6 +5734,18 @@ class CORE_EXPORT Qgis
};
Q_ENUM( PointCloudAccessType )
/**
* Point cloud zoom out options
* \since QGIS 3.42
*/
enum class PointCloudZoomOutBehavior : int
{
Extent,
Overview,
Both
};
Q_ENUM( PointCloudZoomOutBehavior )
/**
* Identify search radius in mm
*/

View File

@ -33,6 +33,7 @@
#include "qgsstyle.h"
#include "qgssymbolwidgetcontext.h"
#include "qgstextformatwidget.h"
#include "qgsvirtualpointcloudprovider.h"
static bool initPointCloudRenderer( const QString &name, QgsPointCloudRendererWidgetFunc f, const QString &iconName = QString() )
{
@ -125,12 +126,44 @@ QgsPointCloudRendererPropertiesWidget::QgsPointCloudRendererPropertiesWidget( Qg
connect( mHorizontalTriangleUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsPointCloudRendererPropertiesWidget::emitWidgetChanged );
// show virtual point cloud options only when vpc layer is selected
bool showVpcOptions = !mLayer->dataProvider()->subIndexes().isEmpty();
mVpcGroupBox->setVisible( showVpcOptions );
mLabelOptions->setDialogTitle( tr( "Customize label text" ) );
connect( mExtendsCheckBox, &QCheckBox::stateChanged, this, &QgsPointCloudRendererPropertiesWidget::emitWidgetChanged );
connect( mLabels, &QCheckBox::stateChanged, this, &QgsPointCloudRendererPropertiesWidget::emitWidgetChanged );
connect( mLabelOptions, &QgsFontButton::changed, this, &QgsPointCloudRendererPropertiesWidget::emitWidgetChanged );
if ( !mLayer->dataProvider()->subIndexes().isEmpty() )
{
mLabelOptions->setDialogTitle( tr( "Customize label text" ) );
connect( mLabels, &QCheckBox::stateChanged, this, &QgsPointCloudRendererPropertiesWidget::emitWidgetChanged );
connect( mLabelOptions, &QgsFontButton::changed, this, &QgsPointCloudRendererPropertiesWidget::emitWidgetChanged );
mZoomOutOptions->addItem( tr( "Show extents only" ), static_cast<int>( Qgis::PointCloudZoomOutBehavior::Extent ) );
try
{
const QgsVirtualPointCloudProvider &vpcProvider = dynamic_cast<QgsVirtualPointCloudProvider &>( *mLayer->dataProvider() );
if ( vpcProvider.overview() != nullptr )
{
mZoomOutOptions->addItem( tr( "Show overview only" ), static_cast<int>( Qgis::PointCloudZoomOutBehavior::Overview ) );
mZoomOutOptions->addItem( tr( "Show extents over overview" ), static_cast<int>( Qgis::PointCloudZoomOutBehavior::Both ) );
}
}
catch ( const std::bad_cast & )
{
mZoomOutOptions->setDisabled( true );
}
connect( mZoomOutOptions, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, [this]() {
Qgis::PointCloudZoomOutBehavior zoomOutBehavior = static_cast<Qgis::PointCloudZoomOutBehavior>( mZoomOutOptions->currentData().toInt() );
if ( zoomOutBehavior == Qgis::PointCloudZoomOutBehavior::Overview )
{
mLabels->setDisabled( true );
mLabelOptions->setDisabled( true );
}
else
{
mLabels->setDisabled( false );
mLabelOptions->setDisabled( false );
}
emitWidgetChanged();
} );
}
else
{
mVpcGroupBox->setVisible( false );
}
syncToLayer( layer );
}
@ -191,7 +224,17 @@ void QgsPointCloudRendererPropertiesWidget::syncToLayer( QgsMapLayer *layer )
{
mLabels->setChecked( mLayer->renderer()->showLabels() );
mLabelOptions->setTextFormat( mLayer->renderer()->labelTextFormat() );
mExtendsCheckBox->setChecked( mLayer->renderer()->showExtends() );
mZoomOutOptions->setCurrentIndex( static_cast<int>( mLayer->renderer()->zoomOutBehavior() ) );
if ( mLayer->renderer()->zoomOutBehavior() == Qgis::PointCloudZoomOutBehavior::Overview )
{
mLabels->setDisabled( true );
mLabelOptions->setDisabled( true );
}
else
{
mLabels->setDisabled( false );
mLabelOptions->setDisabled( false );
}
}
}
@ -235,7 +278,7 @@ void QgsPointCloudRendererPropertiesWidget::apply()
mLayer->renderer()->setShowLabels( mLabels->isChecked() );
mLayer->renderer()->setLabelTextFormat( mLabelOptions->textFormat() );
mLayer->renderer()->setShowExtends( mExtendsCheckBox->isChecked() );
mLayer->renderer()->setZoomOutBehavior( static_cast<Qgis::PointCloudZoomOutBehavior>( mZoomOutOptions->currentData().toInt() ) );
}
void QgsPointCloudRendererPropertiesWidget::rendererChanged()

View File

@ -181,13 +181,6 @@
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="1" column="0">
<widget class="QCheckBox" name="mLabels">
<property name="text">
<string>Show tile labels</string>
</property>
</widget>
</item>
<item row="1" column="1">
<spacer name="horizontalSpacer">
<property name="orientation">
@ -201,6 +194,9 @@
</property>
</spacer>
</item>
<item row="0" column="1" colspan="2">
<widget class="QComboBox" name="mZoomOutOptions"/>
</item>
<item row="1" column="2">
<widget class="QgsFontButton" name="mLabelOptions">
<property name="text">
@ -209,9 +205,16 @@
</widget>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="mExtendsCheckBox">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Show point cloud extends</string>
<string>When zoomed out</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="mLabels">
<property name="text">
<string>Show tile labels</string>
</property>
</widget>
</item>