Skip to content
Permalink
Browse files

[FEATURE][composer] Add option to table item to show headers on first

frame, all frames, or no frames (fix #11136) (Sponsored by City of
Uster, Switzerland)
  • Loading branch information
nyalldawson committed Sep 17, 2014
1 parent c833a93 commit 2d24b322e949a326b114535a9ae3ab0548ef23a2
@@ -467,6 +467,7 @@ void QgsComposerAttributeTableWidget::updateGuiElements()
mFeatureFilterButton->setEnabled( mComposerTable->filterFeatures() );

mHeaderHAlignmentComboBox->setCurrentIndex(( int )mComposerTable->headerHAlignment() );
mHeaderModeComboBox->setCurrentIndex(( int )mComposerTable->headerMode() );

blockAllSignals( false );
}
@@ -484,6 +485,7 @@ void QgsComposerAttributeTableWidget::blockAllSignals( bool b )
mFeatureFilterEdit->blockSignals( b );
mFeatureFilterCheckBox->blockSignals( b );
mHeaderHAlignmentComboBox->blockSignals( b );
mHeaderModeComboBox->blockSignals( b );
mHeaderFontColorButton->blockSignals( b );
mContentFontColorButton->blockSignals( b );
}
@@ -620,6 +622,25 @@ void QgsComposerAttributeTableWidget::on_mHeaderHAlignmentComboBox_currentIndexC
}
}

void QgsComposerAttributeTableWidget::on_mHeaderModeComboBox_currentIndexChanged( int index )
{
if ( !mComposerTable )
{
return;
}

QgsComposition* composition = mComposerTable->composition();
if ( composition )
{
composition->beginMultiFrameCommand( mComposerTable, tr( "Table header mode changed" ) );
}
mComposerTable->setHeaderMode(( QgsComposerTableV2::HeaderMode )index );
if ( composition )
{
composition->endMultiFrameCommand();
}
}

