Skip to content

Commit

Permalink
Adapt and fix attribute table for new vector api
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Apr 12, 2013
1 parent fea86ea commit cddbeb1
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 31 deletions.
7 changes: 5 additions & 2 deletions src/core/composer/qgscomposerattributetable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
37 changes: 17 additions & 20 deletions src/core/composer/qgscomposertable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();
Expand All @@ -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;
}
}
}
Expand All @@ -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 )
Expand Down
7 changes: 3 additions & 4 deletions src/core/composer/qgscomposertable.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
8 changes: 4 additions & 4 deletions src/core/composer/qgscomposertexttable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/composer/qgscomposertexttable.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit cddbeb1

Please sign in to comment.