Skip to content
Permalink
Browse files

[composer] Allow user to set maximum distance for page breaking in ht…

…ml items.
  • Loading branch information
nyalldawson committed May 8, 2014
1 parent 7bcba1f commit 0d3838759e881a252e807dbd461d2904b9f9926f
@@ -35,6 +35,31 @@ class QgsComposerHtml: QgsComposerMultiFrame
*/
void setUseSmartBreaks( bool useSmartBreaks );

/**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.
* @param maxBreakDistance maximum amount of empty space to leave when calculating
* page break locations
* @note added in 2.3
* @see maxBreakDistance
* @see setUseSmartBreaks
*/
void setMaxBreakDistance( double maxBreakDistance );

/**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 setMaxBreakDistance
* @see useSmartBreaks
*/
double maxBreakDistance() const;

public slots:

/**Reloads the html source from the url and redraws the item.
@@ -61,6 +61,7 @@ void QgsComposerHtmlWidget::blockSignals( bool block )
mFileToolButton->blockSignals( block );
mResizeModeComboBox->blockSignals( block );
mUseSmartBreaksCheckBox->blockSignals( block );
mMaxDistanceSpinBox->blockSignals( block );
}

void QgsComposerHtmlWidget::on_mUrlLineEdit_editingFinished()
@@ -117,7 +118,7 @@ void QgsComposerHtmlWidget::on_mResizeModeComboBox_currentIndexChanged( int inde
mAddFramePushButton->setEnabled( mHtml->resizeMode() == QgsComposerMultiFrame::UseExistingFrames );
}

void QgsComposerHtmlWidget::on_mUseSmartBreaksCheckBox_stateChanged( int state )
void QgsComposerHtmlWidget::on_mUseSmartBreaksCheckBox_toggled( bool checked )
{
if ( !mHtml )
{
@@ -129,12 +130,22 @@ void QgsComposerHtmlWidget::on_mUseSmartBreaksCheckBox_stateChanged( int state )
{
blockSignals( true );
composition->beginMultiFrameCommand( mHtml, tr( "Use smart breaks changed" ) );
mHtml->setUseSmartBreaks( state );
mHtml->setUseSmartBreaks( checked );
composition->endMultiFrameCommand();
blockSignals( false );
}
}

void QgsComposerHtmlWidget::on_mMaxDistanceSpinBox_valueChanged( double val )
{
if ( !mHtml )
{
return;
}

mHtml->setMaxBreakDistance( val );
}

void QgsComposerHtmlWidget::on_mReloadPushButton_clicked()
{
if ( !mHtml )
@@ -179,6 +190,7 @@ void QgsComposerHtmlWidget::setGuiElementValues()
mUrlLineEdit->setText( mHtml->url().toString() );
mResizeModeComboBox->setCurrentIndex( mResizeModeComboBox->findData( mHtml->resizeMode() ) );
mUseSmartBreaksCheckBox->setChecked( mHtml->useSmartBreaks() );
mMaxDistanceSpinBox->setValue( mHtml->maxBreakDistance() );

mAddFramePushButton->setEnabled( mHtml->resizeMode() == QgsComposerMultiFrame::UseExistingFrames );
blockSignals( false );
@@ -31,7 +31,9 @@ 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 );
void on_mUseSmartBreaksCheckBox_toggled( bool checked );
void on_mMaxDistanceSpinBox_valueChanged( double val );

void on_mReloadPushButton_clicked();
void on_mAddFramePushButton_clicked();

@@ -30,7 +30,8 @@ QgsComposerHtml::QgsComposerHtml( QgsComposition* c, bool createUndoCommands ):
mLoaded( false ),
mHtmlUnitsToMM( 1.0 ),
mRenderedPage( 0 ),
mUseSmartBreaks( true )
mUseSmartBreaks( true ),
mMaxBreakDistance( 10 )
{
mHtmlUnitsToMM = htmlUnitsToMM();
mWebPage = new QWebPage();
@@ -48,7 +49,8 @@ QgsComposerHtml::QgsComposerHtml(): QgsComposerMultiFrame( 0, false ),
mLoaded( false ),
mHtmlUnitsToMM( 1.0 ),
mRenderedPage( 0 ),
mUseSmartBreaks( true )
mUseSmartBreaks( true ),
mMaxBreakDistance( 10 )
{
}

@@ -191,7 +193,7 @@ double QgsComposerHtml::findNearbyPageBreak( double yPos )
return yPos;
}

int maxSearchDistance = 100;
int maxSearchDistance = mMaxBreakDistance * htmlUnitsToMM();

//loop through all lines just before ideal break location, up to max distance
//of maxSearchDistance
@@ -256,13 +258,22 @@ void QgsComposerHtml::setUseSmartBreaks( bool useSmartBreaks )
{
mUseSmartBreaks = useSmartBreaks;
recalculateFrameSizes();
emit changed();
}

void QgsComposerHtml::setMaxBreakDistance( double maxBreakDistance )
{
mMaxBreakDistance = maxBreakDistance;
recalculateFrameSizes();
emit changed();
}

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" );
htmlElem.setAttribute( "maxBreakDistance", QString::number( mMaxBreakDistance ) );

bool state = _writeXML( htmlElem, doc, ignoreFrames );
elem.appendChild( htmlElem );
@@ -280,6 +291,7 @@ bool QgsComposerHtml::readXML( const QDomElement& itemElem, const QDomDocument&
}

mUseSmartBreaks = itemElem.attribute( "useSmartBreaks", "true" ) == "true" ? true : false;
mMaxBreakDistance = itemElem.attribute( "maxBreakDistance", "10" ).toDouble();

//finally load the set url
QString urlString = itemElem.attribute( "url" );
@@ -59,6 +59,31 @@ class CORE_EXPORT QgsComposerHtml: public QgsComposerMultiFrame
*/
void setUseSmartBreaks( bool useSmartBreaks );

