35 #include <QtConcurrent> 40 QgsVectorLayerChunkLoader::QgsVectorLayerChunkLoader(
const QgsVectorLayerChunkLoaderFactory *factory, QgsChunkNode *node )
41 : QgsChunkLoader( node )
43 , mContext( factory->mMap )
46 if ( node->level() < mFactory->mLeafLevel )
48 QTimer::singleShot( 0,
this, &QgsVectorLayerChunkLoader::finished );
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() ) );
65 QgsDebugMsg( QStringLiteral(
"Unknown 3D symbol type for vector layer: " ) + symbolType );
68 mHandler.reset( handler );
71 exprContext.setFields( layer->
fields() );
72 mContext.setExpressionContext( exprContext );
74 QSet<QString> attributeNames;
75 if ( !mHandler->prepare( mContext, attributeNames ) )
77 QgsDebugMsg( QStringLiteral(
"Failed to prepare 3D feature handler!" ) );
94 QFuture<void> future = QtConcurrent::run( [req,
this]
96 QgsEventTracing::ScopedEvent e( QStringLiteral(
"3D" ), QStringLiteral(
"VL chunk load" ) );
104 mContext.expressionContext().setFeature( f );
105 mHandler->processFeature( f, mContext );
110 mFutureWatcher =
new QFutureWatcher<void>( this );
111 mFutureWatcher->setFuture( future );
112 connect( mFutureWatcher, &QFutureWatcher<void>::finished,
this, &QgsChunkQueueJob::finished );
115 QgsVectorLayerChunkLoader::~QgsVectorLayerChunkLoader()
117 if ( mFutureWatcher && !mFutureWatcher->isFinished() )
119 disconnect( mFutureWatcher, &QFutureWatcher<void>::finished,
this, &QgsChunkQueueJob::finished );
120 mFutureWatcher->waitForFinished();
124 void QgsVectorLayerChunkLoader::cancel()
129 Qt3DCore::QEntity *QgsVectorLayerChunkLoader::createEntity( Qt3DCore::QEntity *parent )
131 if ( mNode->level() < mFactory->mLeafLevel )
133 return new Qt3DCore::QEntity( parent );
136 Qt3DCore::QEntity *entity =
new Qt3DCore::QEntity( parent );
137 mHandler->finalize( entity, mContext );
148 , mSymbol( symbol->
clone() )
149 , mLeafLevel( leafLevel )
153 QgsChunkLoader *QgsVectorLayerChunkLoaderFactory::createChunkLoader( QgsChunkNode *node )
const 155 return new QgsVectorLayerChunkLoader(
this, node );
163 : QgsChunkedEntity(
Qgs3DUtils::layerToWorldExtent( vl->extent(), zMin, zMax, vl->
crs(), map.origin(), map.
crs(), map.transformContext() ),
166 tilingSettings.zoomLevelsCount() - 1,
167 new QgsVectorLayerChunkLoaderFactory( map, vl, symbol, tilingSettings.zoomLevelsCount() - 1 ) )
172 QgsVectorLayerChunkedEntity::~QgsVectorLayerChunkedEntity()
QgsFeatureRequest & setDestinationCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
Sets the destination crs for feature's geometries.
Wrapper for iterator of features from vector data provider or vector layer.
A rectangle specified with double values.
QgsCoordinateReferenceSystem crs() const
Returns coordinate reference system used in the 3D scene.
QgsVectorLayer3DTilingSettings tilingSettings() const
Returns tiling settings of the renderer.
bool showBoundingBoxes() const
Returns whether to display bounding boxes of entity's tiles (for debugging)
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
3 This class defines configuration of how a vector layer gets tiled for 3D rendering.
QgsVectorLayer * layer() const
Returns vector layer associated with the renderer.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
const QgsCoordinateReferenceSystem & crs
3 Definition of the world
3 Abstract base class for 3D symbols that are used by VectorLayer3DRenderer objects.
QgsVectorLayer3DRenderer * clone() const override
Returns a cloned instance.
QgsVector3D origin() const
Returns coordinates in map CRS at which 3D scene has origin (0,0,0)
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which stores various information regarding which datum tran...
QgsFields fields() const FINAL
Returns the list of fields of this layer.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
This class wraps a request for features to a vector layer (or directly its vector data provider)...
QgsFeatureRequest & setFilterRect(const QgsRectangle &rectangle)
Sets the rectangle from which features will be taken.
const QgsAbstract3DSymbol * symbol() const
Returns 3D symbol associated with the renderer.
Partial snapshot of vector layer's state (only the members necessary for access to features) ...
static QgsRectangle worldToLayerExtent(const QgsAABB &bbox, const QgsCoordinateReferenceSystem &layerCrs, const QgsVector3D &mapOrigin, const QgsCoordinateReferenceSystem &mapCrs, const QgsCoordinateTransformContext &context)
Converts axis aligned bounding box in 3D world coordinates to extent in map layer CRS...
static QgsExpressionContext globalProjectLayerExpressionContext(QgsVectorLayer *layer)
Returns expression context for use in preparation of 3D data of a layer.
bool nextFeature(QgsFeature &f)
Represents a vector layer which manages a vector based data sets.
3 Miscellaneous utility functions used from 3D code.