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 );
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()