Skip to content
Permalink
Browse files

[composer] Add checkbox for controlling whether html items should use…

… smart page breaking (sponsored by City of Uster, Switzerland)
  • Loading branch information
nyalldawson committed Apr 28, 2014
1 parent 8059a75 commit ad0b4daf8d06314c00d70bded9fc50516101af0e
@@ -19,4 +19,19 @@ class QgsComposerHtml: QgsComposerMultiFrame
bool readXML( const QDomElement& itemElem, const QDomDocument& doc, bool ignoreFrames = false );

void addFrame( QgsComposerFrame* frame, bool recalcFrameSizes = true );
};

/**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 setUseSmartBreaks
*/
bool useSmartBreaks() const;

/**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.
* @param useSmartBreaks set to true to prevent content from breaking
* mid-way through a line of text
* @see useSmartBreaks
*/
void setUseSmartBreaks( bool useSmartBreaks );
};
@@ -60,6 +60,7 @@ void QgsComposerHtmlWidget::blockSignals( bool block )
mUrlLineEdit->blockSignals( block );
mFileToolButton->blockSignals( block );
mResizeModeComboBox->blockSignals( block );
mUseSmartBreaksCheckBox->blockSignals( block );
}

void QgsComposerHtmlWidget::on_mUrlLineEdit_editingFinished()
@@ -114,6 +115,24 @@ void QgsComposerHtmlWidget::on_mResizeModeComboBox_currentIndexChanged( int inde
}
}

void QgsComposerHtmlWidget::on_mUseSmartBreaksCheckBox_stateChanged( int state )
{
if ( !mHtml )
{
return;
}

QgsComposition* composition = mHtml->composition();
if ( composition )
{
blockSignals( true );
composition->beginMultiFrameCommand( mHtml, tr( "Use smart breaks changed" ) );
mHtml->setUseSmartBreaks( state );
composition->endMultiFrameCommand();
blockSignals( false );
}
}

void QgsComposerHtmlWidget::setGuiElementValues()
{
if ( !mHtml )
@@ -124,7 +143,6 @@ void QgsComposerHtmlWidget::setGuiElementValues()
blockSignals( true );
mUrlLineEdit->setText( mHtml->url().toString() );
mResizeModeComboBox->setCurrentIndex( mResizeModeComboBox->findData( mHtml->resizeMode() ) );
mUseSmartBreaksCheckBox->setChecked( mHtml->useSmartBreaks() );
blockSignals( false );
}


@@ -31,6 +31,7 @@ class QgsComposerHtmlWidget: public QWidget, private Ui::QgsComposerHtmlWidgetBa
void on_mUrlLineEdit_editingFinished();
void on_mFileToolButton_clicked();
void on_mResizeModeComboBox_currentIndexChanged( int index );
void on_mUseSmartBreaksCheckBox_stateChanged( int state );

/**Sets the GUI elements to the values of mHtmlItem*/
void setGuiElementValues();
@@ -24,7 +24,11 @@
#include <QImage>

QgsComposerHtml::QgsComposerHtml( QgsComposition* c, bool createUndoCommands ): QgsComposerMultiFrame( c, createUndoCommands ),
mWebPage( 0 ), mLoaded( false ), mHtmlUnitsToMM( 1.0 ), mRenderedPage( 0 )
mWebPage( 0 ),
mLoaded( false ),
mHtmlUnitsToMM( 1.0 ),
mRenderedPage( 0 ),
mUseSmartBreaks( true )
{
mHtmlUnitsToMM = htmlUnitsToMM();
mWebPage = new QWebPage();
@@ -35,7 +39,12 @@ QgsComposerHtml::QgsComposerHtml( QgsComposition* c, bool createUndoCommands ):
}
}

QgsComposerHtml::QgsComposerHtml(): QgsComposerMultiFrame( 0, false ), mWebPage( 0 ), mLoaded( false ), mHtmlUnitsToMM( 1.0 ), mRenderedPage( 0 )
QgsComposerHtml::QgsComposerHtml(): QgsComposerMultiFrame( 0, false ),
mWebPage( 0 ),
mLoaded( false ),
mHtmlUnitsToMM( 1.0 ),
mRenderedPage( 0 ),
mUseSmartBreaks( true )
{
}

@@ -154,7 +163,7 @@ bool candidateSort( const QPair<int, int> &c1, const QPair<int, int> &c2 )

double QgsComposerHtml::findNearbyPageBreak( double yPos )
{
if ( !mWebPage || !mRenderedPage )
if ( !mWebPage || !mRenderedPage || !mUseSmartBreaks )
{
return yPos;
}
@@ -228,10 +237,18 @@ double QgsComposerHtml::findNearbyPageBreak( double yPos )
return candidates[0].first / htmlUnitsToMM();
}

void QgsComposerHtml::setUseSmartBreaks( bool useSmartBreaks )
{
mUseSmartBreaks = useSmartBreaks;
recalculateFrameSizes();
}

bool QgsComposerHtml::writeXML( QDomElement& elem, QDomDocument & doc, bool ignoreFrames ) const
{
QDomElement htmlElem = doc.createElement( "ComposerHtml" );
htmlElem.setAttribute( "url", mUrl.toString() );
htmlElem.setAttribute( "useSmartBreaks", mUseSmartBreaks ? "true" : "false" );

bool state = _writeXML( htmlElem, doc, ignoreFrames );
elem.appendChild( htmlElem );
return state;
@@ -247,7 +264,9 @@ bool QgsComposerHtml::readXML( const QDomElement& itemElem, const QDomDocument&
return false;
}

//then load the set url
mUseSmartBreaks = itemElem.attribute( "useSmartBreaks", "true" ) == "true" ? true : false;

//finally load the set url
QString urlString = itemElem.attribute( "url" );
if ( !urlString.isEmpty() )
{
@@ -44,6 +44,21 @@ class CORE_EXPORT QgsComposerHtml: public QgsComposerMultiFrame
//overriden to break frames without dividing lines of text
double findNearbyPageBreak( double yPos );

/**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 setUseSmartBreaks
*/
bool useSmartBreaks() const { return mUseSmartBreaks; }

/**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.
* @param useSmartBreaks set to true to prevent content from breaking
* mid-way through a line of text
* @see useSmartBreaks
*/
void setUseSmartBreaks( bool useSmartBreaks );

private slots:
void frameLoaded( bool ok );

@@ -54,6 +69,7 @@ class CORE_EXPORT QgsComposerHtml: public QgsComposerMultiFrame
QSizeF mSize; //total size in mm
double mHtmlUnitsToMM;
QImage* mRenderedPage;
bool mUseSmartBreaks;

double htmlUnitsToMM(); //calculate scale factor

@@ -47,7 +47,7 @@
<x>0</x>
<y>0</y>
<width>407</width>
<height>348</height>
<height>347</height>
</rect>
</property>
<layout class="QVBoxLayout" name="mainLayout">
@@ -106,6 +106,13 @@
<item row="2" column="1">
<widget class="QComboBox" name="mResizeModeComboBox"/>
</item>
<item row="3" column="0" colspan="2">
<widget class="QCheckBox" name="mUseSmartBreaksCheckBox">
<property name="text">
<string>Use smart page breaks</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>

0 comments on commit ad0b4da

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