Skip to content

Commit

Permalink
Disconnect itemChanged signal for composer scalebar if scalebar widge…
Browse files Browse the repository at this point in the history
…t does the change
  • Loading branch information
mhugent committed Aug 14, 2012
1 parent 778e7d7 commit f53f468
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
51 changes: 47 additions & 4 deletions src/app/composer/qgscomposerscalebarwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@
QgsComposerScaleBarWidget::QgsComposerScaleBarWidget( QgsComposerScaleBar* scaleBar ): QWidget(), mComposerScaleBar( scaleBar )
{
setupUi( this );
if ( scaleBar )
{
QObject::connect( scaleBar, SIGNAL( itemChanged() ), this, SLOT( setGuiElements() ) );
}
connectUpdateSignal();

//add widget for general composer item properties
QgsComposerItemWidget* itemPropertiesWidget = new QgsComposerItemWidget( this, scaleBar );
Expand Down Expand Up @@ -147,8 +144,10 @@ void QgsComposerScaleBarWidget::on_mMapComboBox_activated( const QString& text )

//set it to scale bar
mComposerScaleBar->beginCommand( tr( "Scalebar map changed" ) );
disconnectUpdateSignal();
mComposerScaleBar->setComposerMap( composerMap );
mComposerScaleBar->update();
connectUpdateSignal();
mComposerScaleBar->endCommand();
}

Expand Down Expand Up @@ -204,10 +203,12 @@ void QgsComposerScaleBarWidget::on_mLineWidthSpinBox_valueChanged( double d )
}

mComposerScaleBar->beginCommand( tr( "Scalebar line width" ), QgsComposerMergeCommand::ScaleBarLineWidth );
disconnectUpdateSignal();
QPen newPen( QColor( 0, 0, 0 ) );
newPen.setWidthF( d );
mComposerScaleBar->setPen( newPen );
mComposerScaleBar->update();
connectUpdateSignal();
mComposerScaleBar->endCommand();
}

Expand All @@ -219,8 +220,10 @@ void QgsComposerScaleBarWidget::on_mSegmentSizeSpinBox_valueChanged( double d )
}

mComposerScaleBar->beginCommand( tr( "Scalebar segment size" ), QgsComposerMergeCommand::ScaleBarSegmentSize );
disconnectUpdateSignal();
mComposerScaleBar->setNumUnitsPerSegment( d );
mComposerScaleBar->update();
connectUpdateSignal();
mComposerScaleBar->endCommand();
}

Expand All @@ -232,8 +235,10 @@ void QgsComposerScaleBarWidget::on_mSegmentsLeftSpinBox_valueChanged( int i )
}

mComposerScaleBar->beginCommand( tr( "Scalebar segments left" ), QgsComposerMergeCommand::ScaleBarSegmentsLeft );
disconnectUpdateSignal();
mComposerScaleBar->setNumSegmentsLeft( i );
mComposerScaleBar->update();
connectUpdateSignal();
mComposerScaleBar->endCommand();
}

Expand All @@ -245,8 +250,10 @@ void QgsComposerScaleBarWidget::on_mNumberOfSegmentsSpinBox_valueChanged( int i
}

mComposerScaleBar->beginCommand( tr( "Scalebar n segments" ), QgsComposerMergeCommand::ScaleBarNSegments );
disconnectUpdateSignal();
mComposerScaleBar->setNumSegments( i );
mComposerScaleBar->update();
connectUpdateSignal();
mComposerScaleBar->endCommand();
}

Expand All @@ -257,8 +264,10 @@ void QgsComposerScaleBarWidget::on_mHeightSpinBox_valueChanged( int i )
return;
}
mComposerScaleBar->beginCommand( tr( "Scalebar height changed" ), QgsComposerMergeCommand::ScaleBarHeight );
disconnectUpdateSignal();
mComposerScaleBar->setHeight( i );
mComposerScaleBar->update();
connectUpdateSignal();
mComposerScaleBar->endCommand();
}

Expand All @@ -280,7 +289,9 @@ void QgsComposerScaleBarWidget::on_mFontButton_clicked()
if ( dialogAccepted )
{
mComposerScaleBar->beginCommand( tr( "Scalebar font changed" ) );
disconnectUpdateSignal();
mComposerScaleBar->setFont( newFont );
connectUpdateSignal();
mComposerScaleBar->endCommand();
}
mComposerScaleBar->update();
Expand All @@ -302,9 +313,11 @@ void QgsComposerScaleBarWidget::on_mColorPushButton_clicked()
}

mComposerScaleBar->beginCommand( tr( "Scalebar color changed" ) );
disconnectUpdateSignal();
QBrush newBrush( newColor );
mComposerScaleBar->setBrush( newBrush );
mComposerScaleBar->update();
connectUpdateSignal();
mComposerScaleBar->endCommand();
}

