mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04:00
[composer] Composer items which set their own size must consider data defined width and height
This commit is contained in:
parent
da97684878
commit
a914d433b9
@ -660,6 +660,9 @@ class QgsComposerItem : QObject, QGraphicsRectItem
|
|||||||
*/
|
*/
|
||||||
bool dataDefinedEvaluate( QgsComposerItem::DataDefinedProperty property, QVariant &expressionValue );
|
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:
|
signals:
|
||||||
/**Is emitted on item rotation change*/
|
/**Is emitted on item rotation change*/
|
||||||
void itemRotationChanged( double newRotation );
|
void itemRotationChanged( double newRotation );
|
||||||
|
@ -113,11 +113,14 @@ void QgsComposerArrow::paint( QPainter* painter, const QStyleOptionGraphicsItem
|
|||||||
|
|
||||||
void QgsComposerArrow::setSceneRect( const QRectF& rectangle )
|
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;
|
mStartXIdx = 1 - mStartXIdx;
|
||||||
}
|
}
|
||||||
if ( rectangle.height() < 0 )
|
if ( evaluatedRect.height() < 0 )
|
||||||
{
|
{
|
||||||
mStartYIdx = 1 - mStartYIdx;
|
mStartYIdx = 1 - mStartYIdx;
|
||||||
}
|
}
|
||||||
@ -125,7 +128,7 @@ void QgsComposerArrow::setSceneRect( const QRectF& rectangle )
|
|||||||
double margin = computeMarkerMargin();
|
double margin = computeMarkerMargin();
|
||||||
|
|
||||||
// Ensure the rectangle is at least as large as needed to include the markers
|
// 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
|
// Compute new start and stop positions
|
||||||
double x[2] = {rect.x(), rect.x() + rect.width()};
|
double x[2] = {rect.x(), rect.x() + rect.width()};
|
||||||
|
@ -481,17 +481,20 @@ void QgsComposerAttributeTable::removeLayer( QString layerId )
|
|||||||
|
|
||||||
void QgsComposerAttributeTable::setSceneRect( const QRectF& rectangle )
|
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 titleHeight = 2 * mGridStrokeWidth + 2 * mLineTextDistance + fontAscentMillimeters( mHeaderFont );
|
||||||
double attributeHeight = mGridStrokeWidth + 2 * mLineTextDistance + fontAscentMillimeters( mContentFont );
|
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
|
else
|
||||||
{
|
{
|
||||||
mMaximumNumberOfFeatures = 0;
|
mMaximumNumberOfFeatures = 0;
|
||||||
}
|
}
|
||||||
QgsComposerItem::setSceneRect( rectangle );
|
QgsComposerItem::setSceneRect( evaluatedRect );
|
||||||
|
|
||||||
//refresh table attributes, since number of features has likely changed
|
//refresh table attributes, since number of features has likely changed
|
||||||
refreshAttributes();
|
refreshAttributes();
|
||||||
|
@ -668,6 +668,9 @@ class CORE_EXPORT QgsComposerItem: public QObject, public QGraphicsRectItem
|
|||||||
*/
|
*/
|
||||||
bool dataDefinedEvaluate( QgsComposerItem::DataDefinedProperty property, QVariant &expressionValue );
|
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:
|
signals:
|
||||||
/**Is emitted on item rotation change*/
|
/**Is emitted on item rotation change*/
|
||||||
void itemRotationChanged( double newRotation );
|
void itemRotationChanged( double newRotation );
|
||||||
@ -697,9 +700,6 @@ class CORE_EXPORT QgsComposerItem: public QObject, public QGraphicsRectItem
|
|||||||
/**Map of current data defined properties*/
|
/**Map of current data defined properties*/
|
||||||
QMap< QgsComposerItem::DataDefinedProperty, QgsDataDefined* > mDataDefinedProperties;
|
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
|
/**Refresh item's rotation, considering data defined rotation setting
|
||||||
*@param updateItem set to false to prevent the item being automatically updated
|
*@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
|
*@param rotateAroundCenter set to true to rotate the item around its center rather
|
||||||
|
@ -272,7 +272,9 @@ void QgsComposerLabel::adjustSizeToText()
|
|||||||
double yShift = 0;
|
double yShift = 0;
|
||||||
itemShiftAdjustSize( width, height, xShift, yShift );
|
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
|
QFont QgsComposerLabel::font() const
|
||||||
|
@ -382,7 +382,9 @@ void QgsComposerScaleBar::adjustBoxSize()
|
|||||||
}
|
}
|
||||||
|
|
||||||
QRectF box = mStyle->calculateBoxSize();
|
QRectF box = mStyle->calculateBoxSize();
|
||||||
setSceneRect( box );
|
|
||||||
|
//update rect for data defined size and position
|
||||||
|
setSceneRect( evalItemRect( box ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsComposerScaleBar::update()
|
void QgsComposerScaleBar::update()
|
||||||
|
@ -415,7 +415,11 @@ void QgsComposerShape::updateBoundingRect()
|
|||||||
void QgsComposerShape::setSceneRect( const QRectF& rectangle )
|
void QgsComposerShape::setSceneRect( const QRectF& rectangle )
|
||||||
{
|
{
|
||||||
// Reimplemented from QgsComposerItem as we need to call updateBoundingRect after the shape's size changes
|
// 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();
|
updateBoundingRect();
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
@ -368,7 +368,10 @@ void QgsComposerTable::adaptItemFrame( const QMap<int, double>& maxWidthMap, con
|
|||||||
totalWidth += ( 2 * maxWidthMap.size() * mLineTextDistance );
|
totalWidth += ( 2 * maxWidthMap.size() * mLineTextDistance );
|
||||||
totalWidth += ( maxWidthMap.size() + 1 ) * mGridStrokeWidth;
|
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 )
|
void QgsComposerTable::drawHorizontalGridLines( QPainter* p, int nAttributes )
|
||||||
|
Loading…
x
Reference in New Issue
Block a user