Skip to content

Commit ad0b4da

Browse files
committedApr 28, 2014
[composer] Add checkbox for controlling whether html items should use smart page breaking (sponsored by City of Uster, Switzerland)
1 parent 8059a75 commit ad0b4da

File tree

6 files changed

+84
-8
lines changed

6 files changed

+84
-8
lines changed
 

‎python/core/composer/qgscomposerhtml.sip

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,19 @@ class QgsComposerHtml: QgsComposerMultiFrame
1919
bool readXML( const QDomElement& itemElem, const QDomDocument& doc, bool ignoreFrames = false );
2020

2121
void addFrame( QgsComposerFrame* frame, bool recalcFrameSizes = true );
22-
};
22+
23+
/**Returns whether html item is using smart breaks. Smart breaks prevent
24+
* the html frame contents from breaking mid-way though a line of text.
25+
* @returns true if html item is using smart breaks
26+
* @see setUseSmartBreaks
27+
*/
28+
bool useSmartBreaks() const;
29+
30+
/**Sets whether the html item should use smart breaks. Smart breaks prevent
31+
* the html frame contents from breaking mid-way though a line of text.
32+
* @param useSmartBreaks set to true to prevent content from breaking
33+
* mid-way through a line of text
34+
* @see useSmartBreaks
35+
*/
36+
void setUseSmartBreaks( bool useSmartBreaks );
37+
};

‎src/app/composer/qgscomposerhtmlwidget.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ void QgsComposerHtmlWidget::blockSignals( bool block )
6060
mUrlLineEdit->blockSignals( block );
6161
mFileToolButton->blockSignals( block );
6262
mResizeModeComboBox->blockSignals( block );
63+
mUseSmartBreaksCheckBox->blockSignals( block );
6364
}
6465

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

118+
void QgsComposerHtmlWidget::on_mUseSmartBreaksCheckBox_stateChanged( int state )
119+
{
120+
if ( !mHtml )
121+
{
122+
return;
123+
}
124+
125+
QgsComposition* composition = mHtml->composition();
126+
if ( composition )
127+
{
128+
blockSignals( true );
129+
composition->beginMultiFrameCommand( mHtml, tr( "Use smart breaks changed" ) );
130+
mHtml->setUseSmartBreaks( state );
131+
composition->endMultiFrameCommand();
132+
blockSignals( false );
133+
}
134+
}
135+
117136
void QgsComposerHtmlWidget::setGuiElementValues()
118137
{
119138
if ( !mHtml )
@@ -124,7 +143,6 @@ void QgsComposerHtmlWidget::setGuiElementValues()
124143
blockSignals( true );
125144
mUrlLineEdit->setText( mHtml->url().toString() );
126145
mResizeModeComboBox->setCurrentIndex( mResizeModeComboBox->findData( mHtml->resizeMode() ) );
146+
mUseSmartBreaksCheckBox->setChecked( mHtml->useSmartBreaks() );
127147
blockSignals( false );
128148
}
129-
130-

‎src/app/composer/qgscomposerhtmlwidget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class QgsComposerHtmlWidget: public QWidget, private Ui::QgsComposerHtmlWidgetBa
3131
void on_mUrlLineEdit_editingFinished();
3232
void on_mFileToolButton_clicked();
3333
void on_mResizeModeComboBox_currentIndexChanged( int index );
34+
void on_mUseSmartBreaksCheckBox_stateChanged( int state );
3435

3536
/**Sets the GUI elements to the values of mHtmlItem*/
3637
void setGuiElementValues();

‎src/core/composer/qgscomposerhtml.cpp

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@
2424
#include <QImage>
2525

2626
QgsComposerHtml::QgsComposerHtml( QgsComposition* c, bool createUndoCommands ): QgsComposerMultiFrame( c, createUndoCommands ),
27-
mWebPage( 0 ), mLoaded( false ), mHtmlUnitsToMM( 1.0 ), mRenderedPage( 0 )
27+
mWebPage( 0 ),
28+
mLoaded( false ),
29+
mHtmlUnitsToMM( 1.0 ),
30+
mRenderedPage( 0 ),
31+
mUseSmartBreaks( true )
2832
{
2933
mHtmlUnitsToMM = htmlUnitsToMM();
3034
mWebPage = new QWebPage();
@@ -35,7 +39,12 @@ QgsComposerHtml::QgsComposerHtml( QgsComposition* c, bool createUndoCommands ):
3539
}
3640
}
3741

