@@ -43,17 +43,17 @@ void QgsComposerTable::paint( QPainter* painter, const QStyleOptionGraphicsItem*
43
43
}
44
44
45
45
// getFeatureAttributes
46
- QList<QgsAttributes> attributeList ;
47
- if ( !getFeatureAttributes ( attributeList ) )
46
+ QList<QgsAttributeMap> attributeMaps ;
47
+ if ( !getFeatureAttributes ( attributeMaps ) )
48
48
{
49
49
return ;
50
50
}
51
51
52
52
QMap<int , double > maxColumnWidthMap;
53
53
// check how much space each column needs
54
- calculateMaxColumnWidths ( maxColumnWidthMap, attributeList );
54
+ calculateMaxColumnWidths ( maxColumnWidthMap, attributeMaps );
55
55
// adapt item frame to max width / height
56
- adaptItemFrame ( maxColumnWidthMap, attributeList );
56
+ adaptItemFrame ( maxColumnWidthMap, attributeMaps );
57
57
58
58
drawBackground ( painter );
59
59
painter->setPen ( Qt::SolidLine );
@@ -77,14 +77,14 @@ void QgsComposerTable::paint( QPainter* painter, const QStyleOptionGraphicsItem*
77
77
currentY += mGridStrokeWidth ;
78
78
79
79
// draw the attribute values
80
- QList<QgsAttributes >::const_iterator attIt = attributeList .begin ();
81
- for ( ; attIt != attributeList .end (); ++attIt )
80
+ QList<QgsAttributeMap >::const_iterator attIt = attributeMaps .begin ();
81
+ for ( ; attIt != attributeMaps .end (); ++attIt )
82
82
{
83
83
currentY += fontAscentMillimeters ( mContentFont );
84
84
currentY += mLineTextDistance ;
85
85
86
- QgsAttributes currentAttributeMap = *attIt;
87
- QString str = currentAttributeMap. at ( columnIt.key () ) .toString ();
86
+ const QgsAttributeMap & currentAttributeMap = *attIt;
87
+ QString str = currentAttributeMap[ columnIt.key ()] .toString ();
88
88
drawText ( painter, currentX, currentY, str, mContentFont );
89
89
currentY += mLineTextDistance ;
90
90
currentY += mGridStrokeWidth ;
@@ -102,7 +102,7 @@ void QgsComposerTable::paint( QPainter* painter, const QStyleOptionGraphicsItem*
102
102
gridPen.setWidthF ( mGridStrokeWidth );
103
103
gridPen.setColor ( mGridColor );
104
104
painter->setPen ( gridPen );
105
- drawHorizontalGridLines ( painter, attributeList .size () );
105
+ drawHorizontalGridLines ( painter, attributeMaps .size () );
106
106
drawVerticalGridLines ( painter, maxColumnWidthMap );
107
107
}
108
108
@@ -116,17 +116,14 @@ void QgsComposerTable::paint( QPainter* painter, const QStyleOptionGraphicsItem*
116
116
117
117
void QgsComposerTable::adjustFrameToSize ()
118
118
{
119
- QList<QgsAttributes > attributes;
119
+ QList<QgsAttributeMap > attributes;
120
120
if ( !getFeatureAttributes ( attributes ) )
121
- {
122
121
return ;
123
- }
124
122
125
123
QMap<int , double > maxWidthMap;
126
124
if ( !calculateMaxColumnWidths ( maxWidthMap, attributes ) )
127
- {
128
125
return ;
129
- }
126
+
130
127
adaptItemFrame ( maxWidthMap, attributes );
131
128
}
132
129
@@ -172,7 +169,7 @@ bool QgsComposerTable::tableReadXML( const QDomElement& itemElem, const QDomDocu
172
169
return true ;
173
170
}
174
171
175
- bool QgsComposerTable::calculateMaxColumnWidths ( QMap<int , double >& maxWidthMap, const QList<QgsAttributes >& attributeList ) const
172
+ bool QgsComposerTable::calculateMaxColumnWidths ( QMap<int , double >& maxWidthMap, const QList<QgsAttributeMap >& attributeMaps ) const
176
173
{
177
174
maxWidthMap.clear ();
178
175
QMap<int , QString> headerMap = getHeaderLabels ();
@@ -183,34 +180,33 @@ bool QgsComposerTable::calculateMaxColumnWidths( QMap<int, double>& maxWidthMap,
183
180
}
184
181
185
182
// go through all the attributes and adapt the max width values
186
- QList<QgsAttributes >::const_iterator attIt = attributeList .constBegin ();
183
+ QList<QgsAttributeMap >::const_iterator attIt = attributeMaps .constBegin ();
187
184
188
- QgsAttributeMap currentAttributeMap;
189
185
double currentAttributeTextWidth;
190
186
191
- for ( ; attIt != attributeList .constEnd (); ++attIt )
187
+ for ( ; attIt != attributeMaps .constEnd (); ++attIt )
192
188
{
193
- for ( int i = 0 ; i < attIt->size (); ++i )
189
+ QgsAttributeMap::const_iterator attIt2 = attIt->constBegin ();
190
+ for ( ; attIt2 != attIt->constEnd (); ++attIt2 )
194
191
{
195
- currentAttributeTextWidth = textWidthMillimeters ( mContentFont , attIt-> at ( i ).toString () );
196
- if ( currentAttributeTextWidth > maxWidthMap[i ] )
192
+ currentAttributeTextWidth = textWidthMillimeters ( mContentFont , attIt2. value ( ).toString () );
193
+ if ( currentAttributeTextWidth > maxWidthMap[ attIt2. key () ] )
197
194
{
198
- maxWidthMap[i ] = currentAttributeTextWidth;
195
+ maxWidthMap[ attIt2. key () ] = currentAttributeTextWidth;
199
196
}
200
197
}
201
198
}
202
199
return true ;
203
200
}
204
201
205
-
206
-
207
-
208
-
209
- void QgsComposerTable::adaptItemFrame ( const QMap<int , double >& maxWidthMap, const QList<QgsAttributes>& attributeList )
202
+ void QgsComposerTable::adaptItemFrame ( const QMap<int , double >& maxWidthMap, const QList<QgsAttributeMap>& attributeMaps )
210
203
{
211
204
// calculate height
212
- double totalHeight = fontAscentMillimeters ( mHeaderFont ) + attributeList.size () * fontAscentMillimeters ( mContentFont )
213
- + ( attributeList.size () + 1 ) * mLineTextDistance * 2 + ( attributeList.size () + 2 ) * mGridStrokeWidth ;
205
+ int n = attributeMaps.size ();
206
+ double totalHeight = fontAscentMillimeters ( mHeaderFont )
207
+ + n * fontAscentMillimeters ( mContentFont )
208
+ + ( n + 1 ) * mLineTextDistance * 2
209
+ + ( n + 2 ) * mGridStrokeWidth ;
214
210
215
211
// adapt frame to total width
216
212
double totalWidth = 0 ;
0 commit comments