Skip to content

Commit

Permalink
[composer] Don't shrink scalebar height when updating
Browse files Browse the repository at this point in the history
Previously any update of a scalebar would reset it's height to
the minimum height allowed. Now, if the user has set a height
greater than this minimum than that height is kept. (fix #10466)
  • Loading branch information
nyalldawson committed Oct 27, 2014
1 parent d2c9ffd commit 4abaf60
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
33 changes: 32 additions & 1 deletion src/core/composer/qgscomposerscalebar.cpp
Expand Up @@ -387,6 +387,11 @@ void QgsComposerScaleBar::adjustBoxSize()
}

QRectF box = mStyle->calculateBoxSize();
if ( rect().height() > box.height() )
{
//keep user specified item height if higher than minimum scale bar height
box.setHeight( rect().height() );
}

//update rect for data defined size and position
QRectF newRect = evalItemRect( box, true );
Expand All @@ -401,7 +406,33 @@ void QgsComposerScaleBar::adjustBoxSize()
newRect.setHeight( box.height() );
}

setSceneRect( newRect );
QgsComposerItem::setSceneRect( newRect );
}

void QgsComposerScaleBar::setSceneRect( const QRectF& rectangle )
{
QRectF box = mStyle->calculateBoxSize();
if ( rectangle.height() > box.height() )
{
//keep user specified item height if higher than minimum scale bar height
box.setHeight( rectangle.height() );
}
box.moveTopLeft( rectangle.topLeft() );

//update rect for data defined size and position
QRectF newRect = evalItemRect( rectangle );

//scale bars have a minimum size, respect that regardless of data defined settings
if ( newRect.width() < box.width() )
{
newRect.setWidth( box.width() );
}
if ( newRect.height() < box.height() )
{
newRect.setHeight( box.height() );
}

QgsComposerItem::setSceneRect( newRect );
}

void QgsComposerScaleBar::update()
Expand Down
4 changes: 3 additions & 1 deletion src/core/composer/qgscomposerscalebar.h
Expand Up @@ -236,6 +236,9 @@ class CORE_EXPORT QgsComposerScaleBar: public QgsComposerItem
/**Moves scalebar position to the left / right depending on alignment and change in item width*/
void correctXPositionAlignment( double width, double widthAfter );

//overriden to apply minimum size
void setSceneRect( const QRectF &rectangle );

public slots:
void updateSegmentSize();
/**Sets mCompositionMap to 0 if the map is deleted*/
Expand Down Expand Up @@ -291,7 +294,6 @@ class CORE_EXPORT QgsComposerScaleBar: public QgsComposerItem

/**Returns diagonal of composer map in selected units (map units / meters / feet / nautical miles)*/
double mapWidth() const;

};

#endif //QGSCOMPOSERSCALEBAR_H
Expand Down

0 comments on commit 4abaf60

Please sign in to comment.