Skip to content
Permalink
Browse files

Begin port of HTML item

  • Loading branch information
nyalldawson committed Oct 27, 2017
1 parent 0e71505 commit f1d1e454d831995d79c1bffda5eaab516025752a
@@ -409,6 +409,7 @@
%Include layout/qgslayoutframe.sip
%Include layout/qgslayoutitem.sip
%Include layout/qgslayoutitemgroup.sip
%Include layout/qgslayoutitemhtml.sip
%Include layout/qgslayoutitemlabel.sip
%Include layout/qgslayoutitemlegend.sip
%Include layout/qgslayoutitemmap.sip
@@ -0,0 +1,227 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/layout/qgslayoutitemhtml.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/




class QgsLayoutItemHtml: QgsLayoutMultiFrame
{
%Docstring
A layout multiframe subclass for HTML content.
.. versionadded:: 3.0
%End

%TypeHeaderCode
#include "qgslayoutitemhtml.h"
%End
public:

enum ContentMode
{
Url,
ManualHtml
};

QgsLayoutItemHtml( QgsLayout *layout );
%Docstring
Constructor for QgsLayoutItemHtml, with the specified parent ``layout``.
%End

~QgsLayoutItemHtml();

void setContentMode( ContentMode mode );
%Docstring
Sets the source ``mode`` for item's HTML content.
.. seealso:: contentMode()
.. seealso:: setUrl()
.. seealso:: setHtml()
%End

ContentMode contentMode() const;
%Docstring
Returns the source mode for item's HTML content.
.. seealso:: setContentMode()
.. seealso:: url()
.. seealso:: html()
:rtype: ContentMode
%End

void setUrl( const QUrl &url );
%Docstring
Sets the ``url`` for content to display in the item when the item is using
the QgsLayoutItemHtml.Url mode. Content is automatically fetched and the
HTML item refreshed after calling this function.
.. seealso:: url()
.. seealso:: contentMode()
%End

QUrl url() const;
%Docstring
Returns the URL of the content displayed in the item if the item is using
the QgsLayoutItemHtml.Url mode.
.. seealso:: setUrl()
.. seealso:: contentMode()
:rtype: QUrl
%End

void setHtml( const QString &html );
%Docstring
Sets the ``html`` to display in the item when the item is using
the QgsLayoutItemHtml.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.
.. seealso:: html()
.. seealso:: contentMode()
.. seealso:: loadHtml()
%End

QString html() const;
%Docstring
Returns the HTML source displayed in the item if the item is using
the QgsLayoutItemHtml.ManualHtml mode.
.. seealso:: setHtml()
.. seealso:: contentMode()
:rtype: str
%End

bool evaluateExpressions() const;
%Docstring
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.
.. seealso:: setEvaluateExpressions()
:rtype: bool
%End

void setEvaluateExpressions( bool evaluateExpressions );
%Docstring
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.
.. seealso:: evaluateExpressions()
%End

bool useSmartBreaks() const;
%Docstring
Returns whether html item is using smart breaks. Smart breaks prevent
the html frame contents from breaking mid-way though a line of text.
.. seealso:: setUseSmartBreaks()
:rtype: bool
%End

void setUseSmartBreaks( bool useSmartBreaks );
%Docstring
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.
.. seealso:: useSmartBreaks()
%End

void setMaxBreakDistance( double distance );
%Docstring
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.
.. seealso:: maxBreakDistance()
.. seealso:: setUseSmartBreaks()
%End

double maxBreakDistance() const;
%Docstring
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.
.. seealso:: setMaxBreakDistance()
.. seealso:: useSmartBreaks()
:rtype: float
%End

void setUserStylesheet( const QString &stylesheet );
%Docstring
Sets the user ``stylesheet`` CSS rules to use while rendering the HTML content. These
allow for overriding the styles specified within the HTML source. Setting the stylesheet
using this function does not automatically refresh the item's contents. Call loadHtml
to trigger a refresh of the item after setting the stylesheet rules.
.. seealso:: userStylesheet()
.. seealso:: setUserStylesheetEnabled()
.. seealso:: loadHtml()
%End

QString userStylesheet() const;
%Docstring
Returns the user stylesheet CSS rules used while rendering the HTML content. These
overriding the styles specified within the HTML source.
.. seealso:: setUserStylesheet()
.. seealso:: userStylesheetEnabled()
:rtype: str
%End

void setUserStylesheetEnabled( const bool enabled );
%Docstring
Sets whether user stylesheets are ``enabled`` for the HTML content.
.. seealso:: userStylesheetEnabled()
.. seealso:: setUserStylesheet()
%End

bool userStylesheetEnabled() const;
%Docstring
Returns whether user stylesheets are enabled for the HTML content.
.. seealso:: setUserStylesheetEnabled()
.. seealso:: userStylesheet()
:rtype: bool
%End

virtual QString displayName() const;

virtual QSizeF totalSize() const;

virtual void render( QgsRenderContext &context, const QRectF &renderExtent, const int frameIndex,
const QStyleOptionGraphicsItem *itemStyle = 0 );

virtual bool writeXml( QDomElement &elem, QDomDocument &doc, bool ignoreFrames = false ) const;

virtual bool readXml( const QDomElement &itemElem, const QDomDocument &doc, bool ignoreFrames = false );

virtual double findNearbyPageBreak( double yPos );


public slots:

void loadHtml( const bool useCache = false, const QgsExpressionContext *context = 0 );
%Docstring
Reloads the html source from the url and redraws the item.
\param useCache set to true to use a cached copy of remote html
content
\param context expression context for evaluating data defined urls and expressions in html
.. seealso:: setUrl
.. seealso:: url
%End

virtual void recalculateFrameSizes();

%Docstring
Recalculates the frame sizes for the current viewport dimensions
%End
void refreshExpressionContext();

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

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/core/layout/qgslayoutitemhtml.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -373,6 +373,7 @@ SET(QGIS_CORE_SRCS
layout/qgslayoutitem.cpp
layout/qgslayoutitemgroup.cpp
layout/qgslayoutitemgroupundocommand.cpp
layout/qgslayoutitemhtml.cpp
layout/qgslayoutitemlabel.cpp
layout/qgslayoutitemlegend.cpp
layout/qgslayoutitemmap.cpp
@@ -735,6 +736,7 @@ SET(QGIS_CORE_MOC_HDRS
layout/qgslayoutitem.h
layout/qgslayoutitemgroup.h
layout/qgslayoutitemgroupundocommand.h
layout/qgslayoutitemhtml.h
layout/qgslayoutitemlabel.h
layout/qgslayoutitemlegend.h
layout/qgslayoutitemmap.h
@@ -336,18 +336,6 @@ void QgsComposerHtml::addFrame( QgsComposerFrame *frame, bool recalcFrameSizes )
}
}

bool candidateSort( QPair<int, int> c1, QPair<int, int> c2 )
{
if ( c1.second < c2.second )
return true;
else if ( c1.second > c2.second )
return false;
else if ( c1.first > c2.first )
return true;
else
return false;
}

double QgsComposerHtml::findNearbyPageBreak( double yPos )
{
if ( !mWebPage || !mRenderedPage || !mUseSmartBreaks )
@@ -400,7 +388,18 @@ double QgsComposerHtml::findNearbyPageBreak( double yPos )
}

//sort candidate rows by number of changes ascending, row number descending
std::sort( candidates.begin(), candidates.end(), candidateSort );
std::sort( candidates.begin(), candidates.end(),
[]( QPair<int, int> c1, QPair<int, int> c2 )->bool
{
if ( c1.second < c2.second )
return true;
else if ( c1.second > c2.second )
return false;
else if ( c1.first > c2.first )
return true;
else
return false;
} );
//first candidate is now the largest row with smallest number of changes

//OK, now take the mid point of the best candidate position

0 comments on commit f1d1e45

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