Skip to content
Permalink
Browse files

Merge branch 'graticule_labels'

  • Loading branch information
mhugent committed Jul 4, 2012
2 parents 040b046 + 5a7cb21 commit a6adecdb04994986236796d51a347e541c09b506
@@ -47,6 +47,15 @@ class QgsComposerMap : QgsComposerItem
BoundaryDirection
};

/**Enum for different frame borders*/
enum Border
{
Left,
Right,
Bottom,
Top
};

/**@deprecated*/
void draw( QPainter *painter, const QgsRectangle& extent, const QSize& size, int dpi );

@@ -195,20 +204,22 @@ class QgsComposerMap : QgsComposerItem
void setShowGridAnnotation( bool show );
bool showGridAnnotation() const;

/**Sets position of grid annotations. Possibilities are inside or outside of the map frame
@note this function was added in version 1.4*/
void setGridAnnotationPosition( GridAnnotationPosition p );
GridAnnotationPosition gridAnnotationPosition() const;
/**Sets position of grid annotations. Possibilities are inside / outside of the map frame or disabled
@note this function was added in version 1.9*/
void setGridAnnotationPosition( GridAnnotationPosition p, QgsComposerMap::Border border );
/**@note: this function was added in version 1.9*/
GridAnnotationPosition gridAnnotationPosition( QgsComposerMap::Border border ) const;

/**Sets distance between map frame and annotations
@note this function was added in version 1.4*/
void setAnnotationFrameDistance( double d );
double annotationFrameDistance() const;

/**Sets grid annotation direction. Can be horizontal, vertical, direction of axis and horizontal and vertical
@note this function was added in version 1.4*/
void setGridAnnotationDirection( GridAnnotationDirection d );
GridAnnotationDirection gridAnnotationDirection() const;
/**Sets grid annotation direction. Can be horizontal or vertical
@note this function was added in version 1.9*/
void setGridAnnotationDirection( GridAnnotationDirection d, QgsComposerMap::Border border );
/**@note: this function was added in version 1.9*/
GridAnnotationDirection gridAnnotationDirection( QgsComposerMap::Border border ) const;

/**In case of annotations, the bounding rectangle can be larger than the map item rectangle
@note this function was added in version 1.4*/
@@ -17,7 +17,6 @@

#include "qgscomposermapwidget.h"
#include "qgscomposeritemwidget.h"
#include "qgscomposermap.h"
#include "qgsmaprenderer.h"
#include <QColorDialog>
#include <QFontDialog>
@@ -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() ) );
@@ -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() );

@@ -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();
@@ -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 );
}
@@ -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 )
{
@@ -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" ) ) );
}
}
@@ -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
@@ -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:
@@ -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 a6adecd

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