Skip to content

Commit

Permalink
Fix for bug #5354 (scalebar problems in print composer)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Apr 16, 2012
1 parent 3c5b3bb commit 26fda3f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/app/composer/qgscomposerscalebarwidget.cpp
Expand Up @@ -25,6 +25,10 @@
QgsComposerScaleBarWidget::QgsComposerScaleBarWidget( QgsComposerScaleBar* scaleBar ): QWidget(), mComposerScaleBar( scaleBar )
{
setupUi( this );
if ( scaleBar )
{
QObject::connect( scaleBar, SIGNAL( itemChanged() ), this, SLOT( setGuiElements() ) );
}

//add widget for general composer item properties
QgsComposerItemWidget* itemPropertiesWidget = new QgsComposerItemWidget( this, scaleBar );
Expand All @@ -43,9 +47,9 @@ QgsComposerScaleBarWidget::QgsComposerScaleBarWidget( QgsComposerScaleBar* scale
mAlignmentComboBox->insertItem( 0, tr( "Left" ) );
mAlignmentComboBox->insertItem( 1, tr( "Middle" ) );
mAlignmentComboBox->insertItem( 2, tr( "Right" ) );
blockMemberSignals( false );

setGuiElements(); //set the GUI elements to the state of scaleBar
blockMemberSignals( false );
}

QgsComposerScaleBarWidget::~QgsComposerScaleBarWidget()
Expand Down Expand Up @@ -144,6 +148,7 @@ void QgsComposerScaleBarWidget::setGuiElements()
return;
}

blockMemberSignals( true );
mNumberOfSegmentsSpinBox->setValue( mComposerScaleBar->numSegments() );
mSegmentsLeftSpinBox->setValue( mComposerScaleBar->numSegmentsLeft() );
mSegmentSizeSpinBox->setValue( mComposerScaleBar->numUnitsPerSegment() );
Expand Down Expand Up @@ -171,6 +176,7 @@ void QgsComposerScaleBarWidget::setGuiElements()

//alignment
mAlignmentComboBox->setCurrentIndex(( int )( mComposerScaleBar->alignment() ) );
blockMemberSignals( false );
}

//slots
Expand Down
3 changes: 2 additions & 1 deletion src/app/composer/qgscomposerscalebarwidget.h
Expand Up @@ -48,6 +48,8 @@ class QgsComposerScaleBarWidget: public QWidget, private Ui::QgsComposerScaleBar
void on_mBoxSizeSpinBox_valueChanged( double d );
void on_mAlignmentComboBox_currentIndexChanged( int index );

private slots:
void setGuiElements();

protected:
void showEvent( QShowEvent * event );
Expand All @@ -56,7 +58,6 @@ class QgsComposerScaleBarWidget: public QWidget, private Ui::QgsComposerScaleBar
QgsComposerScaleBar* mComposerScaleBar;

void refreshMapComboBox();
void setGuiElements();
/**Enables/disables the signals of the input gui elements*/
void blockMemberSignals( bool enable );
};
Expand Down
12 changes: 11 additions & 1 deletion src/core/composer/qgscomposerscalebar.cpp
Expand Up @@ -29,7 +29,7 @@
#include <cmath>

QgsComposerScaleBar::QgsComposerScaleBar( QgsComposition* composition ): QgsComposerItem( composition ), mComposerMap( 0 ), mStyle( 0 ),
mSegmentMillimeters( 0.0 ), mAlignment( Left )
mNumUnitsPerSegment( 0 ), mSegmentMillimeters( 0.0 ), mAlignment( Left )
{
applyDefaultSettings();
applyDefaultSize();
Expand Down Expand Up @@ -77,6 +77,7 @@ void QgsComposerScaleBar::setNumSegments( int nSegments )
mNumSegments = nSegments;
double widthAfter = mStyle->calculateBoxSize().width();
correctXPositionAlignment( width, widthAfter );
emit itemChanged();
}

void QgsComposerScaleBar::setNumUnitsPerSegment( double units )
Expand All @@ -91,6 +92,7 @@ void QgsComposerScaleBar::setNumUnitsPerSegment( double units )
refreshSegmentMillimeters();
double widthAfter = mStyle->calculateBoxSize().width();
correctXPositionAlignment( width, widthAfter );
emit itemChanged();
}

void QgsComposerScaleBar::setNumSegmentsLeft( int nSegmentsLeft )
Expand All @@ -104,6 +106,7 @@ void QgsComposerScaleBar::setNumSegmentsLeft( int nSegmentsLeft )
mNumSegmentsLeft = nSegmentsLeft;
double widthAfter = mStyle->calculateBoxSize().width();
correctXPositionAlignment( width, widthAfter );
emit itemChanged();
}

void QgsComposerScaleBar::setBoxContentSpace( double space )
Expand All @@ -117,6 +120,7 @@ void QgsComposerScaleBar::setBoxContentSpace( double space )
mBoxContentSpace = space;
double widthAfter = mStyle->calculateBoxSize().width();
correctXPositionAlignment( width, widthAfter );
emit itemChanged();
}

void QgsComposerScaleBar::setComposerMap( const QgsComposerMap* map )
Expand All @@ -134,6 +138,7 @@ void QgsComposerScaleBar::setComposerMap( const QgsComposerMap* map )
connect( mComposerMap, SIGNAL( destroyed( QObject* ) ), this, SLOT( invalidateCurrentMap() ) );

refreshSegmentMillimeters();
emit itemChanged();
}

void QgsComposerScaleBar::invalidateCurrentMap()
Expand Down Expand Up @@ -181,6 +186,7 @@ void QgsComposerScaleBar::applyDefaultSettings()

mLabelBarSpace = 3.0;
mBoxContentSpace = 1.0;
emit itemChanged();
}

void QgsComposerScaleBar::applyDefaultSize()
Expand All @@ -199,6 +205,7 @@ void QgsComposerScaleBar::applyDefaultSize()

refreshSegmentMillimeters();
adjustBoxSize();
emit itemChanged();
}

void QgsComposerScaleBar::adjustBoxSize()
Expand Down Expand Up @@ -229,6 +236,7 @@ void QgsComposerScaleBar::updateSegmentSize()
double widthAfter = mStyle->calculateBoxSize().width();
correctXPositionAlignment( width, widthAfter );
update();
emit itemChanged();
}

void QgsComposerScaleBar::segmentPositions( QList<QPair<double, double> >& posWidthList ) const
Expand Down Expand Up @@ -286,6 +294,7 @@ void QgsComposerScaleBar::setStyle( const QString& styleName )
{
mStyle = new QgsNumericScaleBarStyle( this );
}
emit itemChanged();
}

QString QgsComposerScaleBar::style() const
Expand Down Expand Up @@ -322,6 +331,7 @@ void QgsComposerScaleBar::setFont( const QFont& font )
mFont = font;
adjustBoxSize();
update();
emit itemChanged();
}

bool QgsComposerScaleBar::writeXML( QDomElement& elem, QDomDocument & doc ) const
Expand Down

0 comments on commit 26fda3f

Please sign in to comment.