28 , mLineTextDistance( 1.0 )
29 , mHeaderFontColor( Qt::black )
30 , mContentFontColor( Qt::black )
31 , mHeaderHAlignment( FollowColumn )
33 , mGridStrokeWidth( 0.5 )
34 , mGridColor( QColor( 0, 0, 0 ) )
38 QString defaultFontString = settings.value(
"/Composer/defaultFont" ).toString();
39 if ( !defaultFontString.isEmpty() )
70 Q_UNUSED( itemStyle );
92 painter->setRenderHint( QPainter::Antialiasing,
true );
94 painter->setPen( Qt::SolidLine );
100 QList<QgsComposerTableColumn*>::const_iterator columnIt =
mColumns.constBegin();
106 for ( ; columnIt !=
mColumns.constEnd(); ++columnIt )
114 Qt::AlignmentFlag headerAlign = Qt::AlignLeft;
118 headerAlign = ( *columnIt )->hAlignment();
121 headerAlign = Qt::AlignLeft;
124 headerAlign = Qt::AlignHCenter;
127 headerAlign = Qt::AlignRight;
133 currentY += cellHeaderHeight;
137 QList<QgsAttributeMap>::const_iterator attIt =
mAttributeMaps.begin();
143 QString str = currentAttributeMap[ col ].toString();
146 currentY += cellBodyHeight;
162 gridPen.setJoinStyle( Qt::MiterJoin );
163 painter->setPen( gridPen );
246 QMap<int, QString> headers;
248 QList<QgsComposerTableColumn*>::const_iterator columnIt =
mColumns.constBegin();
250 for ( ; columnIt !=
mColumns.constEnd(); ++columnIt )
252 headers.insert( col, ( *columnIt )->heading() );
270 elem.setAttribute(
"headerFont",
mHeaderFont.toString() );
272 elem.setAttribute(
"headerHAlignment", QString::number((
int )
mHeaderHAlignment ) );
273 elem.setAttribute(
"contentFont",
mContentFont.toString() );
275 elem.setAttribute(
"gridStrokeWidth", QString::number(
mGridStrokeWidth ) );
277 elem.setAttribute(
"showGrid",
mShowGrid );
280 QDomElement displayColumnsElem = doc.createElement(
"displayColumns" );
281 QList<QgsComposerTableColumn*>::const_iterator columnIt =
mColumns.constBegin();
282 for ( ; columnIt !=
mColumns.constEnd(); ++columnIt )
284 QDomElement columnElem = doc.createElement(
"column" );
285 ( *columnIt )->writeXML( columnElem, doc );
286 displayColumnsElem.appendChild( columnElem );
288 elem.appendChild( displayColumnsElem );
295 if ( itemElem.isNull() )
300 mHeaderFont.fromString( itemElem.attribute(
"headerFont",
"" ) );
303 mContentFont.fromString( itemElem.attribute(
"contentFont",
"" ) );
306 mGridStrokeWidth = itemElem.attribute(
"gridStrokeWidth",
"0.5" ).toDouble();
307 mShowGrid = itemElem.attribute(
"showGrid",
"1" ).toInt();
310 if ( itemElem.hasAttribute(
"gridColor" ) )
317 int gridRed = itemElem.attribute(
"gridColorRed",
"0" ).toInt();
318 int gridGreen = itemElem.attribute(
"gridColorGreen",
"0" ).toInt();
319 int gridBlue = itemElem.attribute(
"gridColorBlue",
"0" ).toInt();
320 int gridAlpha = itemElem.attribute(
"gridColorAlpha",
"255" ).toInt();
321 mGridColor = QColor( gridRed, gridGreen, gridBlue, gridAlpha );
327 QDomNodeList columnsList = itemElem.elementsByTagName(
"displayColumns" );
328 if ( columnsList.size() > 0 )
330 QDomElement columnsElem = columnsList.at( 0 ).toElement();
331 QDomNodeList columnEntryList = columnsElem.elementsByTagName(
"column" );
332 for (
int i = 0; i < columnEntryList.size(); ++i )
334 QDomElement columnElem = columnEntryList.at( i ).toElement();
342 QDomNodeList composerItemList = itemElem.elementsByTagName(
"ComposerItem" );
343 if ( composerItemList.size() > 0 )
345 QDomElement composerItemElem = composerItemList.at( 0 ).toElement();
354 QList<QgsComposerTableColumn*>::const_iterator columnIt =
mColumns.constBegin();
357 for ( ; columnIt !=
mColumns.constEnd(); ++columnIt )
364 QList<QgsAttributeMap>::const_iterator attIt = attributeMaps.constBegin();
366 double currentAttributeTextWidth;
368 for ( ; attIt != attributeMaps.constEnd(); ++attIt )
370 QgsAttributeMap::const_iterator attIt2 = attIt->constBegin();
371 for ( ; attIt2 != attIt->constEnd(); ++attIt2 )
374 if ( currentAttributeTextWidth > maxWidthMap[ attIt2.key()] )
376 maxWidthMap[ attIt2.key()] = currentAttributeTextWidth;
386 int n = attributeMaps.size();
393 double totalWidth = 0;
394 QMap<int, double>::const_iterator maxColWidthIt = maxWidthMap.constBegin();
395 for ( ; maxColWidthIt != maxWidthMap.constEnd(); ++maxColWidthIt )
397 totalWidth += maxColWidthIt.value();
400 totalWidth += ( maxWidthMap.size() + 1 ) * mGridStrokeWidth;
402 QRectF evaluatedRect =
evalItemRect( QRectF( pos().x(), pos().y(), totalWidth, totalHeight ) );
412 double currentY = halfGridStrokeWidth;
413 p->drawLine( QPointF( halfGridStrokeWidth, currentY ), QPointF( rect().width() - halfGridStrokeWidth, currentY ) );
416 for (
int i = 0; i < nAttributes; ++i )
418 p->drawLine( QPointF( halfGridStrokeWidth, currentY ), QPointF( rect().width() - halfGridStrokeWidth, currentY ) );
422 p->drawLine( QPointF( halfGridStrokeWidth, currentY ), QPointF( rect().width() - halfGridStrokeWidth, currentY ) );
429 double currentX = halfGridStrokeWidth;
430 p->drawLine( QPointF( currentX, halfGridStrokeWidth ), QPointF( currentX, rect().height() - halfGridStrokeWidth ) );
432 QMap<int, double>::const_iterator maxColWidthIt = maxWidthMap.constBegin();
433 for ( ; maxColWidthIt != maxWidthMap.constEnd(); ++maxColWidthIt )
436 p->drawLine( QPointF( currentX, halfGridStrokeWidth ), QPointF( currentX, rect().height() - halfGridStrokeWidth ) );