Skip to content

Commit

Permalink
[FEATURE]: possibility to change grid annotation position and directi…
Browse files Browse the repository at this point in the history
…on indidually for left/right/top/bottom
  • Loading branch information
mhugent committed Jul 3, 2012
1 parent fab2fe1 commit 9cd59c9
Show file tree
Hide file tree
Showing 5 changed files with 632 additions and 301 deletions.
210 changes: 145 additions & 65 deletions src/app/composer/qgscomposermapwidget.cpp
Expand Up @@ -17,7 +17,6 @@

#include "qgscomposermapwidget.h"
#include "qgscomposeritemwidget.h"
#include "qgscomposermap.h"
#include "qgsmaprenderer.h"
#include <QColorDialog>
#include <QFontDialog>
Expand Down Expand Up @@ -47,13 +46,16 @@ QgsComposerMapWidget::QgsComposerMapWidget( QgsComposerMap* composerMap ): QWidg
mGridTypeComboBox->insertItem( 0, tr( "Solid" ) );
mGridTypeComboBox->insertItem( 1, tr( "Cross" ) );

mAnnotationPositionComboBox->insertItem( 0, tr( "Inside frame" ) );
mAnnotationPositionComboBox->insertItem( 1, tr( "Outside frame" ) );
insertAnnotationPositionEntries( mAnnotationPositionLeftComboBox );
insertAnnotationPositionEntries( mAnnotationPositionRightComboBox );
insertAnnotationPositionEntries( mAnnotationPositionTopComboBox );
insertAnnotationPositionEntries( mAnnotationPositionBottomComboBox );

insertAnnotationDirectionEntries( mAnnotationDirectionComboBoxLeft );
insertAnnotationDirectionEntries( mAnnotationDirectionComboBoxRight );
insertAnnotationDirectionEntries( mAnnotationDirectionComboBoxTop );
insertAnnotationDirectionEntries( mAnnotationDirectionComboBoxBottom );

mAnnotationDirectionComboBox->insertItem( 0, tr( "Horizontal" ) );
mAnnotationDirectionComboBox->insertItem( 1, tr( "Vertical" ) );
mAnnotationDirectionComboBox->insertItem( 2, tr( "Horizontal and Vertical" ) );
mAnnotationDirectionComboBox->insertItem( 2, tr( "Boundary direction" ) );
if ( composerMap )
{
connect( composerMap, SIGNAL( itemChanged() ), this, SLOT( setGuiElementValues() ) );
Expand Down Expand Up @@ -344,15 +346,17 @@ void QgsComposerMapWidget::updateGuiElements()

mCrossWidthSpinBox->setValue( mComposerMap->crossLength() );

QgsComposerMap::GridAnnotationPosition annotationPos = mComposerMap->gridAnnotationPosition();
if ( annotationPos == QgsComposerMap::InsideMapFrame )
{
mAnnotationPositionComboBox->setCurrentIndex( mAnnotationPositionComboBox->findText( tr( "Inside frame" ) ) );
}
else
{
mAnnotationPositionComboBox->setCurrentIndex( mAnnotationPositionComboBox->findText( tr( "Outside frame" ) ) );
}
//grid annotation position
initAnnotationPositionBox( mAnnotationPositionLeftComboBox, mComposerMap->gridAnnotationPosition( QgsComposerMap::Left ) );
initAnnotationPositionBox( mAnnotationPositionRightComboBox, mComposerMap->gridAnnotationPosition( QgsComposerMap::Right ) );
initAnnotationPositionBox( mAnnotationPositionTopComboBox, mComposerMap->gridAnnotationPosition( QgsComposerMap::Top ) );
initAnnotationPositionBox( mAnnotationPositionBottomComboBox, mComposerMap->gridAnnotationPosition( QgsComposerMap::Bottom ) );

//grid annotation direction
initAnnotationDirectionBox( mAnnotationDirectionComboBoxLeft, mComposerMap->gridAnnotationDirection( QgsComposerMap::Left ) );
initAnnotationDirectionBox( mAnnotationDirectionComboBoxRight, mComposerMap->gridAnnotationDirection( QgsComposerMap::Right ) );
initAnnotationDirectionBox( mAnnotationDirectionComboBoxTop, mComposerMap->gridAnnotationDirection( QgsComposerMap::Top ) );
initAnnotationDirectionBox( mAnnotationDirectionComboBoxBottom, mComposerMap->gridAnnotationDirection( QgsComposerMap::Bottom ) );

mDistanceToMapFrameSpinBox->setValue( mComposerMap->annotationFrameDistance() );

Expand All @@ -365,24 +369,6 @@ void QgsComposerMapWidget::updateGuiElements()
mDrawAnnotationCheckBox->setCheckState( Qt::Unchecked );
}

