30 QgsTerrainTextureGenerator::QgsTerrainTextureGenerator(
const Qgs3DMapSettings &map )
33 , mTextureSize( QSize( mMap.mapTileResolution(), mMap.mapTileResolution() ) )
37 int QgsTerrainTextureGenerator::render(
const QgsRectangle &extent, QgsChunkNodeId tileId,
const QString &debugText )
40 mapSettings.setExtent( extent );
42 QgsEventTracing::addEvent( QgsEventTracing::AsyncBegin, QStringLiteral(
"3D" ), QStringLiteral(
"Texture" ), tileId.text() );
49 jobData.jobId = ++mLastJobId;
50 jobData.tileId = tileId;
52 jobData.extent = extent;
53 jobData.debugText = debugText;
55 mJobs.insert( job, jobData );
60 void QgsTerrainTextureGenerator::cancelJob(
int jobId )
62 Q_FOREACH (
const JobData &jd, mJobs )
64 if ( jd.jobId == jobId )
67 jd.job->cancelWithoutBlocking();
69 jd.job->deleteLater();
70 mJobs.remove( jd.job );
74 Q_ASSERT(
false &&
"requested job ID does not exist!" );
77 void QgsTerrainTextureGenerator::waitForFinished()
81 QVector<QgsMapRendererSequentialJob *> toBeDeleted;
84 mapJob->waitForFinished();
85 JobData jobData = mJobs.value( mapJob );
86 toBeDeleted.push_back( mapJob );
88 QImage img = mapJob->renderedImage();
90 if ( mMap.showTerrainTilesInfo() )
94 p.setPen( Qt::white );
95 p.drawRect( 0, 0, img.width() - 1, img.height() - 1 );
96 p.drawText( img.rect(), jobData.debugText, QTextOption( Qt::AlignCenter ) );
101 emit tileReady( jobData.jobId, img );
106 mJobs.remove( mapJob );
107 mapJob->deleteLater();
111 void QgsTerrainTextureGenerator::onRenderingFinished()
115 Q_ASSERT( mJobs.contains( mapJob ) );
116 JobData jobData = mJobs.value( mapJob );
120 if ( mMap.showTerrainTilesInfo() )
124 p.setPen( Qt::white );
125 p.drawRect( 0, 0, img.width() - 1, img.height() - 1 );
126 p.drawText( img.rect(), jobData.debugText, QTextOption( Qt::AlignCenter ) );
130 mapJob->deleteLater();
131 mJobs.remove( mapJob );
135 QgsEventTracing::addEvent( QgsEventTracing::AsyncEnd, QStringLiteral(
"3D" ), QStringLiteral(
"Texture" ), jobData.tileId.text() );
138 emit tileReady( jobData.jobId, img );
154 QString mapThemeName = mMap.terrainMapTheme();
155 if ( mapThemeName.isEmpty() || !mapThemes || !mapThemes->
hasMapTheme( mapThemeName ) )
157 mapSettings.
setLayers( mMap.terrainLayers() );