24 , mLineTextDistance( 1.0 )
26 , mGridStrokeWidth( 0.5 )
27 , mGridColor( QColor( 0, 0, 0 ) )
38 Q_UNUSED( itemStyle );
46 QList<QgsAttributeMap> attributeMaps;
52 QMap<int, double> maxColumnWidthMap;
59 painter->setPen( Qt::SolidLine );
66 QMap<int, QString>::const_iterator columnIt = headerMap.constBegin();
68 for ( ; columnIt != headerMap.constEnd(); ++columnIt )
80 QList<QgsAttributeMap>::const_iterator attIt = attributeMaps.begin();
81 for ( ; attIt != attributeMaps.end(); ++attIt )
87 QString str = currentAttributeMap[ columnIt.key()].toString();
93 currentX += maxColumnWidthMap[columnIt.key()];
104 painter->setPen( gridPen );
119 QList<QgsAttributeMap> attributes;
123 QMap<int, double> maxWidthMap;
133 elem.setAttribute(
"headerFont",
mHeaderFont.toString() );
134 elem.setAttribute(
"contentFont",
mContentFont.toString() );
135 elem.setAttribute(
"gridStrokeWidth", QString::number(
mGridStrokeWidth ) );
136 elem.setAttribute(
"gridColorRed",
mGridColor.red() );
137 elem.setAttribute(
"gridColorGreen",
mGridColor.green() );
138 elem.setAttribute(
"gridColorBlue",
mGridColor.blue() );
139 elem.setAttribute(
"showGrid",
mShowGrid );
145 if ( itemElem.isNull() )
150 mHeaderFont.fromString( itemElem.attribute(
"headerFont",
"" ) );
151 mContentFont.fromString( itemElem.attribute(
"contentFont",
"" ) );
153 mGridStrokeWidth = itemElem.attribute(
"gridStrokeWidth",
"0.5" ).toDouble();
154 mShowGrid = itemElem.attribute(
"showGrid",
"1" ).toInt();
157 int gridRed = itemElem.attribute(
"gridColorRed",
"0" ).toInt();
158 int gridGreen = itemElem.attribute(
"gridColorGreen",
"0" ).toInt();
159 int gridBlue = itemElem.attribute(
"gridColorBlue",
"0" ).toInt();
160 mGridColor = QColor( gridRed, gridGreen, gridBlue );
163 QDomNodeList composerItemList = itemElem.elementsByTagName(
"ComposerItem" );
164 if ( composerItemList.size() > 0 )
166 QDomElement composerItemElem = composerItemList.at( 0 ).toElement();
176 QMap<int, QString>::const_iterator headerIt = headerMap.constBegin();
177 for ( ; headerIt != headerMap.constEnd(); ++headerIt )
183 QList<QgsAttributeMap>::const_iterator attIt = attributeMaps.constBegin();
185 double currentAttributeTextWidth;
187 for ( ; attIt != attributeMaps.constEnd(); ++attIt )
189 QgsAttributeMap::const_iterator attIt2 = attIt->constBegin();
190 for ( ; attIt2 != attIt->constEnd(); ++attIt2 )
193 if ( currentAttributeTextWidth > maxWidthMap[ attIt2.key()] )
195 maxWidthMap[ attIt2.key()] = currentAttributeTextWidth;
205 int n = attributeMaps.size();
212 double totalWidth = 0;
213 QMap<int, double>::const_iterator maxColWidthIt = maxWidthMap.constBegin();
214 for ( ; maxColWidthIt != maxWidthMap.constEnd(); ++maxColWidthIt )
216 totalWidth += maxColWidthIt.value();
219 totalWidth += ( maxWidthMap.size() + 1 ) * mGridStrokeWidth;
220 QTransform t = transform();
228 double currentY = halfGridStrokeWidth;
229 p->drawLine( QPointF( halfGridStrokeWidth, currentY ), QPointF( rect().width() - halfGridStrokeWidth, currentY ) );
232 for (
int i = 0; i < nAttributes; ++i )
234 p->drawLine( QPointF( halfGridStrokeWidth, currentY ), QPointF( rect().width() - halfGridStrokeWidth, currentY ) );
238 p->drawLine( QPointF( halfGridStrokeWidth, currentY ), QPointF( rect().width() - halfGridStrokeWidth, currentY ) );
245 double currentX = halfGridStrokeWidth;
246 p->drawLine( QPointF( currentX, halfGridStrokeWidth ), QPointF( currentX, rect().height() - halfGridStrokeWidth ) );
248 QMap<int, double>::const_iterator maxColWidthIt = maxWidthMap.constBegin();
249 for ( ; maxColWidthIt != maxWidthMap.constEnd(); ++maxColWidthIt )
252 p->drawLine( QPointF( currentX, halfGridStrokeWidth ), QPointF( currentX, rect().height() - halfGridStrokeWidth ) );
QMap< int, QVariant > QgsAttributeMap
A item that forms part of a map composition.
virtual void drawFrame(QPainter *p)
Draw black frame around item.
virtual QMap< int, QString > getHeaderLabels() const
bool _readXML(const QDomElement &itemElem, const QDomDocument &doc)
Reads parameter that are not subclass specific in document.
void drawHorizontalGridLines(QPainter *p, int nAttributes)
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
void drawText(QPainter *p, double x, double y, const QString &text, const QFont &font) const
Draws Text.
virtual ~QgsComposerTable()
Graphics scene for map printing.
virtual bool getFeatureAttributes(QList< QgsAttributeMap > &attributeMaps)
Retrieves feature attributes.
QgsComposerTable(QgsComposition *composition)
bool _writeXML(QDomElement &itemElem, QDomDocument &doc) const
Writes parameter that are not subclass specific in document.
bool tableReadXML(const QDomElement &itemElem, const QDomDocument &doc)
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.
void adaptItemFrame(const QMap< int, double > &maxWidthMap, const QList< QgsAttributeMap > &attributeMaps)
Adapts the size of the item frame to match the content.
virtual bool calculateMaxColumnWidths(QMap< int, double > &maxWidthMap, const QList< QgsAttributeMap > &attributeMaps) const
Calculate the maximum width values of the vector attributes.
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)