Skip to content
Permalink
Browse files
[composer] Composer items which set their own size must consider data…
… defined width and height
  • Loading branch information
nyalldawson committed Jul 5, 2014
1 parent da97684 commit a914d433b98a73a5e2f9f66a321fabed9261b653
@@ -660,6 +660,9 @@ class QgsComposerItem : QObject, QGraphicsRectItem
*/
bool dataDefinedEvaluate( QgsComposerItem::DataDefinedProperty property, QVariant &expressionValue );

/**Update an item rect to consider data defined position and size of item*/
QRectF evalItemRect( const QRectF &newRect );

signals:
/**Is emitted on item rotation change*/
void itemRotationChanged( double newRotation );
@@ -113,19 +113,22 @@ void QgsComposerArrow::paint( QPainter* painter, const QStyleOptionGraphicsItem

void QgsComposerArrow::setSceneRect( const QRectF& rectangle )
{
if ( rectangle.width() < 0 )
//update rect for data defined size and position
QRectF evaluatedRect = evalItemRect( rectangle );

if ( evaluatedRect.width() < 0 )
{
mStartXIdx = 1 - mStartXIdx;
}
if ( rectangle.height() < 0 )
if ( evaluatedRect.height() < 0 )
{
mStartYIdx = 1 - mStartYIdx;
}

double margin = computeMarkerMargin();

// Ensure the rectangle is at least as large as needed to include the markers
QRectF rect = rectangle.united( QRectF( rectangle.x(), rectangle.y(), 2. * margin, 2. * margin ) );
QRectF rect = rectangle.united( QRectF( evaluatedRect.x(), evaluatedRect.y(), 2. * margin, 2. * margin ) );

// Compute new start and stop positions
double x[2] = {rect.x(), rect.x() + rect.width()};
@@ -481,17 +481,20 @@ void QgsComposerAttributeTable::removeLayer( QString layerId )

void QgsComposerAttributeTable::setSceneRect( const QRectF& rectangle )
{
//update rect for data defined size and position
QRectF evaluatedRect = evalItemRect( rectangle );

double titleHeight = 2 * mGridStrokeWidth + 2 * mLineTextDistance + fontAscentMillimeters( mHeaderFont );
double attributeHeight = mGridStrokeWidth + 2 * mLineTextDistance + fontAscentMillimeters( mContentFont );
if (( rectangle.height() - titleHeight ) > 0 )
if (( evaluatedRect.height() - titleHeight ) > 0 )
{
mMaximumNumberOfFeatures = ( rectangle.height() - titleHeight ) / attributeHeight;
mMaximumNumberOfFeatures = ( evaluatedRect.height() - titleHeight ) / attributeHeight;
}
else
{
mMaximumNumberOfFeatures = 0;
}
QgsComposerItem::setSceneRect( rectangle );
QgsComposerItem::setSceneRect( evaluatedRect );

//refresh table attributes, since number of features has likely changed
refreshAttributes();
@@ -668,6 +668,9 @@ class CORE_EXPORT QgsComposerItem: public QObject, public QGraphicsRectItem
*/
bool dataDefinedEvaluate( QgsComposerItem::DataDefinedProperty property, QVariant &expressionValue );

/**Update an item rect to consider data defined position and size of item*/
QRectF evalItemRect( const QRectF &newRect );

signals:
/**Is emitted on item rotation change*/
void itemRotationChanged( double newRotation );
@@ -697,9 +700,6 @@ class CORE_EXPORT QgsComposerItem: public QObject, public QGraphicsRectItem
/**Map of current data defined properties*/
QMap< QgsComposerItem::DataDefinedProperty, QgsDataDefined* > mDataDefinedProperties;

/**Update an item rect to consider data defined position and size of item*/
QRectF evalItemRect( const QRectF &newRect );

/**Refresh item's rotation, considering data defined rotation setting
*@param updateItem set to false to prevent the item being automatically updated
*@param rotateAroundCenter set to true to rotate the item around its center rather
@@ -272,7 +272,9 @@ void QgsComposerLabel::adjustSizeToText()
double yShift = 0;
itemShiftAdjustSize( width, height, xShift, yShift );

setSceneRect( QRectF( pos().x() + xShift, pos().y() + yShift, width, height ) );
//update rect for data defined size and position
QRectF evaluatedRect = evalItemRect( QRectF( pos().x() + xShift, pos().y() + yShift, width, height ) );
setSceneRect( evaluatedRect );
}

QFont QgsComposerLabel::font() const
@@ -382,7 +382,9 @@ void QgsComposerScaleBar::adjustBoxSize()
}

QRectF box = mStyle->calculateBoxSize();
setSceneRect( box );

//update rect for data defined size and position
setSceneRect( evalItemRect( box ) );
}

void QgsComposerScaleBar::update()
@@ -415,7 +415,11 @@ void QgsComposerShape::updateBoundingRect()
void QgsComposerShape::setSceneRect( const QRectF& rectangle )
{
// Reimplemented from QgsComposerItem as we need to call updateBoundingRect after the shape's size changes
QgsComposerItem::setSceneRect( rectangle );

//update rect for data defined size and position
QRectF evaluatedRect = evalItemRect( rectangle );
QgsComposerItem::setSceneRect( evaluatedRect );

updateBoundingRect();
update();
}
@@ -368,7 +368,10 @@ void QgsComposerTable::adaptItemFrame( const QMap<int, double>& maxWidthMap, con
totalWidth += ( 2 * maxWidthMap.size() * mLineTextDistance );
totalWidth += ( maxWidthMap.size() + 1 ) * mGridStrokeWidth;

QgsComposerItem::setSceneRect( QRectF( pos().x(), pos().y(), totalWidth, totalHeight ) );
QRectF evaluatedRect = evalItemRect( QRectF( pos().x(), pos().y(), totalWidth, totalHeight ) );

//update rect for data defined size and position
QgsComposerItem::setSceneRect( evaluatedRect );
}

void QgsComposerTable::drawHorizontalGridLines( QPainter* p, int nAttributes )

0 comments on commit a914d43

Please sign in to comment.