28 #include <QtConcurrent> 33 QgsRuleBasedChunkLoader::QgsRuleBasedChunkLoader(
const QgsRuleBasedChunkLoaderFactory *factory, QgsChunkNode *node )
34 : QgsChunkLoader( node )
36 , mContext( factory->mMap )
39 if ( node->level() < mFactory->mLeafLevel )
41 QTimer::singleShot( 0,
this, &QgsRuleBasedChunkLoader::finished );
49 exprContext.setFields( layer->
fields() );
50 mContext.setExpressionContext( exprContext );
56 mRootRule.reset( mFactory->mRootRule->clone() );
60 QSet<QString> attributeNames;
61 mRootRule->
prepare( mContext, attributeNames, mHandlers );
76 QFuture<void> future = QtConcurrent::run( [req,
this]
78 QgsEventTracing::ScopedEvent e( QStringLiteral(
"3D" ), QStringLiteral(
"RB chunk load" ) );
86 mContext.expressionContext().setFeature( f );
92 mFutureWatcher =
new QFutureWatcher<void>( this );
93 mFutureWatcher->setFuture( future );
94 connect( mFutureWatcher, &QFutureWatcher<void>::finished,
this, &QgsChunkQueueJob::finished );
97 QgsRuleBasedChunkLoader::~QgsRuleBasedChunkLoader()
99 if ( mFutureWatcher && !mFutureWatcher->isFinished() )
101 disconnect( mFutureWatcher, &QFutureWatcher<void>::finished,
this, &QgsChunkQueueJob::finished );
102 mFutureWatcher->waitForFinished();
105 qDeleteAll( mHandlers );
109 void QgsRuleBasedChunkLoader::cancel()
114 Qt3DCore::QEntity *QgsRuleBasedChunkLoader::createEntity( Qt3DCore::QEntity *parent )
116 if ( mNode->level() < mFactory->mLeafLevel )
118 return new Qt3DCore::QEntity( parent );
121 float zMin = std::numeric_limits<float>::max();
122 float zMax = std::numeric_limits<float>::min();
124 Qt3DCore::QEntity *entity =
new Qt3DCore::QEntity( parent );
125 for ( QgsFeature3DHandler *handler : mHandlers.values() )
127 handler->finalize( entity, mContext );
128 if ( handler->zMinimum() < zMin )
129 zMin = handler->zMinimum();
130 if ( handler->zMaximum() > zMax )
131 zMax = handler->zMaximum();
135 if ( zMin != std::numeric_limits<float>::max() && zMax != std::numeric_limits<float>::min() )
140 mNode->setExactBbox( box );
153 , mRootRule( rootRule->
clone() )
154 , mLeafLevel( leafLevel )
158 QgsRuleBasedChunkLoaderFactory::~QgsRuleBasedChunkLoaderFactory() =
default;
160 QgsChunkLoader *QgsRuleBasedChunkLoaderFactory::createChunkLoader( QgsChunkNode *node )
const 162 return new QgsRuleBasedChunkLoader(
this, node );
169 : QgsChunkedEntity(
Qgs3DUtils::layerToWorldExtent( vl->extent(), zMin, zMax, vl->
crs(), map.origin(), map.
crs(), map.transformContext() ),
172 tilingSettings.zoomLevelsCount() - 1,
173 new QgsRuleBasedChunkLoaderFactory( map, vl, rootRule, tilingSettings.zoomLevelsCount() - 1 ) )
178 QgsRuleBasedChunkedEntity::~QgsRuleBasedChunkedEntity()
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.
3 Axis-aligned bounding box - in world coords.
A rectangle specified with double values.
RegisterResult registerFeature(QgsFeature &feature, Qgs3DRenderContext &context, RuleToHandlerMap &handlers) const
register individual features
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
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...
void createHandlers(QgsVectorLayer *layer, RuleToHandlerMap &handlers) const
add handlers
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.
QgsRuleBased3DRenderer::Rule * rootRule()
Returns pointer to the root rule.
Partial snapshot of vector layer's state (only the members necessary for access to features) ...
void prepare(const Qgs3DRenderContext &context, QSet< QString > &attributeNames, RuleToHandlerMap &handlers) const
call prepare() on handlers and populate attributeNames
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.
QgsRuleBased3DRenderer * clone() const override
Returns a cloned instance.
bool nextFeature(QgsFeature &f)
Represents a vector layer which manages a vector based data sets.
3 Miscellaneous utility functions used from 3D code.