Skip to content

Commit

Permalink
Address more comments
Browse files Browse the repository at this point in the history
  • Loading branch information
uclaros authored and nyalldawson committed Jan 18, 2022
1 parent a28cd2c commit d1d148f
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 11 deletions.
7 changes: 7 additions & 0 deletions python/core/auto_additions/qgspointcloudrenderer.py
@@ -0,0 +1,7 @@
# The following has been generated automatically from src/core/pointcloud/qgspointcloudrenderer.h
# monkey patching scoped based enum
QgsPointCloudRenderer.DrawOrder.Default.__doc__ = "Draw points in the order they are stored"
QgsPointCloudRenderer.DrawOrder.BottomToTop.__doc__ = "Draw points with larger Z values last"
QgsPointCloudRenderer.DrawOrder.TopToBottom.__doc__ = "Draw points with larger Z values first"
QgsPointCloudRenderer.DrawOrder.__doc__ = 'Pointcloud rendering order for 2d views\n/since QGIS 3.24\n\n' + '* ``Default``: ' + QgsPointCloudRenderer.DrawOrder.Default.__doc__ + '\n' + '* ``BottomToTop``: ' + QgsPointCloudRenderer.DrawOrder.BottomToTop.__doc__ + '\n' + '* ``TopToBottom``: ' + QgsPointCloudRenderer.DrawOrder.TopToBottom.__doc__
# --
Expand Up @@ -197,7 +197,7 @@ Abstract base class for 2d point cloud renderers.
Circle,
};

enum DrawOrder
enum class DrawOrder
{
Default,
BottomToTop,
Expand Down
16 changes: 12 additions & 4 deletions src/core/pointcloud/qgspointcloudlayerrenderer.cpp
Expand Up @@ -446,13 +446,21 @@ int QgsPointCloudLayerRenderer::renderNodesSorted( const QVector<IndexedPointClo
if ( pointCount == 0 )
return 0;

if ( order == QgsPointCloudRenderer::DrawOrder::BottomToTop )
std::sort( allPairs.begin(), allPairs.end(), []( QPair<int, double> a, QPair<int, double> b ) { return a.second < b.second; } );
else if ( order == QgsPointCloudRenderer::DrawOrder::TopToBottom )
std::sort( allPairs.begin(), allPairs.end(), []( QPair<int, double> a, QPair<int, double> b ) { return a.second > b.second; } );
switch ( order )
{
case QgsPointCloudRenderer::DrawOrder::BottomToTop:
std::sort( allPairs.begin(), allPairs.end(), []( QPair<int, double> a, QPair<int, double> b ) { return a.second < b.second; } );
break;
case QgsPointCloudRenderer::DrawOrder::TopToBottom:
std::sort( allPairs.begin(), allPairs.end(), []( QPair<int, double> a, QPair<int, double> b ) { return a.second > b.second; } );
break;
case QgsPointCloudRenderer::DrawOrder::Default:
break;
}

// Now we can reconstruct a byte array sorted by Z value
QByteArray sortedByteArray;
sortedByteArray.reserve( allPairs.size() );
for ( QPair<int, double> pair : allPairs )
sortedByteArray.append( allByteArrays.mid( pair.first * recordSize, recordSize ) );

Expand Down
2 changes: 1 addition & 1 deletion src/core/pointcloud/qgspointcloudrenderer.cpp
Expand Up @@ -186,7 +186,7 @@ void QgsPointCloudRenderer::saveCommonProperties( QDomElement &element, const Qg
element.setAttribute( QStringLiteral( "maximumScreenError" ), qgsDoubleToString( mMaximumScreenError ) );
element.setAttribute( QStringLiteral( "maximumScreenErrorUnit" ), QgsUnitTypes::encodeUnit( mMaximumScreenErrorUnit ) );
element.setAttribute( QStringLiteral( "pointSymbol" ), QString::number( mPointSymbol ) );
element.setAttribute( QStringLiteral( "drawOrder2d" ), QString::number( mDrawOrder2d ) );
element.setAttribute( QStringLiteral( "drawOrder2d" ), QString::number( static_cast< int >( mDrawOrder2d ) ) );
}

QgsPointCloudRenderer::PointSymbol QgsPointCloudRenderer::pointSymbol() const
Expand Down
2 changes: 1 addition & 1 deletion src/core/pointcloud/qgspointcloudrenderer.h
Expand Up @@ -276,7 +276,7 @@ class CORE_EXPORT QgsPointCloudRenderer
* Pointcloud rendering order for 2d views
* /since QGIS 3.24
*/
enum DrawOrder
enum class DrawOrder : int
{
Default, //!< Draw points in the order they are stored
BottomToTop, //!< Draw points with larger Z values last
Expand Down
8 changes: 4 additions & 4 deletions src/gui/pointcloud/qgspointcloudrendererpropertieswidget.cpp
Expand Up @@ -101,9 +101,9 @@ QgsPointCloudRendererPropertiesWidget::QgsPointCloudRendererPropertiesWidget( Qg
connect( mPointSizeSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ), this, &QgsPointCloudRendererPropertiesWidget::emitWidgetChanged );
connect( mPointSizeUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsPointCloudRendererPropertiesWidget::emitWidgetChanged );

mDrawOrderComboBox->addItem( tr( "Default" ), QgsPointCloudRenderer::DrawOrder::Default );
mDrawOrderComboBox->addItem( tr( "Bottom to top" ), QgsPointCloudRenderer::DrawOrder::BottomToTop );
mDrawOrderComboBox->addItem( tr( "Top to bottom" ), QgsPointCloudRenderer::DrawOrder::TopToBottom );
mDrawOrderComboBox->addItem( tr( "Default" ), static_cast< int >( QgsPointCloudRenderer::DrawOrder::Default ) );
mDrawOrderComboBox->addItem( tr( "Bottom to Top" ), static_cast< int >( QgsPointCloudRenderer::DrawOrder::BottomToTop ) );
mDrawOrderComboBox->addItem( tr( "Top to Bottom" ), static_cast< int >( QgsPointCloudRenderer::DrawOrder::TopToBottom ) );

mMaxErrorUnitWidget->setUnits( QgsUnitTypes::RenderUnitList() << QgsUnitTypes::RenderMillimeters << QgsUnitTypes::RenderMetersInMapUnits << QgsUnitTypes::RenderMapUnits << QgsUnitTypes::RenderPixels
<< QgsUnitTypes::RenderPoints << QgsUnitTypes::RenderInches );
Expand Down Expand Up @@ -152,7 +152,7 @@ void QgsPointCloudRendererPropertiesWidget::syncToLayer( QgsMapLayer *layer )
mPointSizeUnitWidget->setMapUnitScale( mLayer->renderer()->pointSizeMapUnitScale() );

mPointStyleComboBox->setCurrentIndex( mPointStyleComboBox->findData( mLayer->renderer()->pointSymbol() ) );
mDrawOrderComboBox->setCurrentIndex( mDrawOrderComboBox->findData( mLayer->renderer()->drawOrder2d() ) );
mDrawOrderComboBox->setCurrentIndex( mDrawOrderComboBox->findData( static_cast< int >( mLayer->renderer()->drawOrder2d() ) ) );

mMaxErrorSpinBox->setValue( mLayer->renderer()->maximumScreenError() );
mMaxErrorUnitWidget->setUnit( mLayer->renderer()->maximumScreenErrorUnit() );
Expand Down

0 comments on commit d1d148f

Please sign in to comment.