Skip to content

Commit 407a05c

Browse files
committedSep 17, 2014
[composer] Implement total height mechanisms for QgsComposerTableV2
(Sponsored by City of Uster, Switzerland)
1 parent 8171525 commit 407a05c

File tree

3 files changed

+75
-7
lines changed

3 files changed

+75
-7
lines changed
 

‎src/app/composer/qgscomposerattributetablewidget.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ QgsComposerAttributeTableWidget::QgsComposerAttributeTableWidget( QgsComposerAtt
4040
mainLayout->addWidget( itemPropertiesWidget );
4141

4242
blockAllSignals( true );
43+
44+
mResizeModeComboBox->addItem( tr( "Use existing frames" ), QgsComposerMultiFrame::UseExistingFrames );
45+
mResizeModeComboBox->addItem( tr( "Extend to next page" ), QgsComposerMultiFrame::ExtendToNextPage );
46+
mResizeModeComboBox->addItem( tr( "Repeat on every page" ), QgsComposerMultiFrame::RepeatOnEveryPage );
47+
mResizeModeComboBox->addItem( tr( "Repeat until finished" ), QgsComposerMultiFrame::RepeatUntilFinished );
48+
4349
mLayerComboBox->setFilters( QgsMapLayerProxyModel::VectorLayer );
4450
connect( mLayerComboBox, SIGNAL( layerChanged( QgsMapLayer* ) ), this, SLOT( changeLayer( QgsMapLayer* ) ) );
4551

@@ -468,6 +474,9 @@ void QgsComposerAttributeTableWidget::updateGuiElements()
468474
mHeaderHAlignmentComboBox->setCurrentIndex(( int )mComposerTable->headerHAlignment() );
469475
mHeaderModeComboBox->setCurrentIndex(( int )mComposerTable->headerMode() );
470476

477+
mResizeModeComboBox->setCurrentIndex( mResizeModeComboBox->findData( mComposerTable->resizeMode() ) );
478+
mAddFramePushButton->setEnabled( mComposerTable->resizeMode() == QgsComposerMultiFrame::UseExistingFrames );
479+
471480
blockAllSignals( false );
472481
}
473482

@@ -487,6 +496,7 @@ void QgsComposerAttributeTableWidget::blockAllSignals( bool b )
487496
mHeaderModeComboBox->blockSignals( b );
488497
mHeaderFontColorButton->blockSignals( b );
489498
mContentFontColorButton->blockSignals( b );
499+
mResizeModeComboBox->blockSignals( b );
490500
}
491501

492502
void QgsComposerAttributeTableWidget::setMaximumNumberOfFeatures( int n )
@@ -699,3 +709,21 @@ void QgsComposerAttributeTableWidget::on_mAddFramePushButton_clicked()
699709
composition->setSelectedItem( newFrame );
700710
}
701711
}
712+
713+
void QgsComposerAttributeTableWidget::on_mResizeModeComboBox_currentIndexChanged( int index )
714+
{
715+
if ( !mComposerTable )
716+
{
717+
return;
718+
}
719+
720+
QgsComposition* composition = mComposerTable->composition();
721+
if ( composition )
722+
{
723+
composition->beginMultiFrameCommand( mComposerTable, tr( "Change resize mode" ) );
724+
mComposerTable->setResizeMode(( QgsComposerMultiFrame::ResizeMode )mResizeModeComboBox->itemData( index ).toInt() );
725+
composition->endMultiFrameCommand();
726+
}
727+
728+
mAddFramePushButton->setEnabled( mComposerTable->resizeMode() == QgsComposerMultiFrame::UseExistingFrames );
729+
}

‎src/app/composer/qgscomposerattributetablewidget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class QgsComposerAttributeTableWidget: public QgsComposerItemBaseWidget, private
6363
void on_mHeaderModeComboBox_currentIndexChanged( int index );
6464
void changeLayer( QgsMapLayer* layer );
6565
void on_mAddFramePushButton_clicked();
66+
void on_mResizeModeComboBox_currentIndexChanged( int index );
6667

6768
/**Inserts a new maximum number of features into the spin box (without the spinbox emitting a signal)*/
6869
void setMaximumNumberOfFeatures( int n );

‎src/core/composer/qgscomposertablev2.cpp

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

572576
double 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

583622
void QgsComposerTableV2::drawHorizontalGridLines( QPainter *painter, const int rows, const bool drawHeaderLines ) const

0 commit comments

Comments
 (0)
Please sign in to comment.