Skip to content

Commit 993aa83

Browse files
committed
[composer] Tweak calculation of total height of table (Sponsored by
City of Uster, Switzerland)
1 parent a0db663 commit 993aa83

File tree

3 files changed

+54
-7
lines changed

3 files changed

+54
-7
lines changed

src/core/composer/qgscomposertablev2.cpp

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,20 @@ int QgsComposerTableV2::rowsVisible( const int frameIndex ) const
155155
}
156156
QRectF frameExtent = frame( frameIndex )->extent();
157157

158-
//calculate header height
159-
double headerHeight = 0;
158+
bool includeHeader = false;
160159
if (( mHeaderMode == QgsComposerTableV2::FirstFrame && frameIndex < 1 )
161160
|| ( mHeaderMode == QgsComposerTableV2::AllFrames ) )
161+
{
162+
includeHeader = true;
163+
}
164+
return rowsVisible( frameExtent.height(), includeHeader );
165+
}
166+
167+
int QgsComposerTableV2::rowsVisible( const double frameHeight, const bool includeHeader ) const
168+
{
169+
//calculate header height
170+
double headerHeight = 0;
171+
if ( includeHeader )
162172
{
163173
//frame has a header
164174
headerHeight = 2 * ( mShowGrid ? mGridStrokeWidth : 0 ) + 2 * mCellMargin + QgsComposerUtils::fontAscentMM( mHeaderFont );
@@ -170,7 +180,7 @@ int QgsComposerTableV2::rowsVisible( const int frameIndex ) const
170180
}
171181

172182
//remaining height available for content rows
173-
double contentHeight = frameExtent.height() - headerHeight;
183+
double contentHeight = frameHeight - headerHeight;
174184

175185
//calculate number of visible rows
176186
double rowHeight = ( mShowGrid ? mGridStrokeWidth : 0 ) + 2 * mCellMargin + QgsComposerUtils::fontAscentMM( mContentFont );
@@ -519,7 +529,8 @@ void QgsComposerTableV2::refreshAttributes()
519529

520530
//since contents have changed, we also need to recalculate the column widths
521531
//and size of table
522-
adjustFrameToSize();
532+
//gettablecontents does this!
533+
// adjustFrameToSize();
523534
}
524535

525536
bool QgsComposerTableV2::calculateMaxColumnWidths()
@@ -602,6 +613,14 @@ double QgsComposerTableV2::totalHeight() const
602613
}
603614
}
604615

616+
if ( mResizeMode == QgsComposerMultiFrame::ExtendToNextPage )
617+
{
618+
heightOfLastFrame = mComposition->paperHeight();
619+
bool hasHeader = (( mHeaderMode == QgsComposerTableV2::FirstFrame && numberExistingFrames < 1 )
620+
|| ( mHeaderMode == QgsComposerTableV2::AllFrames ) );
621+
rowsVisibleInLastFrame = rowsVisible( heightOfLastFrame, hasHeader );
622+
}
623+
605624
//calculate how many rows left to show
606625
int remainingRows = mTableContents.length() - rowsAlreadyShown;
607626

@@ -685,9 +704,10 @@ void QgsComposerTableV2::drawVerticalGridLines( QPainter *painter, const QMap<in
685704
void QgsComposerTableV2::adjustFrameToSize()
686705
{
687706
mTableSize = QSizeF( totalWidth(), totalHeight() );
707+
708+
recalculateFrameSizes();
709+
688710
//force recalculation of frame rects, so that they are set to the correct
689711
//fixed and minimum frame sizes
690712
recalculateFrameRects();
691-
692-
recalculateFrameSizes();
693713
}

src/core/composer/qgscomposertablev2.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,8 @@ class CORE_EXPORT QgsComposerTableV2: public QgsComposerMultiFrame
329329
*/
330330
int rowsVisible( const int frameIndex ) const;
331331

332+
int rowsVisible( const double frameHeight, const bool includeHeader ) const;
333+
332334
/**Calculates a range of rows which should be visible in a given
333335
* rectangle.
334336
* @param extent visible extent
@@ -337,7 +339,6 @@ class CORE_EXPORT QgsComposerTableV2: public QgsComposerMultiFrame
337339
*/
338340
QPair<int, int> rowRange( const QRectF extent, const int frameIndex ) const;
339341

340-
341342
/**Draws the horizontal grid lines for the table.
342343
* @param painter destination painter for grid lines
343344
* @param rows number of rows shown in table

tests/src/core/testqgscomposertablev2.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class TestQgsComposerTableV2: public QObject
4747
void attributeTableRender(); //test rendering attribute table
4848

4949
void attributeTableExtend();
50+
void attributeTableRepeat();
5051

5152
private:
5253
QgsComposition* mComposition;
@@ -314,7 +315,32 @@ void TestQgsComposerTableV2::attributeTableExtend()
314315
//now auto remove extra created frames
315316
mComposerAttributeTable->setMaximumNumberOfFeatures( 1 );
316317
bool result = checker.testComposition( mReport, 1 );
318+
}
319+
320+
void TestQgsComposerTableV2::attributeTableRepeat()
321+
{
322+
mComposerAttributeTable->setResizeMode( QgsComposerMultiFrame::UseExistingFrames );
323+
//remove extra frames
324+
for ( int idx = mComposerAttributeTable->frameCount(); idx > 0; --idx )
325+
{
326+
mComposerAttributeTable->removeFrame( idx - 1 );
327+
}
328+
329+
mComposerAttributeTable->setMaximumNumberOfFeatures( 1 );
317330

331+
//force auto creation of some new frames
332+
mComposerAttributeTable->setResizeMode( QgsComposerMultiFrame::RepeatUntilFinished );
333+
334+
for ( int features = 0; features < 50; ++features )
335+
{
336+
mComposerAttributeTable->setMaximumNumberOfFeatures( features );
337+
}
338+
339+
//and then the reverse....
340+
for ( int features = 50; features > 1; --features )
341+
{
342+
mComposerAttributeTable->setMaximumNumberOfFeatures( features );
343+
}
318344
}
319345

320346
QTEST_MAIN( TestQgsComposerTableV2 )

0 commit comments

Comments
 (0)