Skip to content
Permalink
Browse files

Remove some processEvents usage

  • Loading branch information
nyalldawson committed Nov 20, 2017
1 parent e71d4d7 commit 30ce60bd9069e139e6b1fad0df2219bc8cc71363
Showing with 13 additions and 24 deletions.
  1. +13 −20 src/core/layout/qgslayoutitemhtml.cpp
  2. +0 −4 src/core/layout/qgslayoutitemhtml.h
@@ -37,7 +37,6 @@
QgsLayoutItemHtml::QgsLayoutItemHtml( QgsLayout *layout )
: QgsLayoutMultiFrame( layout )
, mContentMode( QgsLayoutItemHtml::Url )
, mLoaded( false )
, mHtmlUnitsToLayoutUnits( 1.0 )
, mEvaluateExpressions( true )
, mUseSmartBreaks( true )
@@ -57,7 +56,6 @@ QgsLayoutItemHtml::QgsLayoutItemHtml( QgsLayout *layout )
mWebPage->setPalette( palette );

mWebPage->setNetworkAccessManager( QgsNetworkAccessManager::instance() );
connect( mWebPage, &QWebPage::loadFinished, this, &QgsLayoutItemHtml::frameLoaded );

#if 0 //TODO
if ( mLayout )
@@ -78,8 +76,6 @@ QgsLayoutItemHtml::QgsLayoutItemHtml( QgsLayout *layout )
#endif

mFetcher = new QgsNetworkContentFetcher();
connect( mFetcher, &QgsNetworkContentFetcher::finished, this, [ = ] { frameLoaded(); } );

}

QgsLayoutItemHtml::~QgsLayoutItemHtml()
@@ -186,7 +182,11 @@ void QgsLayoutItemHtml::loadHtml( const bool useCache, const QgsExpressionContex
loadedHtml = QgsExpression::replaceExpressionText( loadedHtml, evalContext, mDistanceArea );
}

mLoaded = false;
bool loaded = false;

QEventLoop loop;
connect( mWebPage, &QWebPage::loadFinished, &loop, [&loaded, &loop ] { loaded = true; loop.quit(); } );
connect( mFetcher, &QgsNetworkContentFetcher::finished, &loop, [&loaded, &loop ] { loaded = true; loop.quit(); } );

//reset page size. otherwise viewport size increases but never decreases again
mWebPage->setViewportSize( QSize( maxFrameWidth() * mHtmlUnitsToLayoutUnits, 0 ) );
@@ -195,6 +195,7 @@ void QgsLayoutItemHtml::loadHtml( const bool useCache, const QgsExpressionContex
const QUrl baseUrl = mContentMode == QgsLayoutItemHtml::Url ?
QUrl( mActualFetchedUrl ) :
QUrl::fromLocalFile( mLayout->project()->fileInfo().absoluteFilePath() );

mWebPage->mainFrame()->setHtml( loadedHtml, baseUrl );

//set user stylesheet
@@ -211,10 +212,8 @@ void QgsLayoutItemHtml::loadHtml( const bool useCache, const QgsExpressionContex
settings->setUserStyleSheetUrl( QUrl() );
}

while ( !mLoaded )
{
qApp->processEvents();
}
if ( !loaded )
loop.exec( QEventLoop::ExcludeUserInputEvents );

//inject JSON feature
if ( !mAtlasFeatureJSON.isEmpty() )
@@ -229,12 +228,6 @@ void QgsLayoutItemHtml::loadHtml( const bool useCache, const QgsExpressionContex
emit contentsChanged();
}

void QgsLayoutItemHtml::frameLoaded( bool ok )
{
Q_UNUSED( ok );
mLoaded = true;
}

double QgsLayoutItemHtml::maxFrameWidth() const
{
double maxWidth = 0;
@@ -290,13 +283,13 @@ void QgsLayoutItemHtml::renderCachedImage()
QString QgsLayoutItemHtml::fetchHtml( const QUrl &url )
{
//pause until HTML fetch
mLoaded = false;
bool loaded = false;
QEventLoop loop;
connect( mFetcher, &QgsNetworkContentFetcher::finished, &loop, [&loaded, &loop ] { loaded = true; loop.quit(); } );
mFetcher->fetchContent( url );

while ( !mLoaded )
{
qApp->processEvents();
}
if ( !loaded )
loop.exec( QEventLoop::ExcludeUserInputEvents );

mFetchedHtml = mFetcher->contentAsString();
mActualFetchedUrl = mFetcher->reply()->url().toString();
@@ -233,9 +233,6 @@ class CORE_EXPORT QgsLayoutItemHtml: public QgsLayoutMultiFrame
bool writePropertiesToElement( QDomElement &elem, QDomDocument &doc, const QgsReadWriteContext &context ) const override;
bool readPropertiesFromElement( const QDomElement &itemElem, const QDomDocument &doc, const QgsReadWriteContext &context ) override;

private slots:
void frameLoaded( bool ok = true );

private:
ContentMode mContentMode;
QUrl mUrl;
@@ -244,7 +241,6 @@ class CORE_EXPORT QgsLayoutItemHtml: public QgsLayoutMultiFrame
QString mFetchedHtml;
QString mLastFetchedUrl;
QString mActualFetchedUrl; //may be different if page was redirected
bool mLoaded;
QSizeF mSize; //total size in mm
double mHtmlUnitsToLayoutUnits;
QImage *mRenderedPage = nullptr;

0 comments on commit 30ce60b

Please sign in to comment.
You can’t perform that action at this time.