Navigation Menu

Skip to content

Commit

Permalink
[composer] Fix crash setting table columns from python
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Apr 7, 2016
1 parent fde77d3 commit 39d0ba5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
5 changes: 3 additions & 2 deletions python/core/composer/qgscomposertablev2.sip
Expand Up @@ -347,10 +347,11 @@ class QgsComposerTableV2: QgsComposerMultiFrame
QgsComposerTableColumns* columns();

/** Replaces the columns in the table with a specified list of QgsComposerTableColumns.
* @param columns list of QgsComposerTableColumns to show in table
* @param columns list of QgsComposerTableColumns to show in table. Ownership of columns
* is transferred to the table.
* @see columns
*/
void setColumns( const QgsComposerTableColumns& columns );
void setColumns( const QgsComposerTableColumns& columns /Transfer/ );

/** Sets the cell style for a cell group.
* @param group group to set style for
Expand Down
18 changes: 9 additions & 9 deletions src/core/composer/qgscomposertablev2.cpp
Expand Up @@ -427,7 +427,7 @@ void QgsComposerTableV2::render( QPainter *p, const QRectF &, const int frameInd
{
//draw the headers
int col = 0;
for ( QList<QgsComposerTableColumn*>::const_iterator columnIt = mColumns.constBegin(); columnIt != mColumns.constEnd(); ++columnIt )
Q_FOREACH ( const QgsComposerTableColumn* column, mColumns )
{
//draw background
p->save();
Expand All @@ -439,7 +439,7 @@ void QgsComposerTableV2::render( QPainter *p, const QRectF &, const int frameInd
currentX += mCellMargin;

Qt::TextFlag textFlag = static_cast< Qt::TextFlag >( 0 );
if (( *columnIt )->width() <= 0 )
if ( column->width() <= 0 )
{
//automatic column width, so we use the Qt::TextDontClip flag when drawing contents, as this works nicer for italicised text
//which may slightly exceed the calculated width
Expand All @@ -454,7 +454,7 @@ void QgsComposerTableV2::render( QPainter *p, const QRectF &, const int frameInd
switch ( mHeaderHAlignment )
{
case FollowColumn:
headerAlign = ( *columnIt )->hAlignment();
headerAlign = column->hAlignment();
break;
case HeaderLeft:
headerAlign = Qt::AlignLeft;
Expand All @@ -467,7 +467,7 @@ void QgsComposerTableV2::render( QPainter *p, const QRectF &, const int frameInd
break;
}

QgsComposerUtils::drawText( p, cell, ( *columnIt )->heading(), mHeaderFont, mHeaderFontColor, headerAlign, Qt::AlignVCenter, textFlag );
QgsComposerUtils::drawText( p, cell, column->heading(), mHeaderFont, mHeaderFontColor, headerAlign, Qt::AlignVCenter, textFlag );

currentX += mMaxColumnWidthMap[ col ];
currentX += mCellMargin;
Expand All @@ -494,7 +494,7 @@ void QgsComposerTableV2::render( QPainter *p, const QRectF &, const int frameInd
double rowHeight = mMaxRowHeightMap[row + 1] + 2 * mCellMargin;


for ( QList<QgsComposerTableColumn*>::const_iterator columnIt = mColumns.constBegin(); columnIt != mColumns.constEnd(); ++columnIt )
Q_FOREACH ( const QgsComposerTableColumn* column, mColumns )
{
//draw background
p->save();
Expand All @@ -510,20 +510,20 @@ void QgsComposerTableV2::render( QPainter *p, const QRectF &, const int frameInd
QString str = cellContents.toString();

Qt::TextFlag textFlag = static_cast< Qt::TextFlag >( 0 );
if (( *columnIt )->width() <= 0 && mWrapBehaviour == TruncateText )
if ( column->width() <= 0 && mWrapBehaviour == TruncateText )
{
//automatic column width, so we use the Qt::TextDontClip flag when drawing contents, as this works nicer for italicised text
//which may slightly exceed the calculated width
//if column size was manually set then we do apply text clipping, to avoid painting text outside of columns width
textFlag = Qt::TextDontClip;
}
else if ( textRequiresWrapping( str, ( *columnIt )->width(), mContentFont ) )
else if ( textRequiresWrapping( str, column->width(), mContentFont ) )
{
str = wrappedText( str, ( *columnIt )->width(), mContentFont );
str = wrappedText( str, column->width(), mContentFont );
}

cell = QRectF( currentX, currentY, mMaxColumnWidthMap[col], rowHeight );
QgsComposerUtils::drawText( p, cell, str, mContentFont, mContentFontColor, ( *columnIt )->hAlignment(), ( *columnIt )->vAlignment(), textFlag );
QgsComposerUtils::drawText( p, cell, str, mContentFont, mContentFontColor, column->hAlignment(), column->vAlignment(), textFlag );

currentX += mMaxColumnWidthMap[ col ];
currentX += mCellMargin;
Expand Down
3 changes: 2 additions & 1 deletion src/core/composer/qgscomposertablev2.h
Expand Up @@ -372,7 +372,8 @@ class CORE_EXPORT QgsComposerTableV2: public QgsComposerMultiFrame
QgsComposerTableColumns* columns() { return &mColumns; }

/** Replaces the columns in the table with a specified list of QgsComposerTableColumns.
* @param columns list of QgsComposerTableColumns to show in table
* @param columns list of QgsComposerTableColumns to show in table. Ownership of columns
* is transferred to the table.
* @see columns
*/
void setColumns( const QgsComposerTableColumns& columns );
Expand Down

0 comments on commit 39d0ba5

Please sign in to comment.