QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Public Types | Public Slots | Public Member Functions | Private Slots | Private Member Functions | Private Attributes | List of all members
QgsComposerHtml Class Reference

#include <qgscomposerhtml.h>

Inheritance diagram for QgsComposerHtml:
Inheritance graph
[legend]
Collaboration diagram for QgsComposerHtml:
Collaboration graph
[legend]

Public Types

enum  ContentMode { Url, ManualHtml }
 Source modes for the HTML content to render in the item. More...
 
- Public Types inherited from QgsComposerMultiFrame
enum  ResizeMode { UseExistingFrames = 0, ExtendToNextPage, RepeatOnEveryPage, RepeatUntilFinished }
 
- Public Types inherited from QgsComposerObject
enum  DataDefinedProperty {
  NoProperty = 0, AllProperties, TestProperty, PresetPaperSize,
  PaperWidth, PaperHeight, NumPages, PaperOrientation,
  PageNumber, PositionX, PositionY, ItemWidth,
  ItemHeight, ItemRotation, Transparency, BlendMode,
  MapRotation, MapScale, MapXMin, MapYMin,
  MapXMax, MapYMax, PictureSource, SourceUrl
}
 Data defined properties for different item types. More...
 
enum  PropertyValueType { EvaluatedValue = 0, OriginalValue }
 Specifies whether the value returned by a function should be the original, user set value, or the current evaluated value for the property. More...
 

Public Slots

void loadHtml ()
 Reloads the html source from the url and redraws the item. More...
 
void refreshExpressionContext ()
 
virtual void refreshDataDefinedProperty (const QgsComposerObject::DataDefinedProperty property=QgsComposerObject::AllProperties)
 
- Public Slots inherited from QgsComposerMultiFrame
void recalculateFrameSizes ()
 Recalculates the portion of the multiframe item which is shown in each of it's component frames. More...
 
- Public Slots inherited from QgsComposerObject
virtual void repaint ()
 Triggers a redraw for the item. More...
 
virtual void refreshDataDefinedProperty (const DataDefinedProperty property=AllProperties)
 Refreshes a data defined property for the item by reevaluating the property's value and redrawing the item with this new value. More...
 

Public Member Functions

 QgsComposerHtml (QgsComposition *c, bool createUndoCommands)
 
 QgsComposerHtml ()
 
 ~QgsComposerHtml ()
 
void setContentMode (ContentMode mode)
 Sets the source mode for item's HTML content. More...
 
ContentMode contentMode () const
 Returns the source mode for item's HTML content. More...
 
void setUrl (const QUrl &url)
 Sets the URL for content to display in the item when the item is using the QgsComposerHtml::Url mode. More...
 
const QUrl & url () const
 Returns the URL of the content displayed in the item if the item is using the QgsComposerHtml::Url mode. More...
 
void setHtml (const QString html)
 Sets the HTML to display in the item when the item is using the QgsComposerHtml::ManualHtml mode. More...
 
QString html () const
 Returns the HTML source displayed in the item if the item is using the QgsComposerHtml::ManualHtml mode. More...
 
bool evaluateExpressions () const
 Returns whether html item will evaluate QGIS expressions prior to rendering the HTML content. More...
 
void setEvaluateExpressions (bool evaluateExpressions)
 Sets whether the html item will evaluate QGIS expressions prior to rendering the HTML content. More...
 
QSizeF totalSize () const
 
void render (QPainter *p, const QRectF &renderExtent)
 
bool writeXML (QDomElement &elem, QDomDocument &doc, bool ignoreFrames=false) const
 
bool readXML (const QDomElement &itemElem, const QDomDocument &doc, bool ignoreFrames=false)
 
void addFrame (QgsComposerFrame *frame, bool recalcFrameSizes=true)
 
double findNearbyPageBreak (double yPos)
 Finds the optimal position to break a frame at. More...
 
bool useSmartBreaks () const
 Returns whether html item is using smart breaks. More...
 
void setUseSmartBreaks (bool useSmartBreaks)
 Sets whether the html item should use smart breaks. More...
 
