@@ -133,6 +133,10 @@ QSizeF QgsComposerTableV2::totalSize() const
133133 // TODO - handle multiple cell headers
134134 // also check height calculation function
135135
136+
137+
138+ // calculate total size
139+
136140 return mTableSize ;
137141}
138142
@@ -571,13 +575,48 @@ double QgsComposerTableV2::totalWidth()
571575
572576double QgsComposerTableV2::totalHeight () const
573577{
574- // calculate height
575- int n = mTableContents .size ();
576- double totalHeight = QgsComposerUtils::fontAscentMM ( mHeaderFont )
577- + n * QgsComposerUtils::fontAscentMM ( mContentFont )
578- + ( n + 1 ) * mCellMargin * 2
579- + ( n + 2 ) * ( mShowGrid ? mGridStrokeWidth : 0 );
580- return totalHeight;
578+ double height = 0 ;
579+
580+ // loop through all existing frames to calculate how many rows are visible in each
581+ // as the entire height of a frame may not be utilised for content rows
582+ int rowsAlreadyShown = 0 ;
583+ int numberExistingFrames = frameCount ();
584+ int rowsVisibleInLastFrame = 0 ;
585+ double heightOfLastFrame = 0 ;
586+ for ( int idx = 0 ; idx < numberExistingFrames; ++idx )
587+ {
588+ rowsVisibleInLastFrame = rowsVisible ( idx );
589+ heightOfLastFrame = frame ( idx )->rect ().height ();
590+ rowsAlreadyShown += rowsVisibleInLastFrame;
591+ height += heightOfLastFrame;
592+ if ( rowsAlreadyShown >= mTableContents .length () )
593+ {
594+ // shown entire contents of table, nothing remaining
595+ return height;
596+ }
597+ }
598+
599+ // calculate how many rows left to show
600+ int remainingRows = mTableContents .length () - rowsAlreadyShown;
601+
602+ if ( remainingRows <= 0 )
603+ {
604+ // no remaining rows
605+ return height;
606+ }
607+
608+ if ( rowsVisibleInLastFrame < 1 )
609+ {
610+ // if no rows are visible in the last frame, calculation of missing frames
611+ // is impossible. So just return total height of existing frames
612+ return height;
613+ }
614+
615+ // rows remain unshown -- how many extra frames would we need to complete the table?
616+ // assume all added frames are same size as final frame
617+ int numberFramesMissing = ceil (( double )remainingRows / ( double )rowsVisibleInLastFrame );
618+ height += heightOfLastFrame * numberFramesMissing;
619+ return height;
581620}
582621
583622void QgsComposerTableV2::drawHorizontalGridLines ( QPainter *painter, const int rows, const bool drawHeaderLines ) const
0 commit comments