Expand All @@ -316,8 +329,10 @@ void QgsComposerScaleBarWidget::on_mUnitLabelLineEdit_textChanged( const QString
}

mComposerScaleBar->beginCommand( tr( "Scalebar unit text" ), QgsComposerMergeCommand::ScaleBarUnitText );
disconnectUpdateSignal();
mComposerScaleBar->setUnitLabeling( text );
mComposerScaleBar->update();
connectUpdateSignal();
mComposerScaleBar->endCommand();
}

Expand All @@ -329,8 +344,10 @@ void QgsComposerScaleBarWidget::on_mMapUnitsPerBarUnitSpinBox_valueChanged( doub
}

mComposerScaleBar->beginCommand( tr( "Scalebar map units per segment" ), QgsComposerMergeCommand::ScaleBarMapUnitsSegment );
disconnectUpdateSignal();
mComposerScaleBar->setNumMapUnitsPerScaleBarUnit( d );
mComposerScaleBar->update();
connectUpdateSignal();
mComposerScaleBar->endCommand();
}

Expand All @@ -342,6 +359,7 @@ void QgsComposerScaleBarWidget::on_mStyleComboBox_currentIndexChanged( const QSt
}

mComposerScaleBar->beginCommand( tr( "Scalebar style changed" ) );
disconnectUpdateSignal();
QString untranslatedStyleName;
if ( text == tr( "Single Box" ) )
{
Expand Down Expand Up @@ -373,6 +391,7 @@ void QgsComposerScaleBarWidget::on_mStyleComboBox_currentIndexChanged( const QSt
}
mComposerScaleBar->setStyle( untranslatedStyleName );
mComposerScaleBar->update();
connectUpdateSignal();
mComposerScaleBar->endCommand();
}

Expand All @@ -384,8 +403,10 @@ void QgsComposerScaleBarWidget::on_mLabelBarSpaceSpinBox_valueChanged( double d
}

mComposerScaleBar->beginCommand( tr( "Scalebar label bar space" ), QgsComposerMergeCommand::ScaleBarLabelBarSize );
disconnectUpdateSignal();
mComposerScaleBar->setLabelBarSpace( d );
mComposerScaleBar->update();
connectUpdateSignal();
mComposerScaleBar->endCommand();
}

Expand All @@ -397,8 +418,10 @@ void QgsComposerScaleBarWidget::on_mBoxSizeSpinBox_valueChanged( double d )
}

mComposerScaleBar->beginCommand( tr( "Scalebar box content space" ), QgsComposerMergeCommand::ScaleBarBoxContentSpace );
disconnectUpdateSignal();
mComposerScaleBar->setBoxContentSpace( d );
mComposerScaleBar->update();
connectUpdateSignal();
mComposerScaleBar->endCommand();
}

Expand All @@ -410,7 +433,9 @@ void QgsComposerScaleBarWidget::on_mAlignmentComboBox_currentIndexChanged( int i
}

mComposerScaleBar->beginCommand( tr( "Scalebar alignment" ) );
disconnectUpdateSignal();
mComposerScaleBar->setAlignment(( QgsComposerScaleBar::Alignment ) index );
connectUpdateSignal();
mComposerScaleBar->endCommand();
}

Expand All @@ -428,8 +453,10 @@ void QgsComposerScaleBarWidget::on_mUnitsComboBox_currentIndexChanged( int index
}

mComposerScaleBar->beginCommand( tr( "Scalebar unit changed" ) );
disconnectUpdateSignal();
mComposerScaleBar->setUnits(( QgsComposerScaleBar::ScaleBarUnits )unitData.toInt() );
mComposerScaleBar->update();
connectUpdateSignal();
mComposerScaleBar->endCommand();
}

Expand All @@ -449,3 +476,19 @@ void QgsComposerScaleBarWidget::blockMemberSignals( bool block )
mAlignmentComboBox->blockSignals( block );
mUnitsComboBox->blockSignals( block );
}

void QgsComposerScaleBarWidget::connectUpdateSignal()
{
if ( mComposerScaleBar )
{
QObject::connect( mComposerScaleBar, SIGNAL( itemChanged() ), this, SLOT( setGuiElements() ) );
}
}

void QgsComposerScaleBarWidget::disconnectUpdateSignal()
{
if ( mComposerScaleBar )
{
QObject::disconnect( mComposerScaleBar, SIGNAL( itemChanged() ), this, SLOT( setGuiElements() ) );
}
}
3 changes: 3 additions & 0 deletions src/app/composer/qgscomposerscalebarwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ class QgsComposerScaleBarWidget: public QWidget, private Ui::QgsComposerScaleBar
void refreshMapComboBox();
/**Enables/disables the signals of the input gui elements*/
void blockMemberSignals( bool enable );

void connectUpdateSignal();
void disconnectUpdateSignal();
};

#endif //QGSCOMPOSERSCALEBARWIDGET_H

0 comments on commit f53f468

Please sign in to comment.