Skip to content

Commit

Permalink
[composer] Add checkbox for controlling whether html items should use…
Browse files Browse the repository at this point in the history
… smart page breaking (sponsored by City of Uster, Switzerland)
  • Loading branch information
nyalldawson committed Apr 28, 2014
1 parent 8059a75 commit ad0b4da
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 8 deletions.
17 changes: 16 additions & 1 deletion python/core/composer/qgscomposerhtml.sip
Expand Up @@ -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 );
};
22 changes: 20 additions & 2 deletions src/app/composer/qgscomposerhtmlwidget.cpp
Expand Up @@ -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()
Expand Down Expand Up @@ -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 )
Expand All @@ -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 );
}


1 change: 1 addition & 0 deletions src/app/composer/qgscomposerhtmlwidget.h
Expand Up @@ -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();
Expand Down
27 changes: 23 additions & 4 deletions src/core/composer/qgscomposerhtml.cpp
Expand Up @@ -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();
Expand All @@ -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 )
{
}

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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() )
{
Expand Down
16 changes: 16 additions & 0 deletions src/core/composer/qgscomposerhtml.h
Expand Up @@ -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 );

Expand All @@ -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

Expand Down
9 changes: 8 additions & 1 deletion src/ui/qgscomposerhtmlwidgetbase.ui
Expand Up @@ -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">
Expand Down Expand Up @@ -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>
Expand Down

0 comments on commit ad0b4da

Please sign in to comment.