Skip to content
Permalink
Browse files

[composer] Fix crash setting table columns from python

  • Loading branch information
nyalldawson committed Apr 7, 2016
1 parent fde77d3 commit 39d0ba5781c8b759faaaf333b54e886c01a2d910
@@ -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
@@ -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();
@@ -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
@@ -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;
@@ -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;
@@ -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();
@@ -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;
@@ -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 );

0 comments on commit 39d0ba5

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