Skip to content

Commit cddbeb1

Browse files
committedApr 12, 2013
Adapt and fix attribute table for new vector api
1 parent fea86ea commit cddbeb1

File tree

5 files changed

+30
-31
lines changed

5 files changed

+30
-31
lines changed
 

‎src/core/composer/qgscomposerattributetable.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,12 @@ bool QgsComposerAttributeTable::getFeatureAttributes( QList<QgsAttributes>& attr
146146
}
147147

148148
QgsFeatureRequest req;
149-
req.setFilterRect( selectionRect );
149+
if ( !selectionRect.isEmpty() )
150+
{
151+
req.setFilterRect( selectionRect );
152+
}
150153
req.setFlags( mShowOnlyVisibleFeatures ? QgsFeatureRequest::ExactIntersect : QgsFeatureRequest::NoGeometry );
151-
if ( mDisplayAttributes.size() >= 0 )
154+
if ( mDisplayAttributes.size() > 0 )
152155
req.setSubsetOfAttributes( mDisplayAttributes.toList() );
153156

154157
QgsFeature f;

‎src/core/composer/qgscomposertable.cpp

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ void QgsComposerTable::paint( QPainter* painter, const QStyleOptionGraphicsItem*
4343
}
4444

4545
//getFeatureAttributes
46-
QList<QgsAttributeMap> attributeList;
47-
if ( !getFeatureAttributeMap( attributeList ) )
46+
QList<QgsAttributes> attributeList;
47+
if ( !getFeatureAttributes( attributeList ) )
4848
{
4949
return;
5050
}
@@ -56,6 +56,7 @@ void QgsComposerTable::paint( QPainter* painter, const QStyleOptionGraphicsItem*
5656
adaptItemFrame( maxColumnWidthMap, attributeList );
5757

5858
drawBackground( painter );
59+
painter->setPen( Qt::SolidLine );
5960

6061
//now draw the text
6162
double currentX = mGridStrokeWidth;
@@ -76,18 +77,16 @@ void QgsComposerTable::paint( QPainter* painter, const QStyleOptionGraphicsItem*
7677
currentY += mGridStrokeWidth;
7778

7879
//draw the attribute values
79-
QList<QgsAttributeMap>::const_iterator attIt = attributeList.begin();
80+
QList<QgsAttributes>::const_iterator attIt = attributeList.begin();
8081
for ( ; attIt != attributeList.end(); ++attIt )
8182
{
8283
currentY += fontAscentMillimeters( mContentFont );
8384
currentY += mLineTextDistance;
8485

85-
QgsAttributeMap currentAttributeMap = *attIt;
86-
QgsAttributeMap::const_iterator attMapIt = currentAttributeMap.find( columnIt.key() );
87-
if ( attMapIt != currentAttributeMap.constEnd() )
88-
{
89-
drawText( painter, currentX, currentY, attMapIt.value().toString(), mContentFont );
90-
}
86+
QgsAttributes currentAttributeMap = *attIt;
87+
int debug = columnIt.key();
88+
QString str = currentAttributeMap.at( columnIt.key() ).toString();
89+
drawText( painter, currentX, currentY, str, mContentFont );
9190
currentY += mLineTextDistance;
9291
currentY += mGridStrokeWidth;
9392
}
@@ -118,8 +117,8 @@ void QgsComposerTable::paint( QPainter* painter, const QStyleOptionGraphicsItem*
118117

119118
void QgsComposerTable::adjustFrameToSize()
120119
{
121-
QList<QgsAttributeMap> attributes;
122-
if ( !getFeatureAttributeMap( attributes ) )
120+
QList<QgsAttributes> attributes;
121+
if ( !getFeatureAttributes( attributes ) )
123122
{
124123
return;
125124
}
@@ -174,7 +173,7 @@ bool QgsComposerTable::tableReadXML( const QDomElement& itemElem, const QDomDocu
174173
return true;
175174
}
176175

177-
bool QgsComposerTable::calculateMaxColumnWidths( QMap<int, double>& maxWidthMap, const QList<QgsAttributeMap>& attributeList ) const
176+
bool QgsComposerTable::calculateMaxColumnWidths( QMap<int, double>& maxWidthMap, const QList<QgsAttributes>& attributeList ) const
178177
{
179178
maxWidthMap.clear();
180179
QMap<int, QString> headerMap = getHeaderLabels();
@@ -185,21 +184,19 @@ bool QgsComposerTable::calculateMaxColumnWidths( QMap<int, double>& maxWidthMap,
185184
}
186185

187186
//go through all the attributes and adapt the max width values
188-
QList<QgsAttributeMap>::const_iterator attIt = attributeList.constBegin();
187+
QList<QgsAttributes>::const_iterator attIt = attributeList.constBegin();
189188

190189
QgsAttributeMap currentAttributeMap;
191190
double currentAttributeTextWidth;
192191

193192
for ( ; attIt != attributeList.constEnd(); ++attIt )
194193
{
195-
currentAttributeMap = *attIt;
196-
QgsAttributeMap::const_iterator attMapIt = currentAttributeMap.constBegin();
197-
for ( ; attMapIt != currentAttributeMap.constEnd(); ++attMapIt )
194+
for ( int i = 0; i < attIt->size(); ++i )
198195
{
199-
currentAttributeTextWidth = textWidthMillimeters( mContentFont, attMapIt.value().toString() );
200-
if ( currentAttributeTextWidth > maxWidthMap[attMapIt.key()] )
196+
currentAttributeTextWidth = textWidthMillimeters( mContentFont, attIt->at( i ).toString() );
197+
if ( currentAttributeTextWidth > maxWidthMap[i] )
201198
{
202-
maxWidthMap[attMapIt.key()] = currentAttributeTextWidth;
199+
maxWidthMap[i] = currentAttributeTextWidth;
203200
}
204201
}
205202
}
@@ -210,7 +207,7 @@ bool QgsComposerTable::calculateMaxColumnWidths( QMap<int, double>& maxWidthMap,
210207

211208

212209

213-
void QgsComposerTable::adaptItemFrame( const QMap<int, double>& maxWidthMap, const QList<QgsAttributeMap>& attributeList )
210+
void QgsComposerTable::adaptItemFrame( const QMap<int, double>& maxWidthMap, const QList<QgsAttributes>& attributeList )
214211
{
215212
//calculate height
216213
double totalHeight = fontAscentMillimeters( mHeaderFont ) + attributeList.size() * fontAscentMillimeters( mContentFont )

‎src/core/composer/qgscomposertable.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,13 @@ class CORE_EXPORT QgsComposerTable: public QgsComposerItem
7676

7777
/**Retrieves feature attributes*/
7878
//! @note not available in python bindings
79-
virtual bool getFeatureAttributeMap( QList<QgsAttributeMap>& attributes )
80-
{ Q_UNUSED( attributes ); return false; } //= 0;
79+
virtual bool getFeatureAttributes( QList<QgsAttributes>& attributes ) { Q_UNUSED( attributes ); return false; }
8180
virtual QMap<int, QString> getHeaderLabels() const { return QMap<int, QString>(); } //= 0;
8281
/**Calculate the maximum width values of the vector attributes*/
83-
virtual bool calculateMaxColumnWidths( QMap<int, double>& maxWidthMap, const QList<QgsAttributeMap>& attributeList ) const;
82+
virtual bool calculateMaxColumnWidths( QMap<int, double>& maxWidthMap, const QList<QgsAttributes>& attributeList ) const;
8483
/**Adapts the size of the item frame to match the content*/
8584
//! @note not available in python bindings
86-
void adaptItemFrame( const QMap<int, double>& maxWidthMap, const QList<QgsAttributeMap>& attributeList );
85+
void adaptItemFrame( const QMap<int, double>& maxWidthMap, const QList<QgsAttributes>& attributeList );
8786
void drawHorizontalGridLines( QPainter* p, int nAttributes );
8887
//! @note not available in python bindings
8988
void drawVerticalGridLines( QPainter* p, const QMap<int, double>& maxWidthMap );

‎src/core/composer/qgscomposertexttable.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ bool QgsComposerTextTable::readXML( const QDomElement& itemElem, const QDomDocum
4242
return tableReadXML( itemElem, doc );
4343
}
4444

45-
bool QgsComposerTextTable::getFeatureAttributes( QList<QgsAttributeMap>& attributes )
45+
bool QgsComposerTextTable::getFeatureAttributes( QList<QgsAttributes>& attributes )
4646
{
4747
attributes.clear();
4848

@@ -51,12 +51,12 @@ bool QgsComposerTextTable::getFeatureAttributes( QList<QgsAttributeMap>& attribu
5151
for ( ; rowIt != mRowText.constEnd(); ++rowIt )
5252
{
5353
currentStringList = *rowIt;
54-
QgsAttributeMap map;
54+
QVector<QVariant> vec;
5555
for ( int i = 0; i < currentStringList.size(); ++i )
5656
{
57-
map.insert( i, QVariant( currentStringList.at( i ) ) );
57+
vec.append( QVariant( currentStringList.at( i ) ) );
5858
}
59-
attributes.append( map );
59+
attributes.append( vec );
6060
}
6161
return true;
6262
}

‎src/core/composer/qgscomposertexttable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class CORE_EXPORT QgsComposerTextTable: public QgsComposerTable
3838

3939
protected:
4040
//! @note not available in python bindings
41-
bool getFeatureAttributes( QList<QgsAttributeMap>& attributes );
41+
bool getFeatureAttributes( QList<QgsAttributes>& attributes );
4242
QMap<int, QString> getHeaderLabels() const;
4343

4444
private:

0 commit comments

Comments
 (0)
Please sign in to comment.