/**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.
* @param maxBreakDistance maximum amount of empty space to leave when calculating
* page break locations
* @note added in 2.3
* @see maxBreakDistance
* @see setUseSmartBreaks
*/
void setMaxBreakDistance( double maxBreakDistance );

/**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 setMaxBreakDistance
* @see useSmartBreaks
*/
double maxBreakDistance() const { return mMaxBreakDistance; }

public slots:

/**Reloads the html source from the url and redraws the item.
@@ -78,6 +103,7 @@ class CORE_EXPORT QgsComposerHtml: public QgsComposerMultiFrame
double mHtmlUnitsToMM;
QImage* mRenderedPage;
bool mUseSmartBreaks;
double mMaxBreakDistance;

double htmlUnitsToMM(); //calculate scale factor

@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>409</width>
<height>370</height>
<height>383</height>
</rect>
</property>
<property name="windowTitle">
@@ -47,7 +47,7 @@
<x>0</x>
<y>0</y>
<width>407</width>
<height>347</height>
<height>360</height>
</rect>
</property>
<layout class="QVBoxLayout" name="mainLayout">
@@ -107,17 +107,51 @@
<item row="2" column="1">
<widget class="QComboBox" name="mResizeModeComboBox"/>
</item>
<item row="4" column="0" colspan="2">
<item row="3" column="0" colspan="2">
<widget class="QPushButton" name="mAddFramePushButton">
<property name="text">
<string>Add Frame</string>
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<widget class="QCheckBox" name="mUseSmartBreaksCheckBox">
</layout>
</widget>
</item>
<item>
<widget class="QgsCollapsibleGroupBoxBasic" name="mUseSmartBreaksCheckBox">
<property name="title">
<string>Use smart page breaks</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<property name="collapsed" stdset="0">
<bool>true</bool>
</property>
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="mLabelMaxDistance">
<property name="text">
<string>Use smart page breaks</string>
<string>Maximum distance</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QDoubleSpinBox" name="mMaxDistanceSpinBox">
<property name="suffix">
<string> mm</string>
</property>
<property name="decimals">
<number>1</number>
</property>
<property name="maximum">
<double>1000.000000000000000</double>
</property>
<property name="singleStep">
<double>1.000000000000000</double>
</property>
</widget>
</item>

0 comments on commit 0d38387

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