30 QgsTerrainTextureGenerator::QgsTerrainTextureGenerator(
const Qgs3DMapSettings &map )
36 int QgsTerrainTextureGenerator::render(
const QgsRectangle &extent, QgsChunkNodeId tileId,
const QString &debugText )
39 mapSettings.setExtent( extent );
41 QgsEventTracing::addEvent( QgsEventTracing::AsyncBegin, QStringLiteral(
"3D" ), QStringLiteral(
"Texture" ), tileId.text() );
48 jobData.jobId = ++mLastJobId;
49 jobData.tileId = tileId;
51 jobData.extent = extent;
52 jobData.debugText = debugText;
54 mJobs.insert( job, jobData );
59 void QgsTerrainTextureGenerator::cancelJob(
int jobId )
61 Q_FOREACH (
const JobData &jd, mJobs )
63 if ( jd.jobId == jobId )
66 jd.job->cancelWithoutBlocking();
68 jd.job->deleteLater();
69 mJobs.remove( jd.job );
73 Q_ASSERT(
false &&
"requested job ID does not exist!" );
76 QImage QgsTerrainTextureGenerator::renderSynchronously(
const QgsRectangle &extent,
const QString &debugText )
79 mapSettings.setExtent( extent );
81 QImage img = QImage( mapSettings.outputSize(), mapSettings.outputImageFormat() );
82 img.setDotsPerMeterX( 1000 * mapSettings.outputDpi() / 25.4 );
83 img.setDotsPerMeterY( 1000 * mapSettings.outputDpi() / 25.4 );
84 img.fill( Qt::transparent );
89 job.renderSynchronously();
91 if ( mMap.showTerrainTilesInfo() )
94 p.setPen( Qt::white );
95 p.drawRect( 0, 0, img.width() - 1, img.height() - 1 );
96 p.drawText( img.rect(), debugText, QTextOption( Qt::AlignCenter ) );
105 void QgsTerrainTextureGenerator::onRenderingFinished()
109 Q_ASSERT( mJobs.contains( mapJob ) );
110 JobData jobData = mJobs.value( mapJob );
114 if ( mMap.showTerrainTilesInfo() )
118 p.setPen( Qt::white );
119 p.drawRect( 0, 0, img.width() - 1, img.height() - 1 );
120 p.drawText( img.rect(), jobData.debugText, QTextOption( Qt::AlignCenter ) );
124 mapJob->deleteLater();
125 mJobs.remove( mapJob );
129 QgsEventTracing::addEvent( QgsEventTracing::AsyncEnd, QStringLiteral(
"3D" ), QStringLiteral(
"Texture" ), jobData.tileId.text() );
132 emit tileReady( jobData.jobId, img );
139 mapSettings.
setOutputSize( QSize( mMap.mapTileResolution(), mMap.mapTileResolution() ) );
147 QString mapThemeName = mMap.terrainMapTheme();
148 if ( mapThemeName.isEmpty() || !mapThemes || !mapThemes->
hasMapTheme( mapThemeName ) )