void setMaxBreakDistance (double maxBreakDistance)
 Sets the maximum distance allowed when calculating where to place page breaks in the html. More...
 
double maxBreakDistance () const
 Returns the maximum distance allowed when calculating where to place page breaks in the html. More...
 
- Public Member Functions inherited from QgsComposerMultiFrame
 QgsComposerMultiFrame (QgsComposition *c, bool createUndoCommands)
 
virtual ~QgsComposerMultiFrame ()
 
void removeFrame (int i)
 
void update ()
 
void setResizeMode (ResizeMode mode)
 
ResizeMode resizeMode () const
 
bool _writeXML (QDomElement &elem, QDomDocument &doc, bool ignoreFrames=false) const
 
bool _readXML (const QDomElement &itemElem, const QDomDocument &doc, bool ignoreFrames=false)
 
QgsCompositioncomposition ()
 
bool createUndoCommands () const
 
void setCreateUndoCommands (bool enabled)
 
void deleteFrames ()
 Removes and deletes all frames from mComposition. More...
 
int frameCount () const
 Return the number of frames associated with this multiframeset. More...
 
QgsComposerFrameframe (int i) const
 
QgsComposerFramecreateNewFrame (QgsComposerFrame *currentFrame, QPointF pos, QSizeF size)
 Creates a new frame and adds it to the multi frame and composition. More...
 
- Public Member Functions inherited from QgsComposerObject
 QgsComposerObject (QgsComposition *composition)
 Constructor. More...
 
virtual ~QgsComposerObject ()
 
const QgsCompositioncomposition () const
 Returns the composition the item is attached to. More...
 
QgsCompositioncomposition ()
 
virtual bool writeXML (QDomElement &elem, QDomDocument &doc) const
 Stores item state in DOM element. More...
 
virtual bool readXML (const QDomElement &itemElem, const QDomDocument &doc)
 Sets item state from DOM element. More...
 
QgsDataDefineddataDefinedProperty (const DataDefinedProperty property) const
 Returns a reference to the data defined settings for one of the item's data defined properties. More...
 
void setDataDefinedProperty (const DataDefinedProperty property, const bool active, const bool useExpression, const QString &expression, const QString &field)
 Sets parameters for a data defined property for the item. More...
 

Private Slots

void frameLoaded (bool ok=true)
 

Private Member Functions

double htmlUnitsToMM ()
 
void renderCachedImage ()
 
QString fetchHtml (QUrl url)
 
void setExpressionContext (QgsFeature *feature, QgsVectorLayer *layer)
 Sets the current feature, the current layer and a list of local variable substitutions for evaluating expressions. More...
 

Private Attributes

ContentMode mContentMode
 
QUrl mUrl
 
QWebPage * mWebPage
 
QString mHtml
 
QString mFetchedHtml
 
QString mLastFetchedUrl
 
bool mLoaded
 
QSizeF mSize
 
double mHtmlUnitsToMM
 
QImage * mRenderedPage
 
bool mEvaluateExpressions
 
bool mUseSmartBreaks
 
double mMaxBreakDistance
 
QgsFeaturemExpressionFeature
 
QgsVectorLayermExpressionLayer
 

Additional Inherited Members

- Signals inherited from QgsComposerMultiFrame
void changed ()
 
void contentsChanged ()
 Emitted when the contents of the multi frame have changed and the frames must be redrawn. More...
 
- Signals inherited from QgsComposerObject
void itemChanged ()
 Emitted when the item changes. More...
 
- Protected Slots inherited from QgsComposerMultiFrame
void handleFrameRemoval (QgsComposerItem *item)
 Called before a frame is going to be removed (update frame list) More...
 
void handlePageChange ()
 Adapts to changed number of pages if resize type is RepeatOnEveryPage. More...
 
- Protected Member Functions inherited from QgsComposerObject
bool dataDefinedEvaluate (const QgsComposerObject::DataDefinedProperty property, QVariant &expressionValue)
 Evaluate a data defined property and return the calculated value. More...
 
