Skip to content

Commit dba794c

Browse files
committed
[composer] Draw text in tables by row, not column
Sponsored by City of Uster
1 parent 9b9dbff commit dba794c

File tree

1 file changed

+51
-31
lines changed

1 file changed

+51
-31
lines changed

src/core/composer/qgscomposertablev2.cpp

+51-31
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,6 @@ void QgsComposerTableV2::render( QPainter *p, const QRectF &renderExtent, const
277277
QPair< int, int > rowsToShow = rowRange( renderExtent, frameIndex );
278278

279279
double gridSize = mShowGrid ? mGridStrokeWidth : 0;
280-
QList<QgsComposerTableColumn*>::const_iterator columnIt = mColumns.constBegin();
281-
282-
int col = 0;
283280
double cellHeaderHeight = QgsComposerUtils::fontAscentMM( mHeaderFont ) + 2 * mCellMargin;
284281
double cellBodyHeight = QgsComposerUtils::fontAscentMM( mContentFont ) + 2 * mCellMargin;
285282
QRectF cell;
@@ -326,26 +323,27 @@ void QgsComposerTableV2::render( QPainter *p, const QRectF &renderExtent, const
326323
}
327324

328325
//now draw the text
329-
double currentX = gridSize;
330-
double currentY;
331326
p->setPen( Qt::SolidLine );
332-
for ( ; columnIt != mColumns.constEnd(); ++columnIt )
333-
{
334-
currentY = gridSize;
335-
currentX += mCellMargin;
336327

337-
Qt::TextFlag textFlag = ( Qt::TextFlag )0;
338-
if (( *columnIt )->width() <= 0 )
328+
double currentX = gridSize;
329+
double currentY = gridSize;
330+
if ( drawHeader )
331+
{
332+
//draw the headers
333+
int col = 0;
334+
for ( QList<QgsComposerTableColumn*>::const_iterator columnIt = mColumns.constBegin(); columnIt != mColumns.constEnd(); ++columnIt )
339335
{
340-
//automatic column width, so we use the Qt::TextDontClip flag when drawing contents, as this works nicer for italicised text
341-
//which may slightly exceed the calculated width
342-
//if column size was manually set then we do apply text clipping, to avoid painting text outside of columns width
343-
textFlag = Qt::TextDontClip;
344-
}
336+
currentX += mCellMargin;
337+
338+
Qt::TextFlag textFlag = ( Qt::TextFlag )0;
339+
if (( *columnIt )->width() <= 0 )
340+
{
341+
//automatic column width, so we use the Qt::TextDontClip flag when drawing contents, as this works nicer for italicised text
342+
//which may slightly exceed the calculated width
343+
//if column size was manually set then we do apply text clipping, to avoid painting text outside of columns width
344+
textFlag = Qt::TextDontClip;
345+
}
345346

346-
if ( drawHeader )
347-
{
348-
//draw the header
349347
cell = QRectF( currentX, currentY, mMaxColumnWidthMap[col], cellHeaderHeight );
350348

351349
//calculate alignment of header
@@ -368,31 +366,53 @@ void QgsComposerTableV2::render( QPainter *p, const QRectF &renderExtent, const
368366

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

371-
currentY += cellHeaderHeight;
372-
currentY += gridSize;
369+
currentX += mMaxColumnWidthMap[ col ];
370+
currentX += mCellMargin;
371+
currentX += gridSize;
372+
col++;
373373
}
374374

375-
if ( drawContents )
375+
currentY += cellHeaderHeight;
376+
currentY += gridSize;
377+
}
378+
379+
//now draw the body cells
380+
if ( drawContents )
381+
{
382+
//draw the attribute values
383+
for ( int row = rowsToShow.first; row < rowsToShow.second; ++row )
376384
{
377-
//draw the attribute values
378-
for ( int row = rowsToShow.first; row < rowsToShow.second; ++row )
385+
currentX = gridSize;
386+
int col = 0;
387+
for ( QList<QgsComposerTableColumn*>::const_iterator columnIt = mColumns.constBegin(); columnIt != mColumns.constEnd(); ++columnIt )
379388
{
389+
// currentY = gridSize;
390+
currentX += mCellMargin;
391+
392+
Qt::TextFlag textFlag = ( Qt::TextFlag )0;
393+
if (( *columnIt )->width() <= 0 )
394+
{
395+
//automatic column width, so we use the Qt::TextDontClip flag when drawing contents, as this works nicer for italicised text
396+
//which may slightly exceed the calculated width
397+
//if column size was manually set then we do apply text clipping, to avoid painting text outside of columns width
398+
textFlag = Qt::TextDontClip;
399+
}
400+
380401
cell = QRectF( currentX, currentY, mMaxColumnWidthMap[col], cellBodyHeight );
381402

382403
QVariant cellContents = mTableContents.at( row ).at( col );
383404
QString str = cellContents.toString();
384405

385406
QgsComposerUtils::drawText( p, cell, str, mContentFont, mContentFontColor, ( *columnIt )->hAlignment(), Qt::AlignVCenter, textFlag );
386407

387-
currentY += cellBodyHeight;
388-
currentY += gridSize;
408+
currentX += mMaxColumnWidthMap[ col ];
409+
currentX += mCellMargin;
410+
currentX += gridSize;
411+
col++;
389412
}
413+
currentY += cellBodyHeight;
414+
currentY += gridSize;
390415
}
391-
392-
currentX += mMaxColumnWidthMap[ col ];
393-
currentX += mCellMargin;
394-
currentX += gridSize;
395-
col++;
396416
}
397417

398418
//and the borders

0 commit comments

Comments
 (0)