Skip to content

Commit

Permalink
Implement layout elevation profile plot rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jan 27, 2023
1 parent 33368d7 commit 4cf399f
Show file tree
Hide file tree
Showing 9 changed files with 518 additions and 9 deletions.
13 changes: 13 additions & 0 deletions python/core/auto_generated/elevation/qgsprofilerenderer.sip.in
Expand Up @@ -55,6 +55,19 @@ Returns the ordered list of source IDs for the sources used by the renderer.
%Docstring
Start the generation job and immediately return.
Does nothing if the generation is already in progress.
%End

void generateSynchronously();
%Docstring
Generate the profile results synchronously in this thread. The function does not return until the generation
is complete.

This is an alternative to ordinary API (using :py:func:`~QgsProfilePlotRenderer.startGeneration` + waiting for :py:func:`~QgsProfilePlotRenderer.generationFinished` signal).
Users are discouraged to use this method unless they have a strong reason for doing it.
The synchronous generation blocks the main thread, making the application unresponsive.
Also, it is not possible to cancel generation while it is in progress.

.. versionadded:: 3.30
%End

void cancelGeneration();
Expand Down
Expand Up @@ -42,6 +42,8 @@ The caller takes responsibility for deleting the returned object.

virtual void refreshDataDefinedProperty( QgsLayoutObject::DataDefinedProperty property = QgsLayoutObject::AllProperties );

virtual QgsLayoutItem::Flags itemFlags() const;


Qgs2DPlot *plot();
%Docstring
Expand Down Expand Up @@ -131,6 +133,16 @@ ignore this tolerance if it is not appropriate for the particular source.
Returns the profile request used to generate the elevation profile.
%End

virtual void paint( QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget );


public slots:

virtual void refresh();

virtual void invalidateCache();


protected:
virtual void draw( QgsLayoutItemRenderContext &context );

Expand Down
25 changes: 25 additions & 0 deletions src/core/elevation/qgsprofilerenderer.cpp
Expand Up @@ -81,6 +81,31 @@ void QgsProfilePlotRenderer::startGeneration()
mFutureWatcher.setFuture( mFuture );
}

void QgsProfilePlotRenderer::generateSynchronously()
{
if ( isActive() )
return;

mStatus = Generating;

Q_ASSERT( mJobs.empty() );
mJobs.reserve( mGenerators.size() );

for ( const auto &it : mGenerators )
{
std::unique_ptr< ProfileJob > job = std::make_unique< ProfileJob >();
job->generator = it.get();
job->context = mContext;
it.get()->generateProfile( job->context );
job->results.reset( job->generator->takeResults() );
job->complete = true;
job->invalidatedResults.reset();
mJobs.emplace_back( std::move( job ) );
}

mStatus = Idle;
}

void QgsProfilePlotRenderer::cancelGeneration()
{
if ( !isActive() )
Expand Down
13 changes: 13 additions & 0 deletions src/core/elevation/qgsprofilerenderer.h
Expand Up @@ -82,6 +82,19 @@ class CORE_EXPORT QgsProfilePlotRenderer : public QObject
*/
void startGeneration();

/**
* Generate the profile results synchronously in this thread. The function does not return until the generation
* is complete.
*
* This is an alternative to ordinary API (using startGeneration() + waiting for generationFinished() signal).
* Users are discouraged to use this method unless they have a strong reason for doing it.
* The synchronous generation blocks the main thread, making the application unresponsive.
* Also, it is not possible to cancel generation while it is in progress.
*
* \since QGIS 3.30
*/
void generateSynchronously();

/**
* Stop the generation job - does not return until the job has terminated.
* Does nothing if the generation is not active.
Expand Down

0 comments on commit 4cf399f

Please sign in to comment.