Skip to content
Permalink
Browse files

[composer] Tweak calculation of total height of table (Sponsored by

City of Uster, Switzerland)
  • Loading branch information
nyalldawson committed Sep 16, 2014
1 parent a0db663 commit 993aa83306694434dd6f48ef714b2aec5a46ec4d
@@ -155,10 +155,20 @@ int QgsComposerTableV2::rowsVisible( const int frameIndex ) const
}
QRectF frameExtent = frame( frameIndex )->extent();

//calculate header height
double headerHeight = 0;
bool includeHeader = false;
if (( mHeaderMode == QgsComposerTableV2::FirstFrame && frameIndex < 1 )
|| ( mHeaderMode == QgsComposerTableV2::AllFrames ) )
{
includeHeader = true;
}
return rowsVisible( frameExtent.height(), includeHeader );
}

int QgsComposerTableV2::rowsVisible( const double frameHeight, const bool includeHeader ) const
{
//calculate header height
double headerHeight = 0;
if ( includeHeader )
{
//frame has a header
headerHeight = 2 * ( mShowGrid ? mGridStrokeWidth : 0 ) + 2 * mCellMargin + QgsComposerUtils::fontAscentMM( mHeaderFont );
@@ -170,7 +180,7 @@ int QgsComposerTableV2::rowsVisible( const int frameIndex ) const
}

//remaining height available for content rows
double contentHeight = frameExtent.height() - headerHeight;
double contentHeight = frameHeight - headerHeight;

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

//since contents have changed, we also need to recalculate the column widths
//and size of table
adjustFrameToSize();
//gettablecontents does this!
// adjustFrameToSize();
}

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

if ( mResizeMode == QgsComposerMultiFrame::ExtendToNextPage )
{
heightOfLastFrame = mComposition->paperHeight();
bool hasHeader = (( mHeaderMode == QgsComposerTableV2::FirstFrame && numberExistingFrames < 1 )
|| ( mHeaderMode == QgsComposerTableV2::AllFrames ) );
rowsVisibleInLastFrame = rowsVisible( heightOfLastFrame, hasHeader );
}

//calculate how many rows left to show
int remainingRows = mTableContents.length() - rowsAlreadyShown;

@@ -685,9 +704,10 @@ void QgsComposerTableV2::drawVerticalGridLines( QPainter *painter, const QMap<in
void QgsComposerTableV2::adjustFrameToSize()
{
mTableSize = QSizeF( totalWidth(), totalHeight() );

recalculateFrameSizes();

//force recalculation of frame rects, so that they are set to the correct
//fixed and minimum frame sizes
recalculateFrameRects();

recalculateFrameSizes();
}
@@ -329,6 +329,8 @@ class CORE_EXPORT QgsComposerTableV2: public QgsComposerMultiFrame
*/
int rowsVisible( const int frameIndex ) const;

int rowsVisible( const double frameHeight, const bool includeHeader ) const;

/**Calculates a range of rows which should be visible in a given
* rectangle.
* @param extent visible extent
@@ -337,7 +339,6 @@ class CORE_EXPORT QgsComposerTableV2: public QgsComposerMultiFrame
*/
QPair<int, int> rowRange( const QRectF extent, const int frameIndex ) const;


/**Draws the horizontal grid lines for the table.
* @param painter destination painter for grid lines
* @param rows number of rows shown in table
@@ -47,6 +47,7 @@ class TestQgsComposerTableV2: public QObject
void attributeTableRender(); //test rendering attribute table

void attributeTableExtend();
void attributeTableRepeat();

private:
QgsComposition* mComposition;
@@ -314,7 +315,32 @@ void TestQgsComposerTableV2::attributeTableExtend()
//now auto remove extra created frames
mComposerAttributeTable->setMaximumNumberOfFeatures( 1 );
bool result = checker.testComposition( mReport, 1 );
}

void TestQgsComposerTableV2::attributeTableRepeat()
{
mComposerAttributeTable->setResizeMode( QgsComposerMultiFrame::UseExistingFrames );
//remove extra frames
for ( int idx = mComposerAttributeTable->frameCount(); idx > 0; --idx )
{
mComposerAttributeTable->removeFrame( idx - 1 );
}

mComposerAttributeTable->setMaximumNumberOfFeatures( 1 );

//force auto creation of some new frames
mComposerAttributeTable->setResizeMode( QgsComposerMultiFrame::RepeatUntilFinished );

for ( int features = 0; features < 50; ++features )
{
mComposerAttributeTable->setMaximumNumberOfFeatures( features );
}

//and then the reverse....
for ( int features = 50; features > 1; --features )
{
mComposerAttributeTable->setMaximumNumberOfFeatures( features );
}
}

QTEST_MAIN( TestQgsComposerTableV2 )

0 comments on commit 993aa83

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