Skip to content

Commit 5029834

Browse files
committed
[composer] Fix crash setting table columns from python
(cherry-picked from 39d0ba5)
1 parent eab09f0 commit 5029834

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

python/core/composer/qgscomposertablev2.sip

+3-2
Original file line numberDiff line numberDiff line change
@@ -347,10 +347,11 @@ class QgsComposerTableV2: QgsComposerMultiFrame
347347
QgsComposerTableColumns* columns();
348348

349349
/** Replaces the columns in the table with a specified list of QgsComposerTableColumns.
350-
* @param columns list of QgsComposerTableColumns to show in table
350+
* @param columns list of QgsComposerTableColumns to show in table. Ownership of columns
351+
* is transferred to the table.
351352
* @see columns
352353
*/
353-
void setColumns( const QgsComposerTableColumns& columns );
354+
void setColumns( const QgsComposerTableColumns& columns /Transfer/ );
354355

355356
/** Sets the cell style for a cell group.
356357
* @param group group to set style for

src/core/composer/qgscomposertablev2.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ void QgsComposerTableV2::render( QPainter *p, const QRectF &, const int frameInd
427427
{
428428
//draw the headers
429429
int col = 0;
430-
for ( QList<QgsComposerTableColumn*>::const_iterator columnIt = mColumns.constBegin(); columnIt != mColumns.constEnd(); ++columnIt )
430+
Q_FOREACH ( const QgsComposerTableColumn* column, mColumns )
431431
{
432432
//draw background
433433
p->save();
@@ -439,7 +439,7 @@ void QgsComposerTableV2::render( QPainter *p, const QRectF &, const int frameInd
439439
currentX += mCellMargin;
440440

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

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

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

496496

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

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

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

528528
currentX += mMaxColumnWidthMap[ col ];
529529
currentX += mCellMargin;

src/core/composer/qgscomposertablev2.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,8 @@ class CORE_EXPORT QgsComposerTableV2: public QgsComposerMultiFrame
372372
QgsComposerTableColumns* columns() { return &mColumns; }
373373

374374
/** Replaces the columns in the table with a specified list of QgsComposerTableColumns.
375-
* @param columns list of QgsComposerTableColumns to show in table
375+
* @param columns list of QgsComposerTableColumns to show in table. Ownership of columns
376+
* is transferred to the table.
376377
* @see columns
377378
*/
378379
void setColumns( const QgsComposerTableColumns& columns );

0 commit comments

Comments
 (0)