Skip to content

Commit ee92e10

Browse files
committedJan 16, 2020
Updates based on PeterP's review
1 parent 1085810 commit ee92e10

12 files changed

+65
-43
lines changed
 

‎python/3d/auto_generated/qgsabstractvectorlayer3drenderer.sip.in

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,15 @@ Returns tiling settings of the renderer
100100
protected:
101101
void copyBaseProperties( QgsAbstractVectorLayer3DRenderer *r ) const;
102102
%Docstring
103-
copy common properties of this object to another object
103+
Copies common properties of this object to another object
104104
%End
105105
void writeXmlBaseProperties( QDomElement &elem, const QgsReadWriteContext &context ) const;
106106
%Docstring
107-
write common properties of this object to DOM element
107+
Writes common properties of this object to DOM element
108108
%End
109109
void readXmlBaseProperties( const QDomElement &elem, const QgsReadWriteContext &context );
110110
%Docstring
111-
read common properties of this object from DOM element
111+
Reads common properties of this object from DOM element
112112
%End
113113

114114
};

‎src/3d/qgs3dmapscene.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
#include <Qt3DCore/QEntity>
2222

23+
#include "qgsfeatureid.h"
24+
2325
namespace Qt3DRender
2426
{
2527
class QRenderSettings;
@@ -47,8 +49,6 @@ class Qgs3DMapSettings;
4749
class QgsTerrainEntity;
4850
class QgsChunkedEntity;
4951

50-
#include "qgsfeatureid.h"
51-
5252

5353
/**
5454
* \ingroup 3d
@@ -73,7 +73,10 @@ class _3D_EXPORT Qgs3DMapScene : public Qt3DCore::QEntity
7373
//! Returns number of pending jobs of the terrain entity
7474
int terrainPendingJobsCount() const;
7575

76-
//! Returns number of pending jobs for all chunked entities
76+
/**
77+
* Returns number of pending jobs for all chunked entities
78+
* \since QGIS 3.12
79+
*/
7780
int totalPendingJobsCount() const;
7881

7982
//! Enumeration of possible states of the 3D scene
@@ -102,7 +105,11 @@ class _3D_EXPORT Qgs3DMapScene : public Qt3DCore::QEntity
102105
void terrainEntityChanged();
103106
//! Emitted when the number of terrain's pending jobs changes
104107
void terrainPendingJobsCountChanged();
105-
//! Emitted when the total number of pending jobs changes
108+
109+
/**
110+
* Emitted when the total number of pending jobs changes
111+
* \since QGIS 3.12
112+
*/
106113
void totalPendingJobsCountChanged();
107114
//! Emitted when the scene's state has changed
108115
void sceneStateChanged();

‎src/3d/qgs3dutils.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ static QgsRectangle _tryReprojectExtent2D( const QgsRectangle &extent, const Qgs
456456
catch ( const QgsCsException & )
457457
{
458458
// bad luck, can't reproject for some reason
459+
QgsDebugMsg( QStringLiteral( "3D utils: transformation of extent failed: " ) + extentMapCrs.toString( -1 ) );
459460
}
460461
}
461462
return extentMapCrs;

‎src/3d/qgs3dutils.h

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,28 @@ class _3D_EXPORT Qgs3DUtils
131131
//! Converts 3D world coordinates to map coordinates (applies offset and turns (x,y,z) into (x,-z,y))
132132
static QgsVector3D worldToMapCoordinates( const QgsVector3D &worldCoords, const QgsVector3D &origin );
133133

134-
//! Converts extent (in map layer's CRS) to axis aligned bounding box in 3D world coordinates
134+
/**
135+
* Converts extent (in map layer's CRS) to axis aligned bounding box in 3D world coordinates
136+
* \since QGIS 3.12
137+
*/
135138
static QgsAABB layerToWorldExtent( const QgsRectangle &extent, double zMin, double zMax, const QgsCoordinateReferenceSystem &layerCrs, const QgsVector3D &mapOrigin, const QgsCoordinateReferenceSystem &mapCrs, const QgsCoordinateTransformContext &context );
136-
//! Converts axis aligned bounding box in 3D world coordinates to extent in map layer CRS
139+
140+
/**
141+
* Converts axis aligned bounding box in 3D world coordinates to extent in map layer CRS
142+
* \since QGIS 3.12
143+
*/
137144
static QgsRectangle worldToLayerExtent( const QgsAABB &bbox, const QgsCoordinateReferenceSystem &layerCrs, const QgsVector3D &mapOrigin, const QgsCoordinateReferenceSystem &mapCrs, const QgsCoordinateTransformContext &context );
138145

139-
//! Converts map extent to axis aligned bounding box in 3D world coordinates
146+
/**
147+
* Converts map extent to axis aligned bounding box in 3D world coordinates
148+
* \since QGIS 3.12
149+
*/
140150
static QgsAABB mapToWorldExtent( const QgsRectangle &extent, double zMin, double zMax, const QgsVector3D &mapOrigin );
141-
//! Converts axis aligned bounding box in 3D world coordinates to extent in map coordinates
151+
152+
/**
153+
* Converts axis aligned bounding box in 3D world coordinates to extent in map coordinates
154+
* \since QGIS 3.12
155+
*/
142156
static QgsRectangle worldToMapExtent( const QgsAABB &bbox, const QgsVector3D &mapOrigin );
143157

144158
//! Transforms a world point from (origin1, crs1) to (origin2, crs2)
@@ -150,6 +164,7 @@ class _3D_EXPORT Qgs3DUtils
150164
* The implementation scans a small amount of features and looks at the Z values of geometries
151165
* (we don't need exact range, just a rough estimate is fine to know where to expect the data to be).
152166
* For layers with geometries without Z values, the returned range will be [0, 0].
167+
* \since QGIS 3.12
153168
*/
154169
static void estimateVectorLayerZRange( QgsVectorLayer *layer, double &zMin, double &zMax );
155170

‎src/3d/qgsabstractvectorlayer3drenderer.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ void QgsVectorLayer3DTilingSettings::readXml( const QDomElement &elem )
4343
//////////////////
4444

4545

46-
QgsAbstractVectorLayer3DRenderer::QgsAbstractVectorLayer3DRenderer()
47-
{
48-
}
46+
QgsAbstractVectorLayer3DRenderer::QgsAbstractVectorLayer3DRenderer() = default;
4947

5048
void QgsAbstractVectorLayer3DRenderer::setLayer( QgsVectorLayer *layer )
5149
{

‎src/3d/qgsabstractvectorlayer3drenderer.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@ class _3D_EXPORT QgsAbstractVectorLayer3DRenderer : public QgsAbstract3DRenderer
9292
void resolveReferences( const QgsProject &project ) override;
9393

9494
protected:
95-
//! copy common properties of this object to another object
95+
//! Copies common properties of this object to another object
9696
void copyBaseProperties( QgsAbstractVectorLayer3DRenderer *r ) const;
97-
//! write common properties of this object to DOM element
97+
//! Writes common properties of this object to DOM element
9898
void writeXmlBaseProperties( QDomElement &elem, const QgsReadWriteContext &context ) const;
99-
//! read common properties of this object from DOM element
99+
//! Reads common properties of this object from DOM element
100100
void readXmlBaseProperties( const QDomElement &elem, const QgsReadWriteContext &context );
101101

102102
private:

‎src/3d/qgsrulebasedchunkloader_p.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ QgsRuleBasedChunkLoader::QgsRuleBasedChunkLoader( const QgsRuleBasedChunkLoaderF
7575

7676
QFuture<void> future = QtConcurrent::run( [req, this]
7777
{
78-
QgsEventTracing::ScopedEvent e( "3D", "RB chunk load" );
78+
QgsEventTracing::ScopedEvent e( QStringLiteral( "3D" ), QStringLiteral( "RB chunk load" ) );
7979

8080
QgsFeature f;
8181
QgsFeatureIterator fi = mSource->getFeatures( req );
@@ -155,9 +155,7 @@ QgsRuleBasedChunkLoaderFactory::QgsRuleBasedChunkLoaderFactory( const Qgs3DMapSe
155155
{
156156
}
157157

158-
QgsRuleBasedChunkLoaderFactory::~QgsRuleBasedChunkLoaderFactory()
159-
{
160-
}
158+
QgsRuleBasedChunkLoaderFactory::~QgsRuleBasedChunkLoaderFactory() = default;
161159

162160
QgsChunkLoader *QgsRuleBasedChunkLoaderFactory::createChunkLoader( QgsChunkNode *node ) const
163161
{

‎src/3d/qgsrulebasedchunkloader_p.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,14 @@
3030
#include "qgschunkloader_p.h"
3131
#include "qgsfeature3dhandler_p.h"
3232
#include "qgschunkedentity_p.h"
33+
#include "qgsrulebased3drenderer.h"
3334

3435
class Qgs3DMapSettings;
3536
class QgsVectorLayer;
3637
class QgsVectorLayerFeatureSource;
3738
class QgsAbstract3DSymbol;
3839
class QgsFeature3DHandler;
3940

40-
#include "qgsrulebased3drenderer.h"
41-
4241

4342
/**
4443
* \ingroup 3d
@@ -50,7 +49,7 @@ class QgsFeature3DHandler;
5049
class QgsRuleBasedChunkLoaderFactory : public QgsChunkLoaderFactory
5150
{
5251
public:
53-
//! Constructs the factory
52+
//! Constructs the factory (vl and rootRule must not be null)
5453
QgsRuleBasedChunkLoaderFactory( const Qgs3DMapSettings &map, QgsVectorLayer *vl, QgsRuleBased3DRenderer::Rule *rootRule, int leafLevel );
5554
~QgsRuleBasedChunkLoaderFactory() override;
5655

@@ -75,7 +74,7 @@ class QgsRuleBasedChunkLoaderFactory : public QgsChunkLoaderFactory
7574
class QgsRuleBasedChunkLoader : public QgsChunkLoader
7675
{
7776
public:
78-
//! Constructs the loader
77+
//! Constructs the loader (factory and node must not be null)
7978
QgsRuleBasedChunkLoader( const QgsRuleBasedChunkLoaderFactory *factory, QgsChunkNode *node );
8079
~QgsRuleBasedChunkLoader() override;
8180

‎src/3d/qgsvectorlayerchunkloader_p.cpp

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include "qgschunknode_p.h"
2121
#include "qgspolygon3dsymbol_p.h"
2222
#include "qgseventtracing.h"
23-
23+
#include "qgslogger.h"
2424
#include "qgsvectorlayer.h"
2525
#include "qgsvectorlayerfeatureiterator.h"
2626

@@ -52,22 +52,31 @@ QgsVectorLayerChunkLoader::QgsVectorLayerChunkLoader( const QgsVectorLayerChunkL
5252
QgsVectorLayer *layer = mFactory->mLayer;
5353
const Qgs3DMapSettings &map = mFactory->mMap;
5454

55-
if ( mFactory->mSymbol->type() == QLatin1String( "polygon" ) )
56-
mHandler = Qgs3DSymbolImpl::handlerForPolygon3DSymbol( layer, *static_cast<QgsPolygon3DSymbol *>( mFactory->mSymbol.get() ) );
57-
else if ( mFactory->mSymbol->type() == QLatin1String( "point" ) )
58-
mHandler = Qgs3DSymbolImpl::handlerForPoint3DSymbol( layer, *static_cast<QgsPoint3DSymbol *>( mFactory->mSymbol.get() ) );
59-
else if ( mFactory->mSymbol->type() == QLatin1String( "line" ) )
60-
mHandler = Qgs3DSymbolImpl::handlerForLine3DSymbol( layer, *static_cast<QgsLine3DSymbol *>( mFactory->mSymbol.get() ) );
55+
QgsFeature3DHandler *handler = nullptr;
56+
QString symbolType = mFactory->mSymbol->type();
57+
if ( symbolType == QLatin1String( "polygon" ) )
58+
handler = Qgs3DSymbolImpl::handlerForPolygon3DSymbol( layer, *static_cast<QgsPolygon3DSymbol *>( mFactory->mSymbol.get() ) );
59+
else if ( symbolType == QLatin1String( "point" ) )
60+
handler = Qgs3DSymbolImpl::handlerForPoint3DSymbol( layer, *static_cast<QgsPoint3DSymbol *>( mFactory->mSymbol.get() ) );
61+
else if ( symbolType == QLatin1String( "line" ) )
62+
handler = Qgs3DSymbolImpl::handlerForLine3DSymbol( layer, *static_cast<QgsLine3DSymbol *>( mFactory->mSymbol.get() ) );
6163
else
62-
return; // TODO: how to handle error
64+
{
65+
QgsDebugMsg( QStringLiteral( "Unknown 3D symbol type for vector layer: " ) + symbolType );
66+
return;
67+
}
68+
mHandler.reset( handler );
6369

6470
QgsExpressionContext exprContext( Qgs3DUtils::globalProjectLayerExpressionContext( layer ) );
6571
exprContext.setFields( layer->fields() );
6672
mContext.setExpressionContext( exprContext );
6773

6874
QSet<QString> attributeNames;
6975
if ( !mHandler->prepare( mContext, attributeNames ) )
70-
return; // TODO: how to handle errors
76+
{
77+
QgsDebugMsg( QStringLiteral( "Failed to prepare 3D feature handler!" ) );
78+
return;
79+
}
7180

7281
// build the feature request
7382
QgsFeatureRequest req;
@@ -84,7 +93,7 @@ QgsVectorLayerChunkLoader::QgsVectorLayerChunkLoader( const QgsVectorLayerChunkL
8493

8594
QFuture<void> future = QtConcurrent::run( [req, this]
8695
{
87-
QgsEventTracing::ScopedEvent e( "3D", "VL chunk load" );
96+
QgsEventTracing::ScopedEvent e( QStringLiteral( "3D" ), QStringLiteral( "VL chunk load" ) );
8897

8998
QgsFeature f;
9099
QgsFeatureIterator fi = mSource->getFeatures( req );
@@ -110,9 +119,6 @@ QgsVectorLayerChunkLoader::~QgsVectorLayerChunkLoader()
110119
disconnect( mFutureWatcher, &QFutureWatcher<void>::finished, this, &QgsChunkQueueJob::finished );
111120
mFutureWatcher->waitForFinished();
112121
}
113-
114-
delete mHandler;
115-
mHandler = nullptr;
116122
}
117123

118124
void QgsVectorLayerChunkLoader::cancel()

‎src/3d/qgsvectorlayerchunkloader_p.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class QgsVectorLayerChunkLoader : public QgsChunkLoader
8484

8585
private:
8686
const QgsVectorLayerChunkLoaderFactory *mFactory;
87-
QgsFeature3DHandler *mHandler = nullptr;
87+
std::unique_ptr<QgsFeature3DHandler> mHandler;
8888
Qgs3DRenderContext mContext;
8989
std::unique_ptr<QgsVectorLayerFeatureSource> mSource;
9090
bool mCanceled = false;

‎src/3d/symbols/qgsline3dsymbol_p.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ void QgsBufferedLine3DSymbolHandler::finalize( Qt3DCore::QEntity *parent, const
167167

168168
void QgsBufferedLine3DSymbolHandler::makeEntity( Qt3DCore::QEntity *parent, const Qgs3DRenderContext &context, LineData &out, bool selected )
169169
{
170-
if ( !out.tessellator->dataVerticesCount() )
170+
if ( out.tessellator->dataVerticesCount() == 0 )
171171
return; // nothing to show - no need to create the entity
172172

173173
Qt3DExtras::QPhongMaterial *mat = _material( mSymbol );

‎src/3d/symbols/qgspolygon3dsymbol_p.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@
3737

3838
/// @cond PRIVATE
3939

40-
class QgsTessellator;
41-
4240

4341
class QgsPolygon3DSymbolHandler : public QgsFeature3DHandler
4442
{
@@ -218,7 +216,7 @@ void QgsPolygon3DSymbolHandler::finalize( Qt3DCore::QEntity *parent, const Qgs3D
218216

219217
void QgsPolygon3DSymbolHandler::makeEntity( Qt3DCore::QEntity *parent, const Qgs3DRenderContext &context, PolygonData &out, bool selected )
220218
{
221-
if ( !out.tessellator->dataVerticesCount() )
219+
if ( out.tessellator->dataVerticesCount() == 0 )
222220
return; // nothing to show - no need to create the entity
223221

224222
Qt3DExtras::QPhongMaterial *mat = material( mSymbol );

0 commit comments

Comments
 (0)
Please sign in to comment.