34 #include <QtConcurrent>
35 #include <Qt3DCore/QTransform>
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 );
58 QgsDebugMsg( QStringLiteral(
"Unknown 3D symbol type for vector layer: " ) + mFactory->mSymbol->type() );
61 mHandler.reset( handler );
65 mContext.setExpressionContext( exprContext );
67 QSet<QString> attributeNames;
68 if ( !mHandler->prepare( mContext, attributeNames ) )
70 QgsDebugMsg( QStringLiteral(
"Failed to prepare 3D feature handler!" ) );
86 mFutureWatcher =
new QFutureWatcher<void>(
this );
87 connect( mFutureWatcher, &QFutureWatcher<void>::finished,
this, &QgsChunkQueueJob::finished );
89 const QFuture<void> future = QtConcurrent::run( [req,
this]
91 const QgsEventTracing::ScopedEvent e( QStringLiteral(
"3D" ), QStringLiteral(
"VL chunk load" ) );
99 mContext.expressionContext().setFeature( f );
100 mHandler->processFeature( f, mContext );
105 mFutureWatcher->setFuture( future );
108 QgsVectorLayerChunkLoader::~QgsVectorLayerChunkLoader()
110 if ( mFutureWatcher && !mFutureWatcher->isFinished() )
112 disconnect( mFutureWatcher, &QFutureWatcher<void>::finished,
this, &QgsChunkQueueJob::finished );
113 mFutureWatcher->waitForFinished();
117 void QgsVectorLayerChunkLoader::cancel()
122 Qt3DCore::QEntity *QgsVectorLayerChunkLoader::createEntity( Qt3DCore::QEntity *parent )
124 if ( mNode->level() < mFactory->mLeafLevel )
126 return new Qt3DCore::QEntity( parent );
129 if ( mHandler->featureCount() == 0 )
135 Qt3DCore::QEntity *entity =
new Qt3DCore::QEntity( parent );
136 mHandler->finalize( entity, mContext );
139 if ( mHandler->zMinimum() != std::numeric_limits<float>::max() && mHandler->zMaximum() != std::numeric_limits<float>::lowest() )
142 box.
yMin = mHandler->zMinimum();
143 box.
yMax = mHandler->zMaximum();
144 mNode->setExactBbox( box );
145 mNode->updateParentBoundingBoxesRecursively();
158 , mSymbol( symbol->clone() )
159 , mLeafLevel( leafLevel )
163 rootBbox.
xMin -= 1.0;
164 rootBbox.
xMax += 1.0;
165 rootBbox.
yMin -= 1.0;
166 rootBbox.
yMax += 1.0;
167 rootBbox.
zMin -= 1.0;
168 rootBbox.
zMax += 1.0;
169 setupQuadtree( rootBbox, -1, leafLevel );
172 QgsChunkLoader *QgsVectorLayerChunkLoaderFactory::createChunkLoader( QgsChunkNode *node )
const
174 return new QgsVectorLayerChunkLoader(
this, node );
182 : QgsChunkedEntity( -1,
183 new QgsVectorLayerChunkLoaderFactory( map, vl, symbol, tilingSettings.zoomLevelsCount() - 1, zMin, zMax ), true )
185 mTransform =
new Qt3DCore::QTransform;
187 this->addComponent( mTransform );
194 QgsVectorLayerChunkedEntity::~QgsVectorLayerChunkedEntity()
200 void QgsVectorLayerChunkedEntity::onTerrainElevationOffsetChanged(
float newOffset )
202 QgsDebugMsgLevel( QStringLiteral(
"QgsVectorLayerChunkedEntity::onTerrainElevationOffsetChanged" ), 2 );
203 mTransform->setTranslation( QVector3D( 0.0f, newOffset, 0.0f ) );