38-
QgsComposerHtml::QgsComposerHtml(): QgsComposerMultiFrame( 0, false ), mWebPage( 0 ), mLoaded( false ), mHtmlUnitsToMM( 1.0 ), mRenderedPage( 0 )
42+
QgsComposerHtml::QgsComposerHtml(): QgsComposerMultiFrame( 0, false ),
43+
mWebPage( 0 ),
44+
mLoaded( false ),
45+
mHtmlUnitsToMM( 1.0 ),
46+
mRenderedPage( 0 ),
47+
mUseSmartBreaks( true )
3948
{
4049
}
4150

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

155164
double QgsComposerHtml::findNearbyPageBreak( double yPos )
156165
{
157-
if ( !mWebPage || !mRenderedPage )
166+
if ( !mWebPage || !mRenderedPage || !mUseSmartBreaks )
158167
{
159168
return yPos;
160169
}
@@ -228,10 +237,18 @@ double QgsComposerHtml::findNearbyPageBreak( double yPos )
228237
return candidates[0].first / htmlUnitsToMM();
229238
}
230239

240+
void QgsComposerHtml::setUseSmartBreaks( bool useSmartBreaks )
241+
{
242+
mUseSmartBreaks = useSmartBreaks;
243+
recalculateFrameSizes();
244+
}
245+
231246
bool QgsComposerHtml::writeXML( QDomElement& elem, QDomDocument & doc, bool ignoreFrames ) const
232247
{
233248
QDomElement htmlElem = doc.createElement( "ComposerHtml" );
234249
htmlElem.setAttribute( "url", mUrl.toString() );
250+
htmlElem.setAttribute( "useSmartBreaks", mUseSmartBreaks ? "true" : "false" );
251+
235252
bool state = _writeXML( htmlElem, doc, ignoreFrames );
236253
elem.appendChild( htmlElem );
237254
return state;
@@ -247,7 +264,9 @@ bool QgsComposerHtml::readXML( const QDomElement& itemElem, const QDomDocument&
247264
return false;
248265
}
249266

250-
//then load the set url
267+
mUseSmartBreaks = itemElem.attribute( "useSmartBreaks", "true" ) == "true" ? true : false;
268+
269+
//finally load the set url
251270
QString urlString = itemElem.attribute( "url" );
252271
if ( !urlString.isEmpty() )
253272
{

‎src/core/composer/qgscomposerhtml.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,21 @@ class CORE_EXPORT QgsComposerHtml: public QgsComposerMultiFrame
4444
//overriden to break frames without dividing lines of text
4545
double findNearbyPageBreak( double yPos );
4646

47+
/**Returns whether html item is using smart breaks. Smart breaks prevent
48+
* the html frame contents from breaking mid-way though a line of text.
49+
* @returns true if html item is using smart breaks
50+
* @see setUseSmartBreaks
51+
*/
52+
bool useSmartBreaks() const { return mUseSmartBreaks; }
53+
54+
/**Sets whether the html item should use smart breaks. Smart breaks prevent
55+
* the html frame contents from breaking mid-way though a line of text.
56+
* @param useSmartBreaks set to true to prevent content from breaking
57+
* mid-way through a line of text
58+
* @see useSmartBreaks
59+
*/
60+
void setUseSmartBreaks( bool useSmartBreaks );
61+
4762
private slots:
4863
void frameLoaded( bool ok );
4964

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

5874
double htmlUnitsToMM(); //calculate scale factor
5975

‎src/ui/qgscomposerhtmlwidgetbase.ui

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
<x>0</x>
4848
<y>0</y>
4949
<width>407</width>
50-
<height>348</height>
50+
<height>347</height>
5151
</rect>
5252
</property>
5353
<layout class="QVBoxLayout" name="mainLayout">
@@ -106,6 +106,13 @@
106106
<item row="2" column="1">
107107
<widget class="QComboBox" name="mResizeModeComboBox"/>
108108
</item>
109+
<item row="3" column="0" colspan="2">
110+
<widget class="QCheckBox" name="mUseSmartBreaksCheckBox">
111+
<property name="text">
112+
<string>Use smart page breaks</string>
113+
</property>
114+
</widget>
115+
</item>
109116
</layout>
110117
</widget>
111118
</item>

0 commit comments

Comments
 (0)
Please sign in to comment.