QgsComposerLabel::QgsComposerLabel( QgsComposition *composition ): QgsComposerItem( composition ), mHtmlState( 0 ), mHtmlUnitsToMM( 1.0 ), mHtmlLoaded( false ), mMargin( 1.0 ), mFontColor( QColor( 0, 0, 0 ) ), mHAlignment( Qt::AlignLeft ), mVAlignment( Qt::AlignTop ), mExpressionFeature( 0 ), mExpressionLayer( 0 ) { mHtmlUnitsToMM = htmlUnitsToMM(); //get default composer font from settings QSettings settings; QString defaultFontString = settings.value( "/Composer/defaultFont" ).toString(); if ( !defaultFontString.isEmpty() ) { mFont.setFamily( defaultFontString ); } //default to a 10 point font size mFont.setPointSizeF( 10 ); //default to no background setBackgroundEnabled( false ); if ( mComposition && mComposition->atlasMode() == QgsComposition::PreviewAtlas ) { //a label added while atlas preview is enabled needs to have the expression context set, //otherwise fields in the label aren't correctly evaluated until atlas preview feature changes (#9457) setExpressionContext( mComposition->atlasComposition().currentFeature(), mComposition->atlasComposition().coverageLayer() ); } //connect to atlas feature changes //to update the expression context connect( &mComposition->atlasComposition(), SIGNAL( featureChanged( QgsFeature* ) ), this, SLOT( refreshExpressionContext() ) ); }
QgsComposerHtml::QgsComposerHtml( QgsComposition* c, bool createUndoCommands ) : QgsComposerMultiFrame( c, createUndoCommands ) , mContentMode( QgsComposerHtml::Url ) , mWebPage( nullptr ) , mLoaded( false ) , mHtmlUnitsToMM( 1.0 ) , mRenderedPage( nullptr ) , mEvaluateExpressions( true ) , mUseSmartBreaks( true ) , mMaxBreakDistance( 10 ) , mExpressionLayer( nullptr ) , mDistanceArea( nullptr ) , mEnableUserStylesheet( false ) , mFetcher( nullptr ) { mDistanceArea = new QgsDistanceArea(); mHtmlUnitsToMM = htmlUnitsToMM(); mWebPage = new QgsWebPage(); mWebPage->setIdentifier( tr( "Composer HTML item" ) ); mWebPage->mainFrame()->setScrollBarPolicy( Qt::Horizontal, Qt::ScrollBarAlwaysOff ); mWebPage->mainFrame()->setScrollBarPolicy( Qt::Vertical, Qt::ScrollBarAlwaysOff ); //This makes the background transparent. Found on http://blog.qt.digia.com/blog/2009/06/30/transparent-qwebview-or-qwebpage/ QPalette palette = mWebPage->palette(); palette.setBrush( QPalette::Base, Qt::transparent ); mWebPage->setPalette( palette ); mWebPage->setNetworkAccessManager( QgsNetworkAccessManager::instance() ); QObject::connect( mWebPage, SIGNAL( loadFinished( bool ) ), this, SLOT( frameLoaded( bool ) ) ); if ( mComposition ) { QObject::connect( mComposition, SIGNAL( itemRemoved( QgsComposerItem* ) ), this, SLOT( handleFrameRemoval( QgsComposerItem* ) ) ); } // data defined strings mDataDefinedNames.insert( QgsComposerObject::SourceUrl, QString( "dataDefinedSourceUrl" ) ); if ( mComposition && mComposition->atlasMode() == QgsComposition::PreviewAtlas ) { //a html item added while atlas preview is enabled needs to have the expression context set, //otherwise fields in the html aren't correctly evaluated until atlas preview feature changes (#9457) setExpressionContext( mComposition->atlasComposition().feature(), mComposition->atlasComposition().coverageLayer() ); } //connect to atlas feature changes //to update the expression context connect( &mComposition->atlasComposition(), SIGNAL( featureChanged( QgsFeature* ) ), this, SLOT( refreshExpressionContext() ) ); mFetcher = new QgsNetworkContentFetcher(); connect( mFetcher, SIGNAL( finished() ), this, SLOT( frameLoaded() ) ); }
void QgsComposerHtml::refreshExpressionContext() { QgsVectorLayer * vl = nullptr; QgsFeature feature; if ( mComposition->atlasComposition().enabled() ) { vl = mComposition->atlasComposition().coverageLayer(); } if ( mComposition->atlasMode() != QgsComposition::AtlasOff ) { feature = mComposition->atlasComposition().feature(); } setExpressionContext( feature, vl ); loadHtml( true ); }
QgsComposerHtml::QgsComposerHtml( QgsComposition* c, bool createUndoCommands ): QgsComposerMultiFrame( c, createUndoCommands ), mContentMode( QgsComposerHtml::Url ), mWebPage( 0 ), mLoaded( false ), mHtmlUnitsToMM( 1.0 ), mRenderedPage( 0 ), mEvaluateExpressions( true ), mUseSmartBreaks( true ), mMaxBreakDistance( 10 ), mExpressionFeature( 0 ), mExpressionLayer( 0 ), mEnableUserStylesheet( false ) { mHtmlUnitsToMM = htmlUnitsToMM(); mWebPage = new QWebPage(); mWebPage->setNetworkAccessManager( QgsNetworkAccessManager::instance() ); QObject::connect( mWebPage, SIGNAL( loadFinished( bool ) ), this, SLOT( frameLoaded( bool ) ) ); if ( mComposition ) { QObject::connect( mComposition, SIGNAL( itemRemoved( QgsComposerItem* ) ), this, SLOT( handleFrameRemoval( QgsComposerItem* ) ) ); } // data defined strings mDataDefinedNames.insert( QgsComposerObject::SourceUrl, QString( "dataDefinedSourceUrl" ) ); if ( mComposition && mComposition->atlasMode() == QgsComposition::PreviewAtlas ) { //a html item added while atlas preview is enabled needs to have the expression context set, //otherwise fields in the html aren't correctly evaluated until atlas preview feature changes (#9457) setExpressionContext( mComposition->atlasComposition().currentFeature(), mComposition->atlasComposition().coverageLayer() ); } //connect to atlas feature changes //to update the expression context connect( &mComposition->atlasComposition(), SIGNAL( featureChanged( QgsFeature* ) ), this, SLOT( refreshExpressionContext() ) ); }
QgsLayoutItemHtml::QgsLayoutItemHtml( QgsLayout *layout ) : QgsLayoutMultiFrame( layout ) { mHtmlUnitsToLayoutUnits = htmlUnitsToLayoutUnits(); mWebPage = qgis::make_unique< QgsWebPage >(); mWebPage->setIdentifier( tr( "Layout HTML item" ) ); mWebPage->mainFrame()->setScrollBarPolicy( Qt::Horizontal, Qt::ScrollBarAlwaysOff ); mWebPage->mainFrame()->setScrollBarPolicy( Qt::Vertical, Qt::ScrollBarAlwaysOff ); //This makes the background transparent. Found on http://blog.qt.digia.com/blog/2009/06/30/transparent-qwebview-or-qwebpage/ QPalette palette = mWebPage->palette(); palette.setBrush( QPalette::Base, Qt::transparent ); mWebPage->setPalette( palette ); mWebPage->setNetworkAccessManager( QgsNetworkAccessManager::instance() ); #if 0 //TODO if ( mLayout ) { connect( mLayout, &QgsComposition::itemRemoved, this, &QgsComposerMultiFrame::handleFrameRemoval ); } if ( mComposition && mComposition->atlasMode() == QgsComposition::PreviewAtlas ) { //a html item added while atlas preview is enabled needs to have the expression context set, //otherwise fields in the html aren't correctly evaluated until atlas preview feature changes (#9457) setExpressionContext( mComposition->atlasComposition().feature(), mComposition->atlasComposition().coverageLayer() ); } //connect to atlas feature changes //to update the expression context connect( &mComposition->atlasComposition(), &QgsAtlasComposition::featureChanged, this, &QgsLayoutItemHtml::refreshExpressionContext ); #endif mFetcher = new QgsNetworkContentFetcher(); }