- Protected Attributes inherited from QgsComposerMultiFrame
QList< QgsComposerFrame * > mFrameItems
 
ResizeMode mResizeMode
 
bool mCreateUndoCommands
 True: creates QgsMultiFrameCommands on internal changes (e.g. More...
 
- Protected Attributes inherited from QgsComposerObject
QgsCompositionmComposition
 
QMap
< QgsComposerObject::DataDefinedProperty,
QString > 
mDataDefinedNames
 Map of data defined properties for the item to string name to use when exporting item to xml. More...
 

Detailed Description

Definition at line 27 of file qgscomposerhtml.h.

Member Enumeration Documentation

Source modes for the HTML content to render in the item.

Enumerator
Url 
ManualHtml 

Definition at line 34 of file qgscomposerhtml.h.

Constructor & Destructor Documentation

QgsComposerHtml::QgsComposerHtml ( QgsComposition c,
bool  createUndoCommands 
)
QgsComposerHtml::QgsComposerHtml ( )

Definition at line 69 of file qgscomposerhtml.cpp.

QgsComposerHtml::~QgsComposerHtml ( )

Definition at line 82 of file qgscomposerhtml.cpp.

References mRenderedPage, and mWebPage.

Member Function Documentation

void QgsComposerHtml::addFrame ( QgsComposerFrame frame,
bool  recalcFrameSizes = true 
)
virtual
ContentMode QgsComposerHtml::contentMode ( ) const
inline

Returns the source mode for item's HTML content.

Returns
ContentMode for the item's source
See also
setContentMode
url
html
Note
added in 2.5

Definition at line 60 of file qgscomposerhtml.h.

bool QgsComposerHtml::evaluateExpressions ( ) const
inline

Returns whether html item will evaluate QGIS expressions prior to rendering the HTML content.

If set, any content inside [% %] tags will be treated as a QGIS expression and evaluated against the current atlas feature.

Returns
true if html item will evaluate expressions in the content
See also
setEvaluateExpressions
Note
added in QGIS 2.5

Definition at line 108 of file qgscomposerhtml.h.

Referenced by setEvaluateExpressions().

QString QgsComposerHtml::fetchHtml ( QUrl  url)
private
double QgsComposerHtml::findNearbyPageBreak ( double  yPos)
virtual

Finds the optimal position to break a frame at.

Parameters
yPosmaximum vertical position for break
Returns
the optimal breakable position which occurs in the multi frame close to and before the specified yPos
Note
added in version 2.3

Reimplemented from QgsComposerMultiFrame.

Definition at line 324 of file qgscomposerhtml.cpp.

References candidateSort(), htmlUnitsToMM(), mMaxBreakDistance, mRenderedPage, mUseSmartBreaks, and mWebPage.

void QgsComposerHtml::frameLoaded ( bool  ok = true)
privateslot

Definition at line 247 of file qgscomposerhtml.cpp.

References mLoaded.

Referenced by fetchHtml(), and QgsComposerHtml().

QString QgsComposerHtml::html ( ) const
inline

Returns the HTML source displayed in the item if the item is using the QgsComposerHtml::ManualHtml mode.

Returns
HTML displayed in item
See also
setHtml
contentMode
Note
added in 2.5

Definition at line 98 of file qgscomposerhtml.h.

Referenced by setHtml().

double QgsComposerHtml::htmlUnitsToMM ( )
private
void QgsComposerHtml::loadHtml ( )
slot
double QgsComposerHtml::maxBreakDistance ( ) const
inline

Returns the maximum distance allowed when calculating where to place page breaks in the html.

This distance is the maximum amount of empty space allowed at the bottom of a frame after calculating the optimum break location. This setting is only effective if useSmartBreaks is true.

Returns
maximum amount of empty space to leave when calculating page break locations
Note
added in 2.3
See also
setMaxBreakDistance
useSmartBreaks

Definition at line 169 of file qgscomposerhtml.h.

Referenced by setMaxBreakDistance().

bool QgsComposerHtml::readXML ( const QDomElement &  itemElem,
const QDomDocument &  doc,
bool  ignoreFrames = false 
)
virtual
void QgsComposerHtml::refreshDataDefinedProperty ( const QgsComposerObject::DataDefinedProperty  property = QgsComposerObject::AllProperties)
virtualslot
void QgsComposerHtml::refreshExpressionContext ( )
slot
void QgsComposerHtml::render ( QPainter *  p,
const QRectF &  renderExtent 
)
virtual

Implements QgsComposerMultiFrame.

Definition at line 272 of file qgscomposerhtml.cpp.

References mHtmlUnitsToMM, and mWebPage.

void QgsComposerHtml::renderCachedImage ( )
private

Definition at line 253 of file qgscomposerhtml.cpp.

References mRenderedPage, and mWebPage.

Referenced by loadHtml().

void QgsComposerHtml::setContentMode ( ContentMode  mode)
inline

Sets the source mode for item's HTML content.

Parameters
modeContentMode for the item's source
See also
contentMode
setUrl
setHtml
Note
added in 2.5

Definition at line 51 of file qgscomposerhtml.h.

void QgsComposerHtml::setEvaluateExpressions ( bool  evaluateExpressions)

Sets whether the html item will evaluate QGIS expressions prior to rendering the HTML content.

If set, any content inside [% %] tags will be treated as a QGIS expression and evaluated against the current atlas feature.

Parameters
evaluateExpressionsset to true to evaluate expressions in the HTML content
See also
evaluateExpressions
Note
added in QGIS 2.5

Definition at line 104 of file qgscomposerhtml.cpp.

References evaluateExpressions(), loadHtml(), and mEvaluateExpressions.

void QgsComposerHtml::setExpressionContext ( QgsFeature feature,
QgsVectorLayer layer 
)
private

Sets the current feature, the current layer and a list of local variable substitutions for evaluating expressions.

Definition at line 463 of file qgscomposerhtml.cpp.

References mExpressionFeature, and mExpressionLayer.

Referenced by QgsComposerHtml(), and refreshExpressionContext().

void QgsComposerHtml::setHtml ( const QString  html)

Sets the HTML to display in the item when the item is using the QgsComposerHtml::ManualHtml mode.

Setting the HTML using this function does not automatically refresh the item's contents. Call loadHtml to trigger a refresh of the item after setting the HTML content.

Parameters
htmlHTML to display in item
See also
html
contentMode
loadHtml
Note
added in 2.5

Definition at line 99 of file qgscomposerhtml.cpp.

References html(), and mHtml.

void QgsComposerHtml::setMaxBreakDistance ( double  maxBreakDistance)

Sets the maximum distance allowed when calculating where to place page breaks in the html.

This distance is the maximum amount of empty space allowed at the bottom of a frame after calculating the optimum break location. Setting a larger value will result in better choice of page break location, but more wasted space at the bottom of frames. This setting is only effective if useSmartBreaks is true.

Parameters
maxBreakDistancemaximum amount of empty space to leave when calculating page break locations
Note
added in 2.3
See also
maxBreakDistance
setUseSmartBreaks

Definition at line 408 of file qgscomposerhtml.cpp.

References QgsComposerMultiFrame::changed(), maxBreakDistance(), mMaxBreakDistance, and QgsComposerMultiFrame::recalculateFrameSizes().

void QgsComposerHtml::setUrl ( const QUrl &  url)

Sets the URL for content to display in the item when the item is using the QgsComposerHtml::Url mode.

Content is automatically fetched and the HTML item refreshed after calling this function.

Parameters
urlURL of content to display in the item
See also
url
contentMode

Definition at line 88 of file qgscomposerhtml.cpp.

References loadHtml(), mUrl, mWebPage, and url().

void QgsComposerHtml::setUseSmartBreaks ( bool  useSmartBreaks)

Sets whether the html item should use smart breaks.

Smart breaks prevent the html frame contents from breaking mid-way though a line of text.

Parameters
useSmartBreaksset to true to prevent content from breaking mid-way through a line of text
See also
useSmartBreaks

Definition at line 401 of file qgscomposerhtml.cpp.

References QgsComposerMultiFrame::changed(), mUseSmartBreaks, QgsComposerMultiFrame::recalculateFrameSizes(), and useSmartBreaks().

QSizeF QgsComposerHtml::totalSize ( ) const
virtual

Implements QgsComposerMultiFrame.

Definition at line 267 of file qgscomposerhtml.cpp.

References mSize.

const QUrl& QgsComposerHtml::url ( ) const
inline

Returns the URL of the content displayed in the item if the item is using the QgsComposerHtml::Url mode.

Returns
url for content displayed in item
See also
setUrl
contentMode

Definition at line 77 of file qgscomposerhtml.h.

Referenced by fetchHtml(), and setUrl().

bool QgsComposerHtml::useSmartBreaks ( ) const
inline

Returns whether html item is using smart breaks.

Smart breaks prevent the html frame contents from breaking mid-way though a line of text.

Returns
true if html item is using smart breaks
See also
setUseSmartBreaks

Definition at line 136 of file qgscomposerhtml.h.

Referenced by setUseSmartBreaks().

bool QgsComposerHtml::writeXML ( QDomElement &  elem,
QDomDocument &  doc,
bool  ignoreFrames = false 
) const
virtual

Member Data Documentation

ContentMode QgsComposerHtml::mContentMode
private

Definition at line 187 of file qgscomposerhtml.h.

Referenced by loadHtml(), readXML(), and writeXML().

bool QgsComposerHtml::mEvaluateExpressions
private

Definition at line 197 of file qgscomposerhtml.h.

Referenced by loadHtml(), readXML(), setEvaluateExpressions(), and writeXML().

QgsFeature* QgsComposerHtml::mExpressionFeature
private

Definition at line 201 of file qgscomposerhtml.h.

Referenced by loadHtml(), and setExpressionContext().

QgsVectorLayer* QgsComposerHtml::mExpressionLayer
private

Definition at line 202 of file qgscomposerhtml.h.

Referenced by loadHtml(), and setExpressionContext().

QString QgsComposerHtml::mFetchedHtml
private

Definition at line 191 of file qgscomposerhtml.h.

Referenced by fetchHtml(), and loadHtml().

QString QgsComposerHtml::mHtml
private

Definition at line 190 of file qgscomposerhtml.h.

Referenced by loadHtml(), readXML(), setHtml(), and writeXML().

double QgsComposerHtml::mHtmlUnitsToMM
private

Definition at line 195 of file qgscomposerhtml.h.

Referenced by loadHtml(), QgsComposerHtml(), and render().

QString QgsComposerHtml::mLastFetchedUrl
private

Definition at line 192 of file qgscomposerhtml.h.

Referenced by loadHtml().

bool QgsComposerHtml::mLoaded
private

Definition at line 193 of file qgscomposerhtml.h.

Referenced by fetchHtml(), frameLoaded(), and loadHtml().

double QgsComposerHtml::mMaxBreakDistance
private

Definition at line 199 of file qgscomposerhtml.h.

Referenced by findNearbyPageBreak(), readXML(), setMaxBreakDistance(), and writeXML().

QImage* QgsComposerHtml::mRenderedPage
private

Definition at line 196 of file qgscomposerhtml.h.

Referenced by findNearbyPageBreak(), renderCachedImage(), and ~QgsComposerHtml().

QSizeF QgsComposerHtml::mSize
private

Definition at line 194 of file qgscomposerhtml.h.

Referenced by loadHtml(), and totalSize().

QUrl QgsComposerHtml::mUrl
private

Definition at line 188 of file qgscomposerhtml.h.

Referenced by loadHtml(), readXML(), setUrl(), and writeXML().

bool QgsComposerHtml::mUseSmartBreaks
private

Definition at line 198 of file qgscomposerhtml.h.

Referenced by findNearbyPageBreak(), readXML(), setUseSmartBreaks(), and writeXML().

QWebPage* QgsComposerHtml::mWebPage
private

The documentation for this class was generated from the following files: