27 , mEmptyTableMode( HeadersOnly )
28 , mShowEmptyRows( false )
29 , mHeaderFontColor( Qt::black )
30 , mHeaderHAlignment( FollowColumn )
31 , mHeaderMode( FirstFrame )
32 , mContentFontColor( Qt::black )
34 , mGridStrokeWidth( 0.5 )
35 , mGridColor( Qt::black )
36 , mBackgroundColor( Qt::white )
46 QString defaultFontString = settings.value(
"/Composer/defaultFont" ).toString();
47 if ( !defaultFontString.isEmpty() )
57 , mEmptyTableMode( HeadersOnly )
58 , mShowEmptyRows( false )
59 , mHeaderFontColor( Qt::black )
60 , mHeaderHAlignment( FollowColumn )
61 , mHeaderMode( FirstFrame )
62 , mContentFontColor( Qt::black )
64 , mGridStrokeWidth( 0.5 )
65 , mGridColor( Qt::black )
66 , mBackgroundColor( Qt::white )
79 elem.setAttribute(
"cellMargin", QString::number(
mCellMargin ) );
80 elem.setAttribute(
"emptyTableMode", QString::number((
int )
mEmptyTableMode ) );
83 elem.setAttribute(
"headerFont",
mHeaderFont.toString() );
85 elem.setAttribute(
"headerHAlignment", QString::number((
int )
mHeaderHAlignment ) );
86 elem.setAttribute(
"headerMode", QString::number((
int )
mHeaderMode ) );
87 elem.setAttribute(
"contentFont",
mContentFont.toString() );
91 elem.setAttribute(
"showGrid",
mShowGrid );
95 QDomElement displayColumnsElem = doc.createElement(
"displayColumns" );
96 QList<QgsComposerTableColumn*>::const_iterator columnIt =
mColumns.constBegin();
97 for ( ; columnIt !=
mColumns.constEnd(); ++columnIt )
99 QDomElement columnElem = doc.createElement(
"column" );
100 ( *columnIt )->writeXML( columnElem, doc );
101 displayColumnsElem.appendChild( columnElem );
103 elem.appendChild( displayColumnsElem );
105 bool state =
_writeXML( elem, doc, ignoreFrames );
114 if ( !
_readXML( itemElem, doc, ignoreFrames ) )
119 if ( itemElem.isNull() )
126 mShowEmptyRows = itemElem.attribute(
"showEmptyRows",
"0" ).toInt();
127 mHeaderFont.fromString( itemElem.attribute(
"headerFont",
"" ) );
131 mContentFont.fromString( itemElem.attribute(
"contentFont",
"" ) );
133 mCellMargin = itemElem.attribute(
"cellMargin",
"1.0" ).toDouble();
134 mGridStrokeWidth = itemElem.attribute(
"gridStrokeWidth",
"0.5" ).toDouble();
135 mShowGrid = itemElem.attribute(
"showGrid",
"1" ).toInt();
142 QDomNodeList columnsList = itemElem.elementsByTagName(
"displayColumns" );
143 if ( columnsList.size() > 0 )
145 QDomElement columnsElem = columnsList.at( 0 ).toElement();
146 QDomNodeList columnEntryList = columnsElem.elementsByTagName(
"column" );
147 for (
int i = 0; i < columnEntryList.size(); ++i )
149 QDomElement columnElem = columnEntryList.at( i ).toElement();
171 QRectF frameExtent =
frame( frameIndex )->
extent();
173 bool includeHeader =
false;
177 includeHeader =
true;
179 return rowsVisible( frameExtent.height(), includeHeader );
185 double headerHeight = 0;
198 double contentHeight = frameHeight - headerHeight;
202 return qMax( floor( contentHeight / rowHeight ), 0.0 );
211 return qMakePair( 0, 0 );
216 int rowsAlreadyShown = 0;
222 double headerHeight = 0;
235 double contentHeight = extent.height() - headerHeight;
239 int firstVisible = qMin( rowsAlreadyShown,
mTableContents.length() );
240 int rowsVisible = qMax( floor( contentHeight / rowHeight ), 0.0 );
241 int lastVisible = qMin( firstVisible + rowsVisible,
mTableContents.length() );
243 return qMakePair( firstVisible, lastVisible );
262 QPair< int, int > rowsToShow =
rowRange( renderExtent, frameIndex );
273 QList<QgsComposerTableColumn*>::const_iterator columnIt =
mColumns.constBegin();
286 int numberRowsToDraw = rowsToShow.second - rowsToShow.first;
291 bool mergeCells =
false;
301 p->setRenderHint( QPainter::Antialiasing,
true );
307 p->setPen( Qt::NoPen );
309 double totalHeight = ( drawHeader || ( numberRowsToDraw > 0 ) ? gridSize : 0 ) +
310 ( drawHeader ? cellHeaderHeight + gridSize : 0.0 ) +
311 ( drawContents ? numberRowsToDraw : 1 ) * ( cellBodyHeight + gridSize );
313 if ( totalHeight > 0 )
316 p->drawRect( backgroundRect );
322 double currentX = gridSize;
324 p->setPen( Qt::SolidLine );
325 for ( ; columnIt !=
mColumns.constEnd(); ++columnIt )
330 Qt::TextFlag textFlag = ( Qt::TextFlag )0;
331 if (( *columnIt )->width() <= 0 )
336 textFlag = Qt::TextDontClip;
345 Qt::AlignmentFlag headerAlign = Qt::AlignLeft;
349 headerAlign = ( *columnIt )->hAlignment();
352 headerAlign = Qt::AlignLeft;
355 headerAlign = Qt::AlignHCenter;
358 headerAlign = Qt::AlignRight;
364 currentY += cellHeaderHeight;
365 currentY += gridSize;
371 for (
int row = rowsToShow.first; row < rowsToShow.second; ++row )
376 QString str = cellContents.toString();
380 currentY += cellBodyHeight;
381 currentY += gridSize;
387 currentX += gridSize;
397 gridPen.setJoinStyle( Qt::MiterJoin );
398 p->setPen( gridPen );
407 double messageY = gridSize + ( drawHeader ? cellHeaderHeight + gridSize : 0 );
408 cell = QRectF( messageX, messageY,
mTableSize.width() - messageX, cellBodyHeight );
618 QMap<int, QString> headers;
620 QgsComposerTableColumns::const_iterator columnIt =
mColumns.constBegin();
622 for ( ; columnIt !=
mColumns.constEnd(); ++columnIt )
624 headers.insert( col, ( *columnIt )->heading() );
632 Q_UNUSED( frameIndex );
645 return QSizeF( 0, height );
671 QgsComposerTableColumns::const_iterator columnIt =
mColumns.constBegin();
673 for ( ; columnIt !=
mColumns.constEnd(); ++columnIt )
676 if (( *columnIt )->width() > 0 )
679 width = ( *columnIt )->width();
691 QgsComposerTableContents::const_iterator rowIt =
mTableContents.constBegin();
692 double currentCellTextWidth;
695 QgsComposerTableRow::const_iterator colIt = rowIt->constBegin();
696 int columnNumber = 0;
697 for ( ; colIt != rowIt->constEnd(); ++colIt )
699 if (
mColumns.at( columnNumber )->width() <= 0 )
703 mMaxColumnWidthMap[ columnNumber ] = qMax( currentCellTextWidth, mMaxColumnWidthMap[ columnNumber ] );
725 totalWidth += maxColWidthIt.value();
739 int rowsAlreadyShown = 0;
741 int rowsVisibleInLastFrame = 0;
742 double heightOfLastFrame = 0;
743 for (
int idx = 0; idx < numberExistingFrames; ++idx )
747 heightOfLastFrame =
frame( idx )->rect().height();
748 rowsVisibleInLastFrame =
rowsVisible( heightOfLastFrame, hasHeader );
749 rowsAlreadyShown += rowsVisibleInLastFrame;
750 height += heightOfLastFrame;
763 rowsVisibleInLastFrame =
rowsVisible( heightOfLastFrame, hasHeader );
769 if ( remainingRows <= 0 )
775 if ( rowsVisibleInLastFrame < 1 )
784 int numberFramesMissing = ceil((
double )remainingRows / (
double )rowsVisibleInLastFrame );
785 height += heightOfLastFrame * numberFramesMissing;
792 if ( rows < 1 && !drawHeaderLines )
799 currentY = halfGridStrokeWidth;
800 if ( drawHeaderLines )
802 painter->drawLine( QPointF( halfGridStrokeWidth, currentY ), QPointF(
mTableSize.width() - halfGridStrokeWidth, currentY ) );
806 for (
int row = 0; row < rows; ++row )
808 painter->drawLine( QPointF( halfGridStrokeWidth, currentY ), QPointF(
mTableSize.width() - halfGridStrokeWidth, currentY ) );
812 painter->drawLine( QPointF( halfGridStrokeWidth, currentY ), QPointF(
mTableSize.width() - halfGridStrokeWidth, currentY ) );
818 if ( numberRows < 1 && !hasHeader )
824 double tableHeight = 0;
830 double headerHeight = tableHeight;
834 double currentX = halfGridStrokeWidth;
835 painter->drawLine( QPointF( currentX, halfGridStrokeWidth ), QPointF( currentX, tableHeight - halfGridStrokeWidth ) );
837 QMap<int, double>::const_iterator maxColWidthIt = maxWidthMap.constBegin();
839 for ( ; maxColWidthIt != maxWidthMap.constEnd(); ++maxColWidthIt )
841 currentX += ( maxColWidthIt.value() + 2 *
mCellMargin );
842 if ( col == maxWidthMap.size() || !mergeCells )
844 painter->drawLine( QPointF( currentX, halfGridStrokeWidth ), QPointF( currentX, tableHeight - halfGridStrokeWidth ) );
846 else if ( hasHeader )
848 painter->drawLine( QPointF( currentX, halfGridStrokeWidth ), QPointF( currentX, headerHeight - halfGridStrokeWidth ) );
867 if ( contents.indexOf( row ) >= 0 )