30QgsTerrainTextureGenerator::QgsTerrainTextureGenerator(
const Qgs3DMapSettings &map )
33 , mTextureSize( QSize( mMap.mapTileResolution(), mMap.mapTileResolution() ) )
37int QgsTerrainTextureGenerator::render(
const QgsRectangle &extent, QgsChunkNodeId tileId,
const QString &debugText )
40 mapSettings.setExtent( extent );
42 QList<QgsMapLayer *> layers = mMap.layers();
43 QList<QgsMapLayer *> toBeRenderedLayers;
46 if ( l->renderer3D() ==
nullptr )
47 toBeRenderedLayers.push_back( l );
49 mapSettings.setLayers( toBeRenderedLayers );
51 QgsEventTracing::addEvent( QgsEventTracing::AsyncBegin, QStringLiteral(
"3D" ), QStringLiteral(
"Texture" ), tileId.text() );
57 jobData.jobId = ++mLastJobId;
58 jobData.tileId = tileId;
60 jobData.extent = extent;
61 jobData.debugText = debugText;
63 mJobs.insert( job, jobData );
70void QgsTerrainTextureGenerator::cancelJob(
int jobId )
72 for (
const JobData &jd : std::as_const( mJobs ) )
74 if ( jd.jobId == jobId )
77 jd.job->cancelWithoutBlocking();
79 jd.job->deleteLater();
80 mJobs.remove( jd.job );
84 Q_ASSERT(
false &&
"requested job ID does not exist!" );
87void QgsTerrainTextureGenerator::waitForFinished()
91 QVector<QgsMapRendererSequentialJob *> toBeDeleted;
94 mapJob->waitForFinished();
95 JobData jobData = mJobs.value( mapJob );
96 toBeDeleted.push_back( mapJob );
98 QImage img = mapJob->renderedImage();
100 if ( mMap.showTerrainTilesInfo() )
104 p.setPen( Qt::white );
105 p.drawRect( 0, 0, img.width() - 1, img.height() - 1 );
106 p.drawText( img.rect(), jobData.debugText, QTextOption( Qt::AlignCenter ) );
111 emit tileReady( jobData.jobId, img );
116 mJobs.remove( mapJob );
117 mapJob->deleteLater();
121void QgsTerrainTextureGenerator::onRenderingFinished()
125 Q_ASSERT( mJobs.contains( mapJob ) );
126 JobData jobData = mJobs.value( mapJob );
130 if ( mMap.showTerrainTilesInfo() )
134 p.setPen( Qt::white );
135 p.drawRect( 0, 0, img.width() - 1, img.height() - 1 );
136 p.drawText( img.rect(), jobData.debugText, QTextOption( Qt::AlignCenter ) );
140 mapJob->deleteLater();
141 mJobs.remove( mapJob );
145 QgsEventTracing::addEvent( QgsEventTracing::AsyncEnd, QStringLiteral(
"3D" ), QStringLiteral(
"Texture" ), jobData.tileId.text() );
148 emit tileReady( jobData.jobId, img );
165 QString mapThemeName = mMap.terrainMapTheme();
166 if ( mapThemeName.isEmpty() || !mapThemes || !mapThemes->
hasMapTheme( mapThemeName ) )
@ DrawLabeling
Enable drawing of labels on top of the map.
@ Render3DMap
Render is for a 3D map.
Base class for all map layer types.
void finished()
emitted when asynchronous rendering is finished (or canceled).
void start()
Start the rendering job and immediately return.
Job implementation that renders everything sequentially in one thread.
QImage renderedImage() override
Gets a preview/resulting image.
The QgsMapSettings class contains configuration for rendering of the map.
void setLayers(const QList< QgsMapLayer * > &layers)
Sets the list of layers to render in the map.
void setRendererUsage(Qgis::RendererUsage rendererUsage)
Sets the rendering usage.
void setLayerStyleOverrides(const QMap< QString, QString > &overrides)
Sets the map of map layer style overrides (key: layer ID, value: style name) where a different style ...
void setTransformContext(const QgsCoordinateTransformContext &context)
Sets the coordinate transform context, which stores various information regarding which datum transfo...
void setPathResolver(const QgsPathResolver &resolver)
Sets the path resolver for conversion between relative and absolute paths during rendering operations...
void setOutputSize(QSize size)
Sets the size of the resulting map image, in pixels.
void setBackgroundColor(const QColor &color)
Sets the background color of the map.
void setFlag(Qgis::MapSettingsFlag flag, bool on=true)
Enable or disable a particular flag (other flags are not affected)
void setDestinationCrs(const QgsCoordinateReferenceSystem &crs)
Sets the destination crs (coordinate reference system) for the map render.
Container class that allows storage of map themes consisting of visible map layers and layer styles.
bool hasMapTheme(const QString &name) const
Returns whether a map theme with a matching name exists.
QList< QgsMapLayer * > mapThemeVisibleLayers(const QString &name) const
Returns the list of layers that are visible for the specified map theme.
QMap< QString, QString > mapThemeStyleOverrides(const QString &name)
Gets layer style overrides (for QgsMapSettings) of the visible layers for given map theme.
A rectangle specified with double values.