26 , mLineTextDistance( 1.0 )
27 , mHeaderHAlignment( FollowColumn )
29 , mGridStrokeWidth( 0.5 )
30 , mGridColor( QColor( 0, 0, 0 ) )
34 QString defaultFontString = settings.value(
"/Composer/defaultFont" ).toString();
35 if ( !defaultFontString.isEmpty() )
66 Q_UNUSED( itemStyle );
82 painter->setPen( Qt::SolidLine );
88 QList<QgsComposerTableColumn*>::const_iterator columnIt =
mColumns.constBegin();
94 for ( ; columnIt !=
mColumns.constEnd(); ++columnIt )
102 Qt::AlignmentFlag headerAlign = Qt::AlignLeft;
106 headerAlign = ( *columnIt )->hAlignment();
109 headerAlign = Qt::AlignLeft;
112 headerAlign = Qt::AlignHCenter;
115 headerAlign = Qt::AlignRight;
119 drawText( painter, cell, ( *columnIt )->heading(),
mHeaderFont, headerAlign, Qt::AlignVCenter, Qt::TextDontClip );
121 currentY += cellHeaderHeight;
125 QList<QgsAttributeMap>::const_iterator attIt =
mAttributeMaps.begin();
131 QString str = currentAttributeMap[ col ].toString();
132 drawText( painter, cell, str,
mContentFont, ( *columnIt )->hAlignment(), Qt::AlignVCenter, Qt::TextDontClip );
134 currentY += cellBodyHeight;
150 gridPen.setJoinStyle( Qt::MiterJoin );
151 painter->setPen( gridPen );
220 QMap<int, QString> headers;
222 QList<QgsComposerTableColumn*>::const_iterator columnIt =
mColumns.constBegin();
224 for ( ; columnIt !=
mColumns.constEnd(); ++columnIt )
226 headers.insert( col, ( *columnIt )->heading() );
244 elem.setAttribute(
"headerFont",
mHeaderFont.toString() );
245 elem.setAttribute(
"headerHAlignment", QString::number((
int )
mHeaderHAlignment ) );
246 elem.setAttribute(
"contentFont",
mContentFont.toString() );
247 elem.setAttribute(
"gridStrokeWidth", QString::number(
mGridStrokeWidth ) );
248 elem.setAttribute(
"gridColorRed",
mGridColor.red() );
249 elem.setAttribute(
"gridColorGreen",
mGridColor.green() );
250 elem.setAttribute(
"gridColorBlue",
mGridColor.blue() );
251 elem.setAttribute(
"showGrid",
mShowGrid );
254 QDomElement displayColumnsElem = doc.createElement(
"displayColumns" );
255 QList<QgsComposerTableColumn*>::const_iterator columnIt =
mColumns.constBegin();
256 for ( ; columnIt !=
mColumns.constEnd(); ++columnIt )
258 QDomElement columnElem = doc.createElement(
"column" );
259 ( *columnIt )->writeXML( columnElem, doc );
260 displayColumnsElem.appendChild( columnElem );
262 elem.appendChild( displayColumnsElem );
269 if ( itemElem.isNull() )
274 mHeaderFont.fromString( itemElem.attribute(
"headerFont",
"" ) );
276 mContentFont.fromString( itemElem.attribute(
"contentFont",
"" ) );
278 mGridStrokeWidth = itemElem.attribute(
"gridStrokeWidth",
"0.5" ).toDouble();
279 mShowGrid = itemElem.attribute(
"showGrid",
"1" ).toInt();
282 int gridRed = itemElem.attribute(
"gridColorRed",
"0" ).toInt();
283 int gridGreen = itemElem.attribute(
"gridColorGreen",
"0" ).toInt();
284 int gridBlue = itemElem.attribute(
"gridColorBlue",
"0" ).toInt();
285 mGridColor = QColor( gridRed, gridGreen, gridBlue );
290 QDomNodeList columnsList = itemElem.elementsByTagName(
"displayColumns" );
291 if ( columnsList.size() > 0 )
293 QDomElement columnsElem = columnsList.at( 0 ).toElement();
294 QDomNodeList columnEntryList = columnsElem.elementsByTagName(
"column" );
295 for (
int i = 0; i < columnEntryList.size(); ++i )
297 QDomElement columnElem = columnEntryList.at( i ).toElement();
305 QDomNodeList composerItemList = itemElem.elementsByTagName(
"ComposerItem" );
306 if ( composerItemList.size() > 0 )
308 QDomElement composerItemElem = composerItemList.at( 0 ).toElement();
317 QList<QgsComposerTableColumn*>::const_iterator columnIt =
mColumns.constBegin();
320 for ( ; columnIt !=
mColumns.constEnd(); ++columnIt )
327 QList<QgsAttributeMap>::const_iterator attIt = attributeMaps.constBegin();
329 double currentAttributeTextWidth;
331 for ( ; attIt != attributeMaps.constEnd(); ++attIt )
333 QgsAttributeMap::const_iterator attIt2 = attIt->constBegin();
334 for ( ; attIt2 != attIt->constEnd(); ++attIt2 )
337 if ( currentAttributeTextWidth > maxWidthMap[ attIt2.key()] )
339 maxWidthMap[ attIt2.key()] = currentAttributeTextWidth;
349 int n = attributeMaps.size();
356 double totalWidth = 0;
357 QMap<int, double>::const_iterator maxColWidthIt = maxWidthMap.constBegin();
358 for ( ; maxColWidthIt != maxWidthMap.constEnd(); ++maxColWidthIt )
360 totalWidth += maxColWidthIt.value();
363 totalWidth += ( maxWidthMap.size() + 1 ) * mGridStrokeWidth;
372 double currentY = halfGridStrokeWidth;
373 p->drawLine( QPointF( halfGridStrokeWidth, currentY ), QPointF( rect().width() - halfGridStrokeWidth, currentY ) );
376 for (
int i = 0; i < nAttributes; ++i )
378 p->drawLine( QPointF( halfGridStrokeWidth, currentY ), QPointF( rect().width() - halfGridStrokeWidth, currentY ) );
382 p->drawLine( QPointF( halfGridStrokeWidth, currentY ), QPointF( rect().width() - halfGridStrokeWidth, currentY ) );
389 double currentX = halfGridStrokeWidth;
390 p->drawLine( QPointF( currentX, halfGridStrokeWidth ), QPointF( currentX, rect().height() - halfGridStrokeWidth ) );
392 QMap<int, double>::const_iterator maxColWidthIt = maxWidthMap.constBegin();
393 for ( ; maxColWidthIt != maxWidthMap.constEnd(); ++maxColWidthIt )
396 p->drawLine( QPointF( currentX, halfGridStrokeWidth ), QPointF( currentX, rect().height() - halfGridStrokeWidth ) );
void setLineTextDistance(double d)
Sets the margin distance between cell borders and their contents.
void setContentFont(const QFont &f)
Sets the font used to draw text in table body cells.
QMap< int, QVariant > QgsAttributeMap
void setGridStrokeWidth(double w)
Sets the width for grid lines in the table.
virtual QMap< int, QString > headerLabels() const
Returns the text used in the column headers for the table.
A item that forms part of a map composition.
void setColumns(QList< QgsComposerTableColumn * > columns)
Replaces the columns in the table with a specified list of QgsComposerTableColumns.
void setShowGrid(bool show)
Sets whether grid lines should be drawn in the table.
HeaderHAlignment mHeaderHAlignment
virtual void drawFrame(QPainter *p)
Draw black frame around item.
bool _readXML(const QDomElement &itemElem, const QDomDocument &doc)
Reads parameter that are not subclass specific in document.
void drawHorizontalGridLines(QPainter *p, int nAttributes)
Draws the horizontal grid lines for the table.
virtual void drawSelectionBoxes(QPainter *p)
Draw selection boxes around item.
double textWidthMillimeters(const QFont &font, const QString &text) const
Returns the font width in millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE...
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget)
Reimplementation of QCanvasItem::paint.
bool tableWriteXML(QDomElement &itemElem, QDomDocument &doc) const
Writes common table properties to xml for storage.
void drawText(QPainter *p, double x, double y, const QString &text, const QFont &font) const
Draws Text.
Stores properties of a column in a QgsComposerTable.
virtual ~QgsComposerTable()
QgsComposition * mComposition
Graphics scene for map printing.
virtual bool getFeatureAttributes(QList< QgsAttributeMap > &attributeMaps)
Fetches the text used for the rows of the table.
void setHeaderHAlignment(const HeaderHAlignment alignment)
Sets the horizontal alignment for table headers.
QList< QgsComposerTableColumn * > mColumns
virtual void refreshAttributes()
Refreshes the attributes shown in the table by querying the vector layer for new data.
QgsComposerTable(QgsComposition *composition)
void setHeaderFont(const QFont &f)
Sets the font used to draw header text in the table.
bool _writeXML(QDomElement &itemElem, QDomDocument &doc) const
Writes parameter that are not subclass specific in document.
QList< QgsAttributeMap > mAttributeMaps
bool tableReadXML(const QDomElement &itemElem, const QDomDocument &doc)
Reads the table's common properties from xml.
virtual void adjustFrameToSize()
Adapts the size of the frame to match the content.
virtual void drawBackground(QPainter *p)
Draw background.
virtual void setSceneRect(const QRectF &rectangle)
Sets this items bound in scene coordinates such that 1 item size units corresponds to 1 scene size un...
double mLineTextDistance
Distance between table lines and text.
virtual bool readXML(const QDomElement &columnElem)
Reads the column's properties from xml.
QMap< int, double > mMaxColumnWidthMap
void adaptItemFrame(const QMap< int, double > &maxWidthMap, const QList< QgsAttributeMap > &attributeMaps)
Adapts the size of the item frame to match the table's content.
QgsComposition::PlotStyle plotStyle() const
virtual bool calculateMaxColumnWidths(QMap< int, double > &maxWidthMap, const QList< QgsAttributeMap > &attributeMaps) const
Calculates the maximum width of text shown in columns.
double fontAscentMillimeters(const QFont &font) const
Returns the font ascent in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCAL...
void drawVerticalGridLines(QPainter *p, const QMap< int, double > &maxWidthMap)
Draws the vertical grid lines for the table.