Move useful point cloud renderer enums to Qgis namespace

This commit is contained in:
Nyall Dawson 2022-04-28 13:33:19 +10:00
parent 77052c6473
commit c35d17b6e4
11 changed files with 95 additions and 81 deletions

View File

@ -1500,3 +1500,19 @@ Qgis.ProfileGeneratorFlag.__doc__ = 'Flags that control the way the :py:class:`Q
Qgis.ProfileGeneratorFlag.baseClass = Qgis
Qgis.ProfileGeneratorFlags.baseClass = Qgis
ProfileGeneratorFlags = Qgis # dirty hack since SIP seems to introduce the flags in module
QgsPointCloudRenderer.PointSymbol = Qgis.PointCloudSymbol
Qgis.PointCloudSymbol.baseClass = Qgis
QgsPointCloudRenderer.DrawOrder = Qgis.PointCloudDrawOrder
# monkey patching scoped based enum
QgsPointCloudRenderer.Default = Qgis.PointCloudDrawOrder.Default
QgsPointCloudRenderer.Default.is_monkey_patched = True
QgsPointCloudRenderer.Default.__doc__ = "Draw points in the order they are stored"
QgsPointCloudRenderer.BottomToTop = Qgis.PointCloudDrawOrder.BottomToTop
QgsPointCloudRenderer.BottomToTop.is_monkey_patched = True
QgsPointCloudRenderer.BottomToTop.__doc__ = "Draw points with larger Z values last"
QgsPointCloudRenderer.TopToBottom = Qgis.PointCloudDrawOrder.TopToBottom
QgsPointCloudRenderer.TopToBottom.is_monkey_patched = True
QgsPointCloudRenderer.TopToBottom.__doc__ = "Draw points with larger Z values first"
Qgis.PointCloudDrawOrder.__doc__ = 'Pointcloud rendering order for 2d views\n\n/since QGIS 3.26\n\n' + '* ``Default``: ' + Qgis.PointCloudDrawOrder.Default.__doc__ + '\n' + '* ``BottomToTop``: ' + Qgis.PointCloudDrawOrder.BottomToTop.__doc__ + '\n' + '* ``TopToBottom``: ' + Qgis.PointCloudDrawOrder.TopToBottom.__doc__
# --
Qgis.PointCloudDrawOrder.baseClass = Qgis

View File

@ -1,7 +0,0 @@
# 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__
# --

View File

@ -191,19 +191,6 @@ Abstract base class for 2d point cloud renderers.
%End
public:
enum PointSymbol
{
Square,
Circle,
};
enum class DrawOrder
{
Default,
BottomToTop,
TopToBottom,
};
QgsPointCloudRenderer();
%Docstring
Constructor for QgsPointCloudRenderer.
@ -373,7 +360,7 @@ Returns the map unit scale used for the point size.
.. seealso:: :py:func:`pointSize`
%End
DrawOrder drawOrder2d() const;
Qgis::PointCloudDrawOrder drawOrder2d() const;
%Docstring
Returns the drawing order used by the renderer for drawing points.
@ -382,7 +369,7 @@ Returns the drawing order used by the renderer for drawing points.
.. versionadded:: 3.24
%End
void setDrawOrder2d( DrawOrder order );
void setDrawOrder2d( Qgis::PointCloudDrawOrder order );
%Docstring
Sets the drawing ``order`` used by the renderer for drawing points.
@ -391,14 +378,14 @@ Sets the drawing ``order`` used by the renderer for drawing points.
.. versionadded:: 3.24
%End
PointSymbol pointSymbol() const;
Qgis::PointCloudSymbol pointSymbol() const;
%Docstring
Returns the symbol used by the renderer for drawing points.
.. seealso:: :py:func:`setPointSymbol`
%End
void setPointSymbol( PointSymbol symbol );
void setPointSymbol( Qgis::PointCloudSymbol symbol );
%Docstring
Sets the ``symbol`` used by the renderer for drawing points.

View File

