Skip to content
Permalink
Browse files

Adapt and fix attribute table for new vector api

  • Loading branch information
mhugent committed Apr 12, 2013
1 parent fea86ea commit cddbeb1dcdd68c3baeaa717eeafb0a17c10125df
@@ -146,9 +146,12 @@ bool QgsComposerAttributeTable::getFeatureAttributes( QList<QgsAttributes>& attr
}

QgsFeatureRequest req;
req.setFilterRect( selectionRect );
if ( !selectionRect.isEmpty() )
{
req.setFilterRect( selectionRect );
}
req.setFlags( mShowOnlyVisibleFeatures ? QgsFeatureRequest::ExactIntersect : QgsFeatureRequest::NoGeometry );
if ( mDisplayAttributes.size() >= 0 )
if ( mDisplayAttributes.size() > 0 )
req.setSubsetOfAttributes( mDisplayAttributes.toList() );

QgsFeature f;
@@ -43,8 +43,8 @@ void QgsComposerTable::paint( QPainter* painter, const QStyleOptionGraphicsItem*
}

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

drawBackground( painter );
painter->setPen( Qt::SolidLine );

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

//draw the attribute values
QList<QgsAttributeMap>::const_iterator attIt = attributeList.begin();
QList<QgsAttributes>::const_iterator attIt = attributeList.begin();
for ( ; attIt != attributeList.end(); ++attIt )
{
currentY += fontAscentMillimeters( mContentFont );
currentY += mLineTextDistance;

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

void QgsComposerTable::adjustFrameToSize()
{
QList<QgsAttributeMap> attributes;
if ( !getFeatureAttributeMap( attributes ) )
QList<QgsAttributes> attributes;
if ( !getFeatureAttributes( attributes ) )
{
return;
}
@@ -174,7 +173,7 @@ bool QgsComposerTable::tableReadXML( const QDomElement& itemElem, const QDomDocu
return true;
}

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

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

QgsAttributeMap currentAttributeMap;
double currentAttributeTextWidth;

for ( ; attIt != attributeList.constEnd(); ++attIt )
{
currentAttributeMap = *attIt;
QgsAttributeMap::const_iterator attMapIt = currentAttributeMap.constBegin();
for ( ; attMapIt != currentAttributeMap.constEnd(); ++attMapIt )
for ( int i = 0; i < attIt->size(); ++i )
{
currentAttributeTextWidth = textWidthMillimeters( mContentFont, attMapIt.value().toString() );
if ( currentAttributeTextWidth > maxWidthMap[attMapIt.key()] )
currentAttributeTextWidth = textWidthMillimeters( mContentFont, attIt->at( i ).toString() );
if ( currentAttributeTextWidth > maxWidthMap[i] )
{
maxWidthMap[attMapIt.key()] = currentAttributeTextWidth;
maxWidthMap[i] = currentAttributeTextWidth;
}
}
}
@@ -210,7 +207,7 @@ bool QgsComposerTable::calculateMaxColumnWidths( QMap<int, double>& maxWidthMap,



void QgsComposerTable::adaptItemFrame( const QMap<int, double>& maxWidthMap, const QList<QgsAttributeMap>& attributeList )
void QgsComposerTable::adaptItemFrame( const QMap<int, double>& maxWidthMap, const QList<QgsAttributes>& attributeList )
{
//calculate height
double totalHeight = fontAscentMillimeters( mHeaderFont ) + attributeList.size() * fontAscentMillimeters( mContentFont )
@@ -76,14 +76,13 @@ class CORE_EXPORT QgsComposerTable: public QgsComposerItem

/**Retrieves feature attributes*/
//! @note not available in python bindings
virtual bool getFeatureAttributeMap( QList<QgsAttributeMap>& attributes )
{ Q_UNUSED( attributes ); return false; } //= 0;
virtual bool getFeatureAttributes( QList<QgsAttributes>& attributes ) { Q_UNUSED( attributes ); return false; }
virtual QMap<int, QString> getHeaderLabels() const { return QMap<int, QString>(); } //= 0;
/**Calculate the maximum width values of the vector attributes*/
virtual bool calculateMaxColumnWidths( QMap<int, double>& maxWidthMap, const QList<QgsAttributeMap>& attributeList ) const;
virtual bool calculateMaxColumnWidths( QMap<int, double>& maxWidthMap, const QList<QgsAttributes>& attributeList ) const;
/**Adapts the size of the item frame to match the content*/
//! @note not available in python bindings
void adaptItemFrame( const QMap<int, double>& maxWidthMap, const QList<QgsAttributeMap>& attributeList );
void adaptItemFrame( const QMap<int, double>& maxWidthMap, const QList<QgsAttributes>& attributeList );
void drawHorizontalGridLines( QPainter* p, int nAttributes );
//! @note not available in python bindings
void drawVerticalGridLines( QPainter* p, const QMap<int, double>& maxWidthMap );
@@ -42,7 +42,7 @@ bool QgsComposerTextTable::readXML( const QDomElement& itemElem, const QDomDocum
return tableReadXML( itemElem, doc );
}

bool QgsComposerTextTable::getFeatureAttributes( QList<QgsAttributeMap>& attributes )
bool QgsComposerTextTable::getFeatureAttributes( QList<QgsAttributes>& attributes )
{
attributes.clear();

@@ -51,12 +51,12 @@ bool QgsComposerTextTable::getFeatureAttributes( QList<QgsAttributeMap>& attribu
for ( ; rowIt != mRowText.constEnd(); ++rowIt )
{
currentStringList = *rowIt;
QgsAttributeMap map;
QVector<QVariant> vec;
for ( int i = 0; i < currentStringList.size(); ++i )
{
map.insert( i, QVariant( currentStringList.at( i ) ) );
vec.append( QVariant( currentStringList.at( i ) ) );
}
attributes.append( map );
attributes.append( vec );
}
return true;
}
@@ -38,7 +38,7 @@ class CORE_EXPORT QgsComposerTextTable: public QgsComposerTable

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

private:

0 comments on commit cddbeb1

Please sign in to comment.
You can’t perform that action at this time.