void QgsComposerAttributeTableWidget::changeLayer( QgsMapLayer *layer )
{
if ( !mComposerTable )
@@ -60,6 +60,7 @@ class QgsComposerAttributeTableWidget: public QgsComposerItemBaseWidget, private
void on_mFeatureFilterEdit_editingFinished();
void on_mFeatureFilterButton_clicked();
void on_mHeaderHAlignmentComboBox_currentIndexChanged( int index );
void on_mHeaderModeComboBox_currentIndexChanged( int index );
void changeLayer( QgsMapLayer* layer );
void on_mAddFramePushButton_clicked();

@@ -26,6 +26,7 @@ QgsComposerTableV2::QgsComposerTableV2( QgsComposition *composition, bool create
, mCellMargin( 1.0 )
, mHeaderFontColor( Qt::black )
, mHeaderHAlignment( FollowColumn )
, mHeaderMode( FirstFrame )
, mContentFontColor( Qt::black )
, mShowGrid( true )
, mGridStrokeWidth( 0.5 )
@@ -100,6 +101,7 @@ bool QgsComposerTableV2::readXML( const QDomElement &itemElem, const QDomDocumen
mHeaderFont.fromString( itemElem.attribute( "headerFont", "" ) );
mHeaderFontColor = QgsSymbolLayerV2Utils::decodeColor( itemElem.attribute( "headerFontColor", "0,0,0,255" ) );
mHeaderHAlignment = QgsComposerTableV2::HeaderHAlignment( itemElem.attribute( "headerHAlignment", "0" ).toInt() );
mHeaderMode = QgsComposerTableV2::HeaderMode( itemElem.attribute( "headerMode", "0" ).toInt() );
mContentFont.fromString( itemElem.attribute( "contentFont", "" ) );
mContentFontColor = QgsSymbolLayerV2Utils::decodeColor( itemElem.attribute( "contentFontColor", "0,0,0,255" ) );
mCellMargin = itemElem.attribute( "cellMargin", "1.0" ).toDouble();
@@ -139,16 +141,15 @@ QSizeF QgsComposerTableV2::totalSize() const
QPair< int, int > QgsComposerTableV2::rowRange( const QRectF extent, const int frameIndex ) const
{
//calculate row height
//TODO - handle different header modes
//TODO - need to traverse all previous frames to calculate what is visible in each
//as the entire height of a frame may not be used for content
double headerHeight = 0;
double firstHeaderHeight = 2 * mGridStrokeWidth + 2 * mCellMargin + QgsComposerUtils::fontAscentMM( mHeaderFont );

//int frameNumber = mFrameItems.indexOf( this );
if ( frameIndex < 1 )
if (( mHeaderMode == QgsComposerTableV2::FirstFrame && frameIndex < 1 )
|| ( mHeaderMode == QgsComposerTableV2::AllFrames ) )
{
//currently only header on first
//frame has a header
headerHeight = firstHeaderHeight;
}
else
@@ -204,9 +205,9 @@ void QgsComposerTableV2::render( QPainter *p, const QRectF &renderExtent, const
double cellBodyHeight = QgsComposerUtils::fontAscentMM( mContentFont ) + 2 * mCellMargin;
QRectF cell;

//TODO - should be controlled via a property, eg an enum with values
//always/never/first frame
bool drawHeader = frameIndex < 1;
//calculate whether a header is required
bool drawHeader = (( mHeaderMode == QgsComposerTableV2::FirstFrame && frameIndex < 1 )
|| ( mHeaderMode == QgsComposerTableV2::AllFrames ) );

for ( ; columnIt != mColumns.constEnd(); ++columnIt )
{
@@ -325,6 +326,18 @@ void QgsComposerTableV2::setHeaderHAlignment( const QgsComposerTableV2::HeaderHA
repaint();
}

void QgsComposerTableV2::setHeaderMode( const QgsComposerTableV2::HeaderMode mode )
{
if ( mode == mHeaderMode )
{
return;
}

mHeaderMode = mode;
adjustFrameToSize();

}

void QgsComposerTableV2::setContentFont( const QFont &font )
{
if ( font == mContentFont )
@@ -415,10 +428,10 @@ QSizeF QgsComposerTableV2::fixedFrameSize( const int frameIndex ) const
QSizeF QgsComposerTableV2::minFrameSize( const int frameIndex ) const
{
double height = 0;
if ( frameIndex == 0 )
if (( mHeaderMode == QgsComposerTableV2::FirstFrame && frameIndex < 1 )
|| ( mHeaderMode == QgsComposerTableV2::AllFrames ) )
{
//force first frame to be high enough for header
//TODO - handle different header modes
//header required, force frame to be high enough for header
height = 2 * mGridStrokeWidth + 2 * mCellMargin + QgsComposerUtils::fontAscentMM( mHeaderFont );
}
return QSizeF( 0, height );
@@ -449,7 +462,12 @@ bool QgsComposerTableV2::calculateMaxColumnWidths()
int col = 0;
for ( ; columnIt != mColumns.constEnd(); ++columnIt )
{
mMaxColumnWidthMap.insert( col, QgsComposerUtils::textWidthMM( mHeaderFont, ( *columnIt )->heading() ) );
double width = 0;
if ( mHeaderMode != QgsComposerTableV2::NoHeaders )
{
width = QgsComposerUtils::textWidthMM( mHeaderFont, ( *columnIt )->heading() );
}
mMaxColumnWidthMap.insert( col, width );
col++;
}

@@ -63,6 +63,15 @@ class CORE_EXPORT QgsComposerTableV2: public QgsComposerMultiFrame
HeaderRight /*!< align headers right */
};

/*! Controls where headers are shown in the table
*/
enum HeaderMode
{
FirstFrame = 0, /*!< header shown on first frame only */
AllFrames, /*!< headers shown on all frames */
NoHeaders /*!< no headers shown for table */
};

QgsComposerTableV2( QgsComposition* composition, bool createUndoCommands );
QgsComposerTableV2();

@@ -131,6 +140,20 @@ class CORE_EXPORT QgsComposerTableV2: public QgsComposerMultiFrame
*/
HeaderHAlignment headerHAlignment() const { return mHeaderHAlignment; }

/**Sets the display mode for headers in the table. This property controls
* if and where headers are shown in the table.
* @param mode display mode for headers
* @see headerMode
*/
void setHeaderMode( const HeaderMode mode );

/**Returns the display mode for headers in the table. This property controls
* if and where headers are shown in the table.
* @returns display mode for headers
* @see setHeaderMode
*/
HeaderMode headerMode() const { return mHeaderMode; }

/**Sets the font used to draw text in table body cells.
* @param font font for table cells
* @see contentFont
@@ -263,6 +286,9 @@ class CORE_EXPORT QgsComposerTableV2: public QgsComposerMultiFrame
/**Alignment for table headers*/
HeaderHAlignment mHeaderHAlignment;

/**Header display mode*/
HeaderMode mHeaderMode;

/**Table contents font*/
QFont mContentFont;

@@ -45,9 +45,9 @@
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<y>-21</y>
<width>392</width>
<height>813</height>
<height>846</height>
</rect>
</property>
<layout class="QVBoxLayout" name="mainLayout">
@@ -297,7 +297,14 @@
<string>Table heading</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="1" colspan="2">
<item row="1" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Display</string>
</property>
</widget>
</item>
<item row="5" column="1" colspan="2">
<widget class="QComboBox" name="mHeaderHAlignmentComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
@@ -327,35 +334,35 @@
</item>
</widget>
</item>
<item row="3" column="0">
<item row="5" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Alignment</string>
</property>
</widget>
</item>
<item row="2" column="0">
<item row="4" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Color</string>
</property>
</widget>
</item>
<item row="0" column="0">
<item row="2" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Font</string>
</property>
</widget>
</item>
<item row="0" column="1" colspan="2">
<item row="2" column="1" colspan="2">
<widget class="QPushButton" name="mHeaderFontPushButton">
<property name="text">
<string>Choose font...</string>
</property>
</widget>
</item>
<item row="2" column="1" colspan="2">
<item row="4" column="1" colspan="2">
<widget class="QgsColorButtonV2" name="mHeaderFontColorButton">
<property name="minimumSize">
<size>
@@ -374,6 +381,25 @@
</property>
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="QComboBox" name="mHeaderModeComboBox">
<item>
<property name="text">
<string>On first frame</string>
</property>
</item>
<item>
<property name="text">
<string>On all frames</string>
</property>
</item>
<item>
<property name="text">
<string>No header</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
</item>

0 comments on commit 2d24b32

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