@ -1025,6 +1025,19 @@ The development version
typedef QFlags<Qgis::ProfileGeneratorFlag> ProfileGeneratorFlags;
enum PointCloudSymbol
{
Square,
Circle,
};
enum class PointCloudDrawOrder
{
Default,
BottomToTop,
TopToBottom,
};
static const double DEFAULT_SEARCH_RADIUS_MM;
static const float DEFAULT_MAPTOPIXEL_THRESHOLD;

View File

@ -117,8 +117,8 @@ bool QgsPointCloudLayerRenderer::render()
mAttributes.push_back( QgsPointCloudAttribute( QStringLiteral( "Y" ), QgsPointCloudAttribute::Int32 ) );
if ( !context.renderContext().zRange().isInfinite() ||
mRenderer->drawOrder2d() == QgsPointCloudRenderer::DrawOrder::BottomToTop ||
mRenderer->drawOrder2d() == QgsPointCloudRenderer::DrawOrder::TopToBottom )
mRenderer->drawOrder2d() == Qgis::PointCloudDrawOrder::BottomToTop ||
mRenderer->drawOrder2d() == Qgis::PointCloudDrawOrder::TopToBottom )
mAttributes.push_back( QgsPointCloudAttribute( QStringLiteral( "Z" ), QgsPointCloudAttribute::Int32 ) );
// collect attributes required by renderer
@ -193,13 +193,13 @@ bool QgsPointCloudLayerRenderer::render()
switch ( mRenderer->drawOrder2d() )
{
case QgsPointCloudRenderer::DrawOrder::BottomToTop:
case QgsPointCloudRenderer::DrawOrder::TopToBottom:
case Qgis::PointCloudDrawOrder::BottomToTop:
case Qgis::PointCloudDrawOrder::TopToBottom:
{
nodesDrawn += renderNodesSorted( nodes, pc, context, request, canceled, mRenderer->drawOrder2d() );
break;
}
case QgsPointCloudRenderer::DrawOrder::Default:
case Qgis::PointCloudDrawOrder::Default:
{
switch ( pc->accessType() )
{
@ -359,7 +359,7 @@ int QgsPointCloudLayerRenderer::renderNodesAsync( const QVector<IndexedPointClou
return nodesDrawn;
}
int QgsPointCloudLayerRenderer::renderNodesSorted( const QVector<IndexedPointCloudNode> &nodes, QgsPointCloudIndex *pc, QgsPointCloudRenderContext &context, QgsPointCloudRequest &request, bool &canceled, QgsPointCloudRenderer::DrawOrder order )
int QgsPointCloudLayerRenderer::renderNodesSorted( const QVector<IndexedPointCloudNode> &nodes, QgsPointCloudIndex *pc, QgsPointCloudRenderContext &context, QgsPointCloudRequest &request, bool &canceled, Qgis::PointCloudDrawOrder order )
{
int blockCount = 0;
int pointCount = 0;
@ -448,13 +448,13 @@ int QgsPointCloudLayerRenderer::renderNodesSorted( const QVector<IndexedPointClo
switch ( order )
{
case QgsPointCloudRenderer::DrawOrder::BottomToTop:
case Qgis::PointCloudDrawOrder::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:
case Qgis::PointCloudDrawOrder::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:
case Qgis::PointCloudDrawOrder::Default:
break;
}

View File

@ -74,7 +74,7 @@ class CORE_EXPORT QgsPointCloudLayerRenderer: public QgsMapLayerRenderer
QVector<IndexedPointCloudNode> traverseTree( const QgsPointCloudIndex *pc, const QgsRenderContext &context, IndexedPointCloudNode n, double maxErrorPixels, double nodeErrorPixels );
int renderNodesSync( const QVector<IndexedPointCloudNode> &nodes, QgsPointCloudIndex *pc, QgsPointCloudRenderContext &context, QgsPointCloudRequest &request, bool &canceled );
int renderNodesAsync( const QVector<IndexedPointCloudNode> &nodes, QgsPointCloudIndex *pc, QgsPointCloudRenderContext &context, QgsPointCloudRequest &request, bool &canceled );
int renderNodesSorted( const QVector<IndexedPointCloudNode> &nodes, QgsPointCloudIndex *pc, QgsPointCloudRenderContext &context, QgsPointCloudRequest &request, bool &canceled, QgsPointCloudRenderer::DrawOrder order );
int renderNodesSorted( const QVector<IndexedPointCloudNode> &nodes, QgsPointCloudIndex *pc, QgsPointCloudRenderContext &context, QgsPointCloudRequest &request, bool &canceled, Qgis::PointCloudDrawOrder order );
QgsPointCloudLayer *mLayer = nullptr;

View File

@ -97,12 +97,12 @@ void QgsPointCloudRenderer::startRender( QgsPointCloudRenderContext &context )
switch ( mPointSymbol )
{
case Square:
case Qgis::PointCloudSymbol::Square:
// for square point we always disable antialiasing -- it's not critical here and we benefit from the performance boost disabling it gives
context.renderContext().painter()->setRenderHint( QPainter::Antialiasing, false );
break;
case Circle:
case Qgis::PointCloudSymbol::Circle:
break;
}
}
@ -173,8 +173,8 @@ void QgsPointCloudRenderer::restoreCommonProperties( const QDomElement &element,
mMaximumScreenError = element.attribute( QStringLiteral( "maximumScreenError" ), QStringLiteral( "0.3" ) ).toDouble();
mMaximumScreenErrorUnit = QgsUnitTypes::decodeRenderUnit( element.attribute( QStringLiteral( "maximumScreenErrorUnit" ), QStringLiteral( "MM" ) ) );
mPointSymbol = static_cast< PointSymbol >( element.attribute( QStringLiteral( "pointSymbol" ), QStringLiteral( "0" ) ).toInt() );
mDrawOrder2d = static_cast< DrawOrder >( element.attribute( QStringLiteral( "drawOrder2d" ), QStringLiteral( "0" ) ).toInt() );
mPointSymbol = static_cast< Qgis::PointCloudSymbol >( element.attribute( QStringLiteral( "pointSymbol" ), QStringLiteral( "0" ) ).toInt() );
mDrawOrder2d = static_cast< Qgis::PointCloudDrawOrder >( element.attribute( QStringLiteral( "drawOrder2d" ), QStringLiteral( "0" ) ).toInt() );
}
void QgsPointCloudRenderer::saveCommonProperties( QDomElement &element, const QgsReadWriteContext & ) const
@ -189,22 +189,22 @@ void QgsPointCloudRenderer::saveCommonProperties( QDomElement &element, const Qg
element.setAttribute( QStringLiteral( "drawOrder2d" ), QString::number( static_cast< int >( mDrawOrder2d ) ) );
}
QgsPointCloudRenderer::PointSymbol QgsPointCloudRenderer::pointSymbol() const
Qgis::PointCloudSymbol QgsPointCloudRenderer::pointSymbol() const
{
return mPointSymbol;
}
void QgsPointCloudRenderer::setPointSymbol( PointSymbol symbol )
void QgsPointCloudRenderer::setPointSymbol( Qgis::PointCloudSymbol symbol )
{
mPointSymbol = symbol;
}
QgsPointCloudRenderer::DrawOrder QgsPointCloudRenderer::drawOrder2d() const
Qgis::PointCloudDrawOrder QgsPointCloudRenderer::drawOrder2d() const
{
return mDrawOrder2d;
}
void QgsPointCloudRenderer::setDrawOrder2d( DrawOrder order )
void QgsPointCloudRenderer::setDrawOrder2d( Qgis::PointCloudDrawOrder order )
{
mDrawOrder2d = order;
}
@ -261,7 +261,7 @@ QVector<QVariantMap> QgsPointCloudRenderer::identify( QgsPointCloudLayer *layer,
const double pointSizePixels = renderContext.convertToPainterUnits( mPointSize, mPointSizeUnit, mPointSizeMapUnitScale );
switch ( pointSymbol() )
{
case QgsPointCloudRenderer::PointSymbol::Square:
case Qgis::PointCloudSymbol::Square:
{
const QgsPointXY deviceCoords = renderContext.mapToPixel().transform( QgsPointXY( x, y ) );
const QgsPointXY point1( deviceCoords.x() - std::max( toleranceInPixels, pointSizePixels / 2.0 ), deviceCoords.y() - std::max( toleranceInPixels, pointSizePixels / 2.0 ) );
@ -272,7 +272,7 @@ QVector<QVariantMap> QgsPointCloudRenderer::identify( QgsPointCloudLayer *layer,
selectionGeometry = QgsGeometry::fromRect( pointRect );
break;
}
case QgsPointCloudRenderer::PointSymbol::Circle:
case Qgis::PointCloudSymbol::Circle:
{
const QgsPoint centerMapCoords( x, y );
const QgsPointXY deviceCoords = renderContext.mapToPixel().transform( centerMapCoords );

View File

@ -274,26 +274,6 @@ class CORE_EXPORT QgsPointCloudRenderer
public:
/**
* Rendering symbols for points.
*/
enum PointSymbol
{
Square, //!< Renders points as squares
Circle, //!< Renders points as circles
};
/**
* Pointcloud rendering order for 2d views
* /since QGIS 3.24
*/
enum class DrawOrder : int
{
Default, //!< Draw points in the order they are stored
BottomToTop, //!< Draw points with larger Z values last
TopToBottom, //!< Draw points with larger Z values first
};
/**
* Constructor for QgsPointCloudRenderer.
*/
@ -464,7 +444,7 @@ class CORE_EXPORT QgsPointCloudRenderer
* \see setDrawOrder2d()
* \since QGIS 3.24
*/
DrawOrder drawOrder2d() const;
Qgis::PointCloudDrawOrder drawOrder2d() const;
/**
* Sets the drawing \a order used by the renderer for drawing points.
@ -472,21 +452,21 @@ class CORE_EXPORT QgsPointCloudRenderer
* \see drawOrder2d()
* \since QGIS 3.24
*/
void setDrawOrder2d( DrawOrder order );
void setDrawOrder2d( Qgis::PointCloudDrawOrder order );
/**
* Returns the symbol used by the renderer for drawing points.
*
* \see setPointSymbol()
*/
PointSymbol pointSymbol() const;
Qgis::PointCloudSymbol pointSymbol() const;
/**
* Sets the \a symbol used by the renderer for drawing points.
*
* \see pointSymbol()
*/
void setPointSymbol( PointSymbol symbol );
void setPointSymbol( Qgis::PointCloudSymbol symbol );
/**
* Returns the maximum screen error allowed when rendering the point cloud.
@ -574,13 +554,13 @@ class CORE_EXPORT QgsPointCloudRenderer
QPainter *painter = context.renderContext().painter();
switch ( mPointSymbol )
{
case Square:
case Qgis::PointCloudSymbol::Square:
painter->fillRect( QRectF( x - mPainterPenWidth * 0.5,
y - mPainterPenWidth * 0.5,
mPainterPenWidth, mPainterPenWidth ), color );
break;
case Circle:
case Qgis::PointCloudSymbol::Circle:
painter->setBrush( QBrush( color ) );
painter->setPen( Qt::NoPen );
painter->drawEllipse( QRectF( x - mPainterPenWidth * 0.5,
@ -628,9 +608,9 @@ class CORE_EXPORT QgsPointCloudRenderer
QgsUnitTypes::RenderUnit mPointSizeUnit = QgsUnitTypes::RenderMillimeters;
QgsMapUnitScale mPointSizeMapUnitScale;
PointSymbol mPointSymbol = Square;
Qgis::PointCloudSymbol mPointSymbol = Qgis::PointCloudSymbol::Square;
int mPainterPenWidth = 1;
DrawOrder mDrawOrder2d = DrawOrder::Default;
Qgis::PointCloudDrawOrder mDrawOrder2d = Qgis::PointCloudDrawOrder::Default;
};
#endif // QGSPOINTCLOUDRENDERER_H

View File

@ -1689,6 +1689,31 @@ class CORE_EXPORT Qgis
Q_DECLARE_FLAGS( ProfileGeneratorFlags, ProfileGeneratorFlag )
Q_FLAG( ProfileGeneratorFlags )
/**
* Rendering symbols for point cloud points.
*
* \since QGIS 3.26
*/
enum PointCloudSymbol SIP_MONKEYPATCH_SCOPEENUM_UNNEST( QgsPointCloudRenderer, PointSymbol ) : int
{
Square, //!< Renders points as squares
Circle, //!< Renders points as circles
};
Q_ENUM( PointCloudSymbol )
/**
* Pointcloud rendering order for 2d views
*
* /since QGIS 3.26
*/
enum class PointCloudDrawOrder SIP_MONKEYPATCH_SCOPEENUM_UNNEST( QgsPointCloudRenderer, DrawOrder ) : int
{
Default, //!< Draw points in the order they are stored
BottomToTop, //!< Draw points with larger Z values last
TopToBottom, //!< Draw points with larger Z values first
};
Q_ENUM( PointCloudDrawOrder )
/**
* Identify search radius in mm
* \since QGIS 2.3

View File

@ -87,8 +87,8 @@ QgsPointCloudRendererPropertiesWidget::QgsPointCloudRendererPropertiesWidget( Qg
cboRenderers->setCurrentIndex( -1 ); // set no current renderer
mPointStyleComboBox->addItem( tr( "Square" ), QgsPointCloudRenderer::Square );
mPointStyleComboBox->addItem( tr( "Circle" ), QgsPointCloudRenderer::Circle );
mPointStyleComboBox->addItem( tr( "Square" ), Qgis::PointCloudSymbol::Square );
mPointStyleComboBox->addItem( tr( "Circle" ), Qgis::PointCloudSymbol::Circle );
connect( cboRenderers, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsPointCloudRendererPropertiesWidget::rendererChanged );
@ -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" ), 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 ) );
mDrawOrderComboBox->addItem( tr( "Default" ), static_cast< int >( Qgis::PointCloudDrawOrder::Default ) );
mDrawOrderComboBox->addItem( tr( "Bottom to Top" ), static_cast< int >( Qgis::PointCloudDrawOrder::BottomToTop ) );
mDrawOrderComboBox->addItem( tr( "Top to Bottom" ), static_cast< int >( Qgis::PointCloudDrawOrder::TopToBottom ) );
mMaxErrorUnitWidget->setUnits( QgsUnitTypes::RenderUnitList() << QgsUnitTypes::RenderMillimeters << QgsUnitTypes::RenderMetersInMapUnits << QgsUnitTypes::RenderMapUnits << QgsUnitTypes::RenderPixels
<< QgsUnitTypes::RenderPoints << QgsUnitTypes::RenderInches );
@ -185,11 +185,11 @@ void QgsPointCloudRendererPropertiesWidget::apply()
mLayer->renderer()->setPointSizeUnit( mPointSizeUnitWidget->unit() );
mLayer->renderer()->setPointSizeMapUnitScale( mPointSizeUnitWidget->getMapUnitScale() );
mLayer->renderer()->setPointSymbol( static_cast< QgsPointCloudRenderer::PointSymbol >( mPointStyleComboBox->currentData().toInt() ) );
mLayer->renderer()->setPointSymbol( static_cast< Qgis::PointCloudSymbol >( mPointStyleComboBox->currentData().toInt() ) );
mLayer->renderer()->setMaximumScreenError( mMaxErrorSpinBox->value() );
mLayer->renderer()->setMaximumScreenErrorUnit( mMaxErrorUnitWidget->unit() );
mLayer->renderer()->setDrawOrder2d( static_cast< QgsPointCloudRenderer::DrawOrder >( mDrawOrderComboBox->currentData().toInt() ) );
mLayer->renderer()->setDrawOrder2d( static_cast< Qgis::PointCloudDrawOrder >( mDrawOrderComboBox->currentData().toInt() ) );
}
void QgsPointCloudRendererPropertiesWidget::rendererChanged()

View File

@ -405,10 +405,10 @@ void QgsHighlight::paint( QPainter *p )
sizeUnit = QgsUnitTypes::RenderPixels;
switch ( pcRenderer->pointSymbol() )
{
case QgsPointCloudRenderer::PointSymbol::Circle:
case Qgis::PointCloudSymbol::Circle:
symbol = Circle;
break;
case QgsPointCloudRenderer::PointSymbol::Square:
case Qgis::PointCloudSymbol::Square:
symbol = Square;
break;
}