QgsComposerMap::GridAnnotationDirection dir = mComposerMap->gridAnnotationDirection();
if ( dir == QgsComposerMap::Horizontal )
{
mAnnotationDirectionComboBox->setCurrentIndex( mAnnotationDirectionComboBox->findText( tr( "Horizontal" ) ) );
}
else if ( dir == QgsComposerMap::Vertical )
{
mAnnotationDirectionComboBox->setCurrentIndex( mAnnotationDirectionComboBox->findText( tr( "Vertical" ) ) );
}
else if ( dir == QgsComposerMap::HorizontalAndVertical )
{
mAnnotationDirectionComboBox->setCurrentIndex( mAnnotationDirectionComboBox->findText( tr( "Horizontal and Vertical" ) ) );
}
else //BoundaryDirection
{
mAnnotationDirectionComboBox->setCurrentIndex( mAnnotationDirectionComboBox->findText( tr( "Boundary direction" ) ) );
}

mCoordinatePrecisionSpinBox->setValue( mComposerMap->gridAnnotationPrecision() );

QPen gridPen = mComposerMap->gridPen();
Expand Down Expand Up @@ -445,9 +431,15 @@ void QgsComposerMapWidget::blockAllSignals( bool b )
mLineColorButton->blockSignals( b );
mDrawAnnotationCheckBox->blockSignals( b );
mAnnotationFontButton->blockSignals( b );
mAnnotationPositionComboBox->blockSignals( b );
mAnnotationPositionLeftComboBox->blockSignals( b );
mAnnotationPositionRightComboBox->blockSignals( b );
mAnnotationPositionTopComboBox->blockSignals( b );
mAnnotationPositionBottomComboBox->blockSignals( b );
mDistanceToMapFrameSpinBox->blockSignals( b );
mAnnotationDirectionComboBox->blockSignals( b );
mAnnotationDirectionComboBoxLeft->blockSignals( b );
mAnnotationDirectionComboBoxRight->blockSignals( b );
mAnnotationDirectionComboBoxTop->blockSignals( b );
mAnnotationDirectionComboBoxBottom->blockSignals( b );
mCoordinatePrecisionSpinBox->blockSignals( b );
mDrawCanvasItemsCheckBox->blockSignals( b );
}
Expand Down Expand Up @@ -683,49 +675,120 @@ void QgsComposerMapWidget::on_mDistanceToMapFrameSpinBox_valueChanged( double d
mComposerMap->endCommand();
}

void QgsComposerMapWidget::on_mAnnotationPositionComboBox_currentIndexChanged( const QString& text )
void QgsComposerMapWidget::on_mAnnotationPositionLeftComboBox_currentIndexChanged( const QString& text )
{
handleChangedAnnotationPosition( QgsComposerMap::Left, text );
}

void QgsComposerMapWidget::on_mAnnotationPositionRightComboBox_currentIndexChanged( const QString& text )
{
handleChangedAnnotationPosition( QgsComposerMap::Right, text );
}

void QgsComposerMapWidget::on_mAnnotationPositionTopComboBox_currentIndexChanged( const QString& text )
{
handleChangedAnnotationPosition( QgsComposerMap::Top, text );
}

void QgsComposerMapWidget::on_mAnnotationPositionBottomComboBox_currentIndexChanged( const QString& text )
{
handleChangedAnnotationPosition( QgsComposerMap::Bottom, text );
}

void QgsComposerMapWidget::on_mDrawAnnotationCheckBox_stateChanged( int state )
{
if ( !mComposerMap )
{
return;
}

mComposerMap->beginCommand( tr( "Annotation position changed" ) );
if ( text == tr( "Inside frame" ) )
mComposerMap->beginCommand( tr( "Annotation toggled" ) );
if ( state == Qt::Checked )
{
mComposerMap->setGridAnnotationPosition( QgsComposerMap::InsideMapFrame );
mComposerMap->setShowGridAnnotation( true );
}
else
{
mComposerMap->setGridAnnotationPosition( QgsComposerMap::OutsideMapFrame );
mComposerMap->setShowGridAnnotation( false );
}
mComposerMap->updateBoundingRect();
mComposerMap->update();
mComposerMap->endCommand();
}

