Skip to content
Permalink
Browse files

[composer] Don't shrink scalebar height when updating

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 4abaf60a1118b4e77718c88ac237ebaee5e72290
Showing with 35 additions and 2 deletions.
  1. +32 −1 src/core/composer/qgscomposerscalebar.cpp
  2. +3 −1 src/core/composer/qgscomposerscalebar.h
@@ -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 );
@@ -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()
@@ -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*/
@@ -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

0 comments on commit 4abaf60

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