28 #include <QtConcurrent>
29 #include <Qt3DCore/QTransform>
34 QgsRuleBasedChunkLoader::QgsRuleBasedChunkLoader(
const QgsRuleBasedChunkLoaderFactory *factory, QgsChunkNode *node )
35 : QgsChunkLoader( node )
37 , mContext( factory->mMap )
40 if ( node->level() < mFactory->mLeafLevel )
42 QTimer::singleShot( 0,
this, &QgsRuleBasedChunkLoader::finished );
50 exprContext.setFields( layer->
fields() );
51 mContext.setExpressionContext( exprContext );
57 mRootRule.reset( mFactory->mRootRule->clone() );
59 mRootRule->createHandlers( layer, mHandlers );
61 QSet<QString> attributeNames;
62 mRootRule->prepare( mContext, attributeNames, mHandlers );
76 mFutureWatcher =
new QFutureWatcher<void>(
this );
77 connect( mFutureWatcher, &QFutureWatcher<void>::finished,
this, &QgsChunkQueueJob::finished );
79 const QFuture<void> future = QtConcurrent::run( [req,
this]
81 const QgsEventTracing::ScopedEvent e( QStringLiteral(
"3D" ), QStringLiteral(
"RB chunk load" ) );
89 mContext.expressionContext().setFeature( f );
90 mRootRule->registerFeature( f, mContext, mHandlers );
95 mFutureWatcher->setFuture( future );
98 QgsRuleBasedChunkLoader::~QgsRuleBasedChunkLoader()
100 if ( mFutureWatcher && !mFutureWatcher->isFinished() )
102 disconnect( mFutureWatcher, &QFutureWatcher<void>::finished,
this, &QgsChunkQueueJob::finished );
103 mFutureWatcher->waitForFinished();
106 qDeleteAll( mHandlers );
110 void QgsRuleBasedChunkLoader::cancel()
115 Qt3DCore::QEntity *QgsRuleBasedChunkLoader::createEntity( Qt3DCore::QEntity *parent )
117 if ( mNode->level() < mFactory->mLeafLevel )
119 return new Qt3DCore::QEntity( parent );
122 float zMin = std::numeric_limits<float>::max();
123 float zMax = std::numeric_limits<float>::min();
125 Qt3DCore::QEntity *entity =
new Qt3DCore::QEntity( parent );
126 for ( QgsFeature3DHandler *handler : mHandlers.values() )
128 handler->finalize( entity, mContext );
129 if ( handler->zMinimum() < zMin )
130 zMin = handler->zMinimum();
131 if ( handler->zMaximum() > zMax )
132 zMax = handler->zMaximum();
136 if ( zMin != std::numeric_limits<float>::max() && zMax != std::numeric_limits<float>::min() )
141 mNode->setExactBbox( box );
154 , mRootRule( rootRule->clone() )
155 , mLeafLevel( leafLevel )
158 setupQuadtree( rootBbox, -1, leafLevel );
161 QgsRuleBasedChunkLoaderFactory::~QgsRuleBasedChunkLoaderFactory() =
default;
163 QgsChunkLoader *QgsRuleBasedChunkLoaderFactory::createChunkLoader( QgsChunkNode *node )
const
165 return new QgsRuleBasedChunkLoader(
this, node );
172 : QgsChunkedEntity( -1,
173 new QgsRuleBasedChunkLoaderFactory( map, vl, rootRule, tilingSettings.zoomLevelsCount() - 1, zMin, zMax ), true )
175 mTransform =
new Qt3DCore::QTransform;
177 this->addComponent( mTransform );
183 QgsRuleBasedChunkedEntity::~QgsRuleBasedChunkedEntity()
189 void QgsRuleBasedChunkedEntity::onTerrainElevationOffsetChanged(
float newOffset )
191 mTransform->setTranslation( QVector3D( 0.0f, newOffset, 0.0f ) );
float terrainElevationOffset() const
Returns the elevation offset of the terrain (used to move the terrain up or down)
void terrainElevationOffsetChanged(float newElevation)
Emitted when the terrain elevation offset is changed.
QgsCoordinateReferenceSystem crs() const
Returns coordinate reference system used in the 3D scene.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which stores various information regarding which datum tran...
QgsVector3D origin() const
Returns coordinates in map CRS at which 3D scene has origin (0,0,0)
static QgsRectangle worldToMapExtent(const QgsAABB &bbox, const QgsVector3D &mapOrigin)
Converts axis aligned bounding box in 3D world coordinates to extent in map coordinates.
static QgsAABB layerToWorldExtent(const QgsRectangle &extent, double zMin, double zMax, const QgsCoordinateReferenceSystem &layerCrs, const QgsVector3D &mapOrigin, const QgsCoordinateReferenceSystem &mapCrs, const QgsCoordinateTransformContext &context)
Converts extent (in map layer's CRS) to axis aligned bounding box in 3D world coordinates.
static QgsExpressionContext globalProjectLayerExpressionContext(QgsVectorLayer *layer)
Returns expression context for use in preparation of 3D data of a layer.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
This class wraps a request for features to a vector layer (or directly its vector data provider).
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
QgsFeatureRequest & setDestinationCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
Sets the destination crs for feature's geometries.
QgsFeatureRequest & setFilterRect(const QgsRectangle &rectangle)
Sets the rectangle from which features will be taken.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
QgsCoordinateReferenceSystem crs
A rectangle specified with double values.
bool showBoundingBoxes() const
Returns whether to display bounding boxes of entity's tiles (for debugging)
Partial snapshot of vector layer's state (only the members necessary for access to features)
Represents a vector layer which manages a vector based data sets.
QgsFields fields() const FINAL
Returns the list of fields of this layer.
QgsRectangle extent() const FINAL
Returns the extent of the layer.