void QgsComposerMapWidget::on_mDrawAnnotationCheckBox_stateChanged( int state )
void QgsComposerMapWidget::on_mAnnotationDirectionComboBoxLeft_currentIndexChanged( const QString& text )
{
handleChangedAnnotationDirection( QgsComposerMap::Left, text );
}

void QgsComposerMapWidget::on_mAnnotationDirectionComboBoxRight_currentIndexChanged( const QString& text )
{
handleChangedAnnotationDirection( QgsComposerMap::Right, text );
}

void QgsComposerMapWidget::on_mAnnotationDirectionComboBoxTop_currentIndexChanged( const QString& text )
{
handleChangedAnnotationDirection( QgsComposerMap::Top, text );
}

void QgsComposerMapWidget::on_mAnnotationDirectionComboBoxBottom_currentIndexChanged( const QString& text )
{
handleChangedAnnotationDirection( QgsComposerMap::Bottom, text );
}

void QgsComposerMapWidget::on_mCoordinatePrecisionSpinBox_valueChanged( int value )
{
if ( !mComposerMap )
{
return;
}
mComposerMap->beginCommand( tr( "Changed annotation precision" ) );
mComposerMap->setGridAnnotationPrecision( value );
mComposerMap->updateBoundingRect();
mComposerMap->update();
mComposerMap->endCommand();
}

void QgsComposerMapWidget::insertAnnotationPositionEntries( QComboBox* c )
{
c->insertItem( 0, tr( "Inside frame" ) );
c->insertItem( 1, tr( "Outside frame" ) );
c->insertItem( 2, tr( "Disabled" ) );
}

void QgsComposerMapWidget::insertAnnotationDirectionEntries( QComboBox* c )
{
c->insertItem( 0, tr( "Horizontal" ) );
c->insertItem( 1, tr( "Vertical" ) );
}

void QgsComposerMapWidget::handleChangedAnnotationPosition( QgsComposerMap::Border border, const QString& text )
{
if ( !mComposerMap )
{
return;
}

mComposerMap->beginCommand( tr( "Annotation toggled" ) );
if ( state == Qt::Checked )
mComposerMap->beginCommand( tr( "Annotation position changed" ) );
if ( text == tr( "Inside frame" ) )
{
mComposerMap->setShowGridAnnotation( true );
mComposerMap->setGridAnnotationPosition( QgsComposerMap::InsideMapFrame, border );
}
else
else if ( text == tr( "Disabled" ) )
{
mComposerMap->setShowGridAnnotation( false );
mComposerMap->setGridAnnotationPosition( QgsComposerMap::Disabled, border );
}
else //Outside frame
{
mComposerMap->setGridAnnotationPosition( QgsComposerMap::OutsideMapFrame, border );
}

mComposerMap->updateBoundingRect();
mComposerMap->update();
mComposerMap->endCommand();
}

void QgsComposerMapWidget::on_mAnnotationDirectionComboBox_currentIndexChanged( const QString& text )
void QgsComposerMapWidget::handleChangedAnnotationDirection( QgsComposerMap::Border border, const QString& text )
{
if ( !mComposerMap )
{
Expand All @@ -735,34 +798,51 @@ void QgsComposerMapWidget::on_mAnnotationDirectionComboBox_currentIndexChanged(
mComposerMap->beginCommand( tr( "Changed annotation direction" ) );
if ( text == tr( "Horizontal" ) )
{
mComposerMap->setGridAnnotationDirection( QgsComposerMap::Horizontal );
mComposerMap->setGridAnnotationDirection( QgsComposerMap::Horizontal, border );
}
else //Vertical
{
mComposerMap->setGridAnnotationDirection( QgsComposerMap::Vertical, border );
}
else if ( text == tr( "Vertical" ) )
mComposerMap->updateBoundingRect();
mComposerMap->update();
mComposerMap->endCommand();
}

void QgsComposerMapWidget::initAnnotationPositionBox( QComboBox* c, QgsComposerMap::GridAnnotationPosition pos )
{
if ( !c )
{
mComposerMap->setGridAnnotationDirection( QgsComposerMap::Vertical );
return;
}
else if ( text == tr( "Horizontal and Vertical" ) )

if ( pos == QgsComposerMap::InsideMapFrame )
{
mComposerMap->setGridAnnotationDirection( QgsComposerMap::HorizontalAndVertical );
c->setCurrentIndex( c->findText( tr( "Inside frame" ) ) );
}
else //BoundaryDirection
else if ( pos == QgsComposerMap::OutsideMapFrame )
{
mComposerMap->setGridAnnotationDirection( QgsComposerMap::BoundaryDirection );
c->setCurrentIndex( c->findText( tr( "Outside frame" ) ) );
}
else //disabled
{
c->setCurrentIndex( c->findText( tr( "Disabled" ) ) );
}
mComposerMap->updateBoundingRect();
mComposerMap->update();
mComposerMap->endCommand();
}

void QgsComposerMapWidget::on_mCoordinatePrecisionSpinBox_valueChanged( int value )
void QgsComposerMapWidget::initAnnotationDirectionBox( QComboBox* c, QgsComposerMap::GridAnnotationDirection dir )
{
if ( !mComposerMap )
if ( !c )
{
return;
}
mComposerMap->beginCommand( tr( "Changed annotation precision" ) );
mComposerMap->setGridAnnotationPrecision( value );
mComposerMap->updateBoundingRect();
mComposerMap->update();
mComposerMap->endCommand();

if ( dir == QgsComposerMap::Vertical )
{
c->setCurrentIndex( c->findText( tr( "Vertical" ) ) );
}
else //horizontal
{
c->setCurrentIndex( c->findText( tr( "Horizontal" ) ) );
}
}
27 changes: 23 additions & 4 deletions src/app/composer/qgscomposermapwidget.h
Expand Up @@ -19,8 +19,7 @@
#define QGSCOMPOSERMAPWIDGET_H

#include "ui_qgscomposermapwidgetbase.h"

class QgsComposerMap;
#include "qgscomposermap.h"

/** \ingroup MapComposer
* Input widget for the configuration of QgsComposerMap
Expand Down Expand Up @@ -61,9 +60,20 @@ class QgsComposerMapWidget: public QWidget, private Ui::QgsComposerMapWidgetBase
void on_mCrossWidthSpinBox_valueChanged( double d );
void on_mAnnotationFontButton_clicked();
void on_mDistanceToMapFrameSpinBox_valueChanged( double d );
void on_mAnnotationPositionComboBox_currentIndexChanged( const QString& text );

//annotation position
void on_mAnnotationPositionLeftComboBox_currentIndexChanged( const QString& text );
void on_mAnnotationPositionRightComboBox_currentIndexChanged( const QString& text );
void on_mAnnotationPositionTopComboBox_currentIndexChanged( const QString& text );
void on_mAnnotationPositionBottomComboBox_currentIndexChanged( const QString& text );

//annotation direction
void on_mAnnotationDirectionComboBoxLeft_currentIndexChanged( const QString& text );
void on_mAnnotationDirectionComboBoxRight_currentIndexChanged( const QString& text );
void on_mAnnotationDirectionComboBoxTop_currentIndexChanged( const QString& text );
void on_mAnnotationDirectionComboBoxBottom_currentIndexChanged( const QString& text );

void on_mDrawAnnotationCheckBox_stateChanged( int state );
void on_mAnnotationDirectionComboBox_currentIndexChanged( const QString& text );
void on_mCoordinatePrecisionSpinBox_valueChanged( int value );

private slots:
Expand All @@ -82,6 +92,15 @@ class QgsComposerMapWidget: public QWidget, private Ui::QgsComposerMapWidgetBase

/**Blocks / unblocks the signals of all GUI elements*/
void blockAllSignals( bool b );

void handleChangedAnnotationPosition( QgsComposerMap::Border border, const QString& text );
void handleChangedAnnotationDirection( QgsComposerMap::Border border, const QString& text );

void insertAnnotationPositionEntries( QComboBox* c );
void insertAnnotationDirectionEntries( QComboBox* c );

void initAnnotationPositionBox( QComboBox* c, QgsComposerMap::GridAnnotationPosition pos );
void initAnnotationDirectionBox( QComboBox* c, QgsComposerMap::GridAnnotationDirection dir );
};

#endif

0 comments on commit 9cd59c9

Please sign in to comment.