Skip to content

Commit

Permalink
rollback the existing implementation and use QgsHighlight
Browse files Browse the repository at this point in the history
  • Loading branch information
NEDJIMAbelgacem authored and nyalldawson committed Jan 17, 2021
1 parent 6de83cd commit bec8fe5
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 74 deletions.
10 changes: 0 additions & 10 deletions python/core/auto_generated/pointcloud/qgspointcloudlayer.sip.in
Expand Up @@ -130,16 +130,6 @@ Sets the 2D ``renderer`` for the point cloud.
Ownership of ``renderer`` is transferred to the layer.

.. seealso:: :py:func:`renderer`
%End

void setHighlightedPoints( const QVector<QPointF> &points );
%Docstring
Sets the points that will be highlighted when the layer is rendered
%End

QVector<QPointF> highlightedPoints() const;
%Docstring
Returns the list of the points that need to be highlighted when the layer is rendered
%End

private:
Expand Down
Expand Up @@ -26,7 +26,7 @@ Encapsulates the render context for a 2D point cloud rendering operation.
public:

QgsPointCloudRenderContext( QgsRenderContext &context, const QgsVector3D &scale, const QgsVector3D &offset,
double zValueScale, double zValueFixedOffset, const QVector<QPointF> &highlightedPoints );
double zValueScale, double zValueFixedOffset );
%Docstring
Constructor for QgsPointCloudRenderContext.

Expand Down Expand Up @@ -137,11 +137,6 @@ Returns any constant offset which must be applied to z values taken from the poi
Scaling of z values via :py:func:`~QgsPointCloudRenderContext.zValueScale` should be applied before the :py:func:`~QgsPointCloudRenderContext.zValueFixedOffset`.
%End

bool isPointHighlighted( const QPointF &p ) const;
%Docstring
Returns whether the point cloud point ``p`` should be highlighted
%End


private:
QgsPointCloudRenderContext( const QgsPointCloudRenderContext &rh );
Expand Down
23 changes: 22 additions & 1 deletion src/app/qgsidentifyresultsdialog.cpp
Expand Up @@ -1287,8 +1287,12 @@ void QgsIdentifyResultsDialog::addFeature( QgsPointCloudLayer *layer,
connect( layer, &QgsMapLayer::crsChanged, this, &QgsIdentifyResultsDialog::layerDestroyed );
}

QgsFeature feature;
QgsPointXY point( attributes[ QStringLiteral( "X" ) ].toDouble(), attributes[ QStringLiteral( "Y" ) ].toDouble() );
feature.setGeometry( QgsGeometry::fromPointXY( point ) );

QgsIdentifyResultsFeatureItem *featItem = new QgsIdentifyResultsFeatureItem( QgsFields(),
QgsFeature(),
feature,
layer->crs(),
QStringList() << label << QString() );
layItem->addChild( featItem );
Expand All @@ -1304,6 +1308,8 @@ void QgsIdentifyResultsDialog::addFeature( QgsPointCloudLayer *layer,
{
featItem->addChild( new QTreeWidgetItem( QStringList() << it.key() << it.value() ) );
}

highlightFeature( featItem );
}


Expand Down Expand Up @@ -1825,6 +1831,14 @@ QgsVectorTileLayer *QgsIdentifyResultsDialog::vectorTileLayer( QTreeWidgetItem *
return qobject_cast<QgsVectorTileLayer *>( item->data( 0, Qt::UserRole ).value<QObject *>() );
}

QgsPointCloudLayer *QgsIdentifyResultsDialog::pointCloudLayer( QTreeWidgetItem *item )
{
item = layerItem( item );
if ( !item )
return nullptr;
return qobject_cast<QgsPointCloudLayer *>( item->data( 0, Qt::UserRole ).value<QObject *>() );
}

QTreeWidgetItem *QgsIdentifyResultsDialog::retrieveAttributes( QTreeWidgetItem *item, QgsAttributeMap &attributes, int &idx )
{
QTreeWidgetItem *featItem = featureItem( item );
Expand Down Expand Up @@ -2054,9 +2068,11 @@ void QgsIdentifyResultsDialog::highlightFeature( QTreeWidgetItem *item )
QgsVectorLayer *vlayer = vectorLayer( item );
QgsRasterLayer *rlayer = rasterLayer( item );
QgsVectorTileLayer *vtlayer = vectorTileLayer( item );
QgsPointCloudLayer *pcLayer = pointCloudLayer( item );

layer = vlayer ? static_cast<QgsMapLayer *>( vlayer ) : static_cast<QgsMapLayer *>( rlayer );
layer = layer ? layer : vtlayer;
layer = layer ? layer : pcLayer;

if ( !layer ) return;

Expand All @@ -2075,6 +2091,11 @@ void QgsIdentifyResultsDialog::highlightFeature( QTreeWidgetItem *item )
{
highlight = new QgsHighlight( mCanvas, featItem->feature(), vlayer );
}
else if ( pcLayer )
{
highlight = new QgsHighlight( mCanvas, featItem->feature().geometry(), layer );
highlight->setWidth( 2 );
}
else
{
highlight = new QgsHighlight( mCanvas, featItem->feature().geometry(), layer );
Expand Down
1 change: 1 addition & 0 deletions src/app/qgsidentifyresultsdialog.h
Expand Up @@ -301,6 +301,7 @@ class APP_EXPORT QgsIdentifyResultsDialog: public QDialog, private Ui::QgsIdenti
QgsRasterLayer *rasterLayer( QTreeWidgetItem *item );
QgsMeshLayer *meshLayer( QTreeWidgetItem *item );
QgsVectorTileLayer *vectorTileLayer( QTreeWidgetItem *item );
QgsPointCloudLayer *pointCloudLayer( QTreeWidgetItem *item );
QTreeWidgetItem *featureItem( QTreeWidgetItem *item );
QTreeWidgetItem *layerItem( QTreeWidgetItem *item );
QTreeWidgetItem *layerItem( QObject *layer );
Expand Down
5 changes: 0 additions & 5 deletions src/core/pointcloud/qgspointcloudlayer.cpp
Expand Up @@ -621,8 +621,3 @@ void QgsPointCloudLayer::setRenderer( QgsPointCloudRenderer *renderer )
emit rendererChanged();
emit styleChanged();
}

void QgsPointCloudLayer::setHighlightedPoints( const QVector<QPointF> &points )
{
mHighlightedPoints = points;
}
12 changes: 0 additions & 12 deletions src/core/pointcloud/qgspointcloudlayer.h
Expand Up @@ -167,16 +167,6 @@ class CORE_EXPORT QgsPointCloudLayer : public QgsMapLayer
*/
void setRenderer( QgsPointCloudRenderer *renderer SIP_TRANSFER );

/**
* Sets the points that will be highlighted when the layer is rendered
*/
void setHighlightedPoints( const QVector<QPointF> &points );

/**
* Returns the list of the points that need to be highlighted when the layer is rendered
*/
QVector<QPointF> highlightedPoints() const { return mHighlightedPoints; }

private slots:
void onPointCloudIndexGenerationStateChanged( QgsPointCloudDataProvider::PointCloudIndexGenerationState state );

Expand All @@ -193,8 +183,6 @@ class CORE_EXPORT QgsPointCloudLayer : public QgsMapLayer
std::unique_ptr<QgsPointCloudRenderer> mRenderer;

QgsPointCloudLayerElevationProperties *mElevationProperties = nullptr;

QVector<QPointF> mHighlightedPoints;
};


Expand Down
2 changes: 1 addition & 1 deletion src/core/pointcloud/qgspointcloudlayerrenderer.cpp
Expand Up @@ -64,7 +64,7 @@ QgsPointCloudLayerRenderer::QgsPointCloudLayerRenderer( QgsPointCloudLayer *laye

bool QgsPointCloudLayerRenderer::render()
{
QgsPointCloudRenderContext context( *renderContext(), mScale, mOffset, mZScale, mZOffset, mLayer->highlightedPoints() );
QgsPointCloudRenderContext context( *renderContext(), mScale, mOffset, mZScale, mZOffset );

// Set up the render configuration options
QPainter *painter = context.renderContext().painter();
Expand Down
8 changes: 1 addition & 7 deletions src/core/pointcloud/qgspointcloudrenderer.cpp
Expand Up @@ -25,13 +25,12 @@
#include "qgslogger.h"
#include "qgscircle.h"

QgsPointCloudRenderContext::QgsPointCloudRenderContext( QgsRenderContext &context, const QgsVector3D &scale, const QgsVector3D &offset, double zValueScale, double zValueFixedOffset, const QVector<QPointF> &highlightedPoints )
QgsPointCloudRenderContext::QgsPointCloudRenderContext( QgsRenderContext &context, const QgsVector3D &scale, const QgsVector3D &offset, double zValueScale, double zValueFixedOffset )
: mRenderContext( context )
, mScale( scale )
, mOffset( offset )
, mZValueScale( zValueScale )
, mZValueFixedOffset( zValueFixedOffset )
, mHighlightedPoints( highlightedPoints )
{

}
Expand Down Expand Up @@ -152,8 +151,6 @@ QStringList QgsPointCloudRenderer::legendRuleKeys() const
return QStringList();
}



void QgsPointCloudRenderer::copyCommonProperties( QgsPointCloudRenderer *destination ) const
{
destination->setPointSize( mPointSize );
Expand Down Expand Up @@ -196,8 +193,6 @@ void QgsPointCloudRenderer::setPointSymbol( PointSymbol symbol )
mPointSymbol = symbol;
}



QVector<QVariantMap> QgsPointCloudRenderer::identify( QgsPointCloudLayer *layer, const QgsRenderContext &renderContext, const QgsGeometry &geometry, double toleranceForPointIdentification )
{
QVector<QVariantMap> selectedPoints;
Expand Down Expand Up @@ -286,4 +281,3 @@ QVector<QVariantMap> QgsPointCloudRenderer::identify( QgsPointCloudLayer *layer,

return selectedPoints;
}

25 changes: 1 addition & 24 deletions src/core/pointcloud/qgspointcloudrenderer.h
Expand Up @@ -57,7 +57,7 @@ class CORE_EXPORT QgsPointCloudRenderContext
* The \a highlightedPoints argument specifies highlighted points during rendering
*/
QgsPointCloudRenderContext( QgsRenderContext &context, const QgsVector3D &scale, const QgsVector3D &offset,
double zValueScale, double zValueFixedOffset, const QVector<QPointF> &highlightedPoints );
double zValueScale, double zValueFixedOffset );

//! QgsPointCloudRenderContext cannot be copied.
QgsPointCloudRenderContext( const QgsPointCloudRenderContext &rh ) = delete;
Expand Down Expand Up @@ -156,11 +156,6 @@ class CORE_EXPORT QgsPointCloudRenderContext
*/
double zValueFixedOffset() const { return mZValueFixedOffset; }

/**
* Returns whether the point cloud point \a p should be highlighted
*/
bool isPointHighlighted( const QPointF &p ) const { return mHighlightedPoints.contains( p ); }

#ifndef SIP_RUN

/**
Expand Down Expand Up @@ -215,8 +210,6 @@ class CORE_EXPORT QgsPointCloudRenderContext
int mZOffset = 0;
double mZValueScale = 1.0;
double mZValueFixedOffset = 0;

QVector<QPointF> mHighlightedPoints;
};


Expand Down Expand Up @@ -538,22 +531,6 @@ class CORE_EXPORT QgsPointCloudRenderer
mPainterPenWidth, mPainterPenWidth ) );
break;
};
if ( context.isPointHighlighted( originalXY ) )
{
QPen highlightPen( QColor( 255 - color.red(), 255 - color.green(), 255 - color.blue() ), 0.3 * mPainterPenWidth );
painter->setPen( highlightPen );
switch ( mPointSymbol )
{
case Square:
painter->drawRect( QRectF( x - mPainterPenWidth * 0.65, y - mPainterPenWidth * 0.65,
mPainterPenWidth * 1.3, mPainterPenWidth * 1.3 ) );
break;
case Circle:
painter->drawEllipse( QRectF( x - mPainterPenWidth * 0.65, y - mPainterPenWidth * 0.65,
mPainterPenWidth * 1.3, mPainterPenWidth * 1.3 ) );
break;
}
}
}

/**
Expand Down
8 changes: 0 additions & 8 deletions src/gui/qgsmaptoolidentify.cpp
Expand Up @@ -517,16 +517,8 @@ bool QgsMapToolIdentify::identifyPointCloudLayer( QList<QgsMapToolIdentify::Iden

const QVector<QVariantMap> points = renderer->identify( layer, context, geometry, searchRadiusMapUnits );

QVector<QPointF> highlightedPoints;
for ( const QVariantMap &point : points )
{
highlightedPoints.push_back( QPointF( point[QStringLiteral( "X" ) ].toDouble(), point[QStringLiteral( "Y" ) ].toDouble() ) );
}
layer->setHighlightedPoints( highlightedPoints );

fromPointCloudIdentificationToIdentifyResults( layer, points, *results );

layer->triggerRepaint();
return true;
}

Expand Down

0 comments on commit bec8fe5

Please sign in to comment.