Skip to content

Commit a6adecd

Browse files
committed
Merge branch 'graticule_labels'
2 parents 040b046 + 5a7cb21 commit a6adecd

7 files changed

Lines changed: 706 additions & 323 deletions

File tree

‎python/core/qgscomposermap.sip‎

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ class QgsComposerMap : QgsComposerItem
4747
BoundaryDirection
4848
};
4949

50+
/**Enum for different frame borders*/
51+
enum Border
52+
{
53+
Left,
54+
Right,
55+
Bottom,
56+
Top
57+
};
58+
5059
/**@deprecated*/
5160
void draw( QPainter *painter, const QgsRectangle& extent, const QSize& size, int dpi );
5261

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

198-
/**Sets position of grid annotations. Possibilities are inside or outside of the map frame
199-
@note this function was added in version 1.4*/
200-
void setGridAnnotationPosition( GridAnnotationPosition p );
201-
GridAnnotationPosition gridAnnotationPosition() const;
207+
/**Sets position of grid annotations. Possibilities are inside / outside of the map frame or disabled
208+
@note this function was added in version 1.9*/
209+
void setGridAnnotationPosition( GridAnnotationPosition p, QgsComposerMap::Border border );
210+
/**@note: this function was added in version 1.9*/
211+
GridAnnotationPosition gridAnnotationPosition( QgsComposerMap::Border border ) const;
202212

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

208-
/**Sets grid annotation direction. Can be horizontal, vertical, direction of axis and horizontal and vertical
209-
@note this function was added in version 1.4*/
210-
void setGridAnnotationDirection( GridAnnotationDirection d );
211-
GridAnnotationDirection gridAnnotationDirection() const;
218+
/**Sets grid annotation direction. Can be horizontal or vertical
219+
@note this function was added in version 1.9*/
220+
void setGridAnnotationDirection( GridAnnotationDirection d, QgsComposerMap::Border border );
221+
/**@note: this function was added in version 1.9*/
222+
GridAnnotationDirection gridAnnotationDirection( QgsComposerMap::Border border ) const;
212223

213224
/**In case of annotations, the bounding rectangle can be larger than the map item rectangle
214225
@note this function was added in version 1.4*/

‎src/app/composer/qgscomposermapwidget.cpp‎

Lines changed: 145 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
#include "qgscomposermapwidget.h"
1919
#include "qgscomposeritemwidget.h"
20-
#include "qgscomposermap.h"
2120
#include "qgsmaprenderer.h"
2221
#include <QColorDialog>
2322
#include <QFontDialog>
@@ -47,13 +46,16 @@ QgsComposerMapWidget::QgsComposerMapWidget( QgsComposerMap* composerMap ): QWidg
4746
mGridTypeComboBox->insertItem( 0, tr( "Solid" ) );
4847
mGridTypeComboBox->insertItem( 1, tr( "Cross" ) );
4948

50-
mAnnotationPositionComboBox->insertItem( 0, tr( "Inside frame" ) );
51-
mAnnotationPositionComboBox->insertItem( 1, tr( "Outside frame" ) );
49+
insertAnnotationPositionEntries( mAnnotationPositionLeftComboBox );
50+
insertAnnotationPositionEntries( mAnnotationPositionRightComboBox );
51+
insertAnnotationPositionEntries( mAnnotationPositionTopComboBox );
52+
insertAnnotationPositionEntries( mAnnotationPositionBottomComboBox );
53+
54+
insertAnnotationDirectionEntries( mAnnotationDirectionComboBoxLeft );
55+
insertAnnotationDirectionEntries( mAnnotationDirectionComboBoxRight );
56+
insertAnnotationDirectionEntries( mAnnotationDirectionComboBoxTop );
57+
insertAnnotationDirectionEntries( mAnnotationDirectionComboBoxBottom );
5258

53-
mAnnotationDirectionComboBox->insertItem( 0, tr( "Horizontal" ) );
54-
mAnnotationDirectionComboBox->insertItem( 1, tr( "Vertical" ) );
55-
mAnnotationDirectionComboBox->insertItem( 2, tr( "Horizontal and Vertical" ) );
56-
mAnnotationDirectionComboBox->insertItem( 2, tr( "Boundary direction" ) );
5759
if ( composerMap )
5860
{
5961
connect( composerMap, SIGNAL( itemChanged() ), this, SLOT( setGuiElementValues() ) );
@@ -344,15 +346,17 @@ void QgsComposerMapWidget::updateGuiElements()
344346

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

347-
QgsComposerMap::GridAnnotationPosition annotationPos = mComposerMap->gridAnnotationPosition();
348-
if ( annotationPos == QgsComposerMap::InsideMapFrame )
349-
{
350-
mAnnotationPositionComboBox->setCurrentIndex( mAnnotationPositionComboBox->findText( tr( "Inside frame" ) ) );
351-
}
352-
else
353-
{
354-
mAnnotationPositionComboBox->setCurrentIndex( mAnnotationPositionComboBox->findText( tr( "Outside frame" ) ) );
355-
}
349+
//grid annotation position
350+
initAnnotationPositionBox( mAnnotationPositionLeftComboBox, mComposerMap->gridAnnotationPosition( QgsComposerMap::Left ) );
351+
initAnnotationPositionBox( mAnnotationPositionRightComboBox, mComposerMap->gridAnnotationPosition( QgsComposerMap::Right ) );
352+
initAnnotationPositionBox( mAnnotationPositionTopComboBox, mComposerMap->gridAnnotationPosition( QgsComposerMap::Top ) );
353+
initAnnotationPositionBox( mAnnotationPositionBottomComboBox, mComposerMap->gridAnnotationPosition( QgsComposerMap::Bottom ) );
354+
355+
//grid annotation direction
356+
initAnnotationDirectionBox( mAnnotationDirectionComboBoxLeft, mComposerMap->gridAnnotationDirection( QgsComposerMap::Left ) );
357+
initAnnotationDirectionBox( mAnnotationDirectionComboBoxRight, mComposerMap->gridAnnotationDirection( QgsComposerMap::Right ) );
358+
initAnnotationDirectionBox( mAnnotationDirectionComboBoxTop, mComposerMap->gridAnnotationDirection( QgsComposerMap::Top ) );
359+
initAnnotationDirectionBox( mAnnotationDirectionComboBoxBottom, mComposerMap->gridAnnotationDirection( QgsComposerMap::Bottom ) );
356360

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

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

368-
QgsComposerMap::GridAnnotationDirection dir = mComposerMap->gridAnnotationDirection();
369-
if ( dir == QgsComposerMap::Horizontal )
370-
{
371-
mAnnotationDirectionComboBox->setCurrentIndex( mAnnotationDirectionComboBox->findText( tr( "Horizontal" ) ) );
372-
}
373-
else if ( dir == QgsComposerMap::Vertical )
374-
{
375-
mAnnotationDirectionComboBox->setCurrentIndex( mAnnotationDirectionComboBox->findText( tr( "Vertical" ) ) );
376-
}
377-
else if ( dir == QgsComposerMap::HorizontalAndVertical )
378-
{
379-
mAnnotationDirectionComboBox->setCurrentIndex( mAnnotationDirectionComboBox->findText( tr( "Horizontal and Vertical" ) ) );
380-
}
381-
else //BoundaryDirection
382-
{
383-
mAnnotationDirectionComboBox->setCurrentIndex( mAnnotationDirectionComboBox->findText( tr( "Boundary direction" ) ) );
384-
}
385-
386372
mCoordinatePrecisionSpinBox->setValue( mComposerMap->gridAnnotationPrecision() );
387373

388374
QPen gridPen = mComposerMap->gridPen();
@@ -445,9 +431,15 @@ void QgsComposerMapWidget::blockAllSignals( bool b )
445431
mLineColorButton->blockSignals( b );
446432
mDrawAnnotationCheckBox->blockSignals( b );
447433
mAnnotationFontButton->blockSignals( b );
448-
mAnnotationPositionComboBox->blockSignals( b );
434+
mAnnotationPositionLeftComboBox->blockSignals( b );
435+
mAnnotationPositionRightComboBox->blockSignals( b );
436+
mAnnotationPositionTopComboBox->blockSignals( b );
437+
mAnnotationPositionBottomComboBox->blockSignals( b );
449438
mDistanceToMapFrameSpinBox->blockSignals( b );
450-
mAnnotationDirectionComboBox->blockSignals( b );
439+
mAnnotationDirectionComboBoxLeft->blockSignals( b );
440+
mAnnotationDirectionComboBoxRight->blockSignals( b );
441+
mAnnotationDirectionComboBoxTop->blockSignals( b );
442+
mAnnotationDirectionComboBoxBottom->blockSignals( b );
451443
mCoordinatePrecisionSpinBox->blockSignals( b );
452444
mDrawCanvasItemsCheckBox->blockSignals( b );
453445
}
@@ -683,49 +675,120 @@ void QgsComposerMapWidget::on_mDistanceToMapFrameSpinBox_valueChanged( double d
683675
mComposerMap->endCommand();
684676
}
685677

686-
void QgsComposerMapWidget::on_mAnnotationPositionComboBox_currentIndexChanged( const QString& text )
678+
void QgsComposerMapWidget::on_mAnnotationPositionLeftComboBox_currentIndexChanged( const QString& text )
679+
{
680+
handleChangedAnnotationPosition( QgsComposerMap::Left, text );
681+
}
682+
683+
void QgsComposerMapWidget::on_mAnnotationPositionRightComboBox_currentIndexChanged( const QString& text )
684+
{
685+
handleChangedAnnotationPosition( QgsComposerMap::Right, text );
686+
}
687+
688+
void QgsComposerMapWidget::on_mAnnotationPositionTopComboBox_currentIndexChanged( const QString& text )
689+
{
690+
handleChangedAnnotationPosition( QgsComposerMap::Top, text );
691+
}
692+
693+
void QgsComposerMapWidget::on_mAnnotationPositionBottomComboBox_currentIndexChanged( const QString& text )
694+
{
695+
handleChangedAnnotationPosition( QgsComposerMap::Bottom, text );
696+
}
697+
698+
void QgsComposerMapWidget::on_mDrawAnnotationCheckBox_stateChanged( int state )
687699
{
688700
if ( !mComposerMap )
689701
{
690702
return;
691703
}
692704

693-
mComposerMap->beginCommand( tr( "Annotation position changed" ) );
694-
if ( text == tr( "Inside frame" ) )
705+
mComposerMap->beginCommand( tr( "Annotation toggled" ) );
706+
if ( state == Qt::Checked )
695707
{
696-
mComposerMap->setGridAnnotationPosition( QgsComposerMap::InsideMapFrame );
708+
mComposerMap->setShowGridAnnotation( true );
697709
}
698710
else
699711
{
700-
mComposerMap->setGridAnnotationPosition( QgsComposerMap::OutsideMapFrame );
712+
mComposerMap->setShowGridAnnotation( false );
701713
}
702714
mComposerMap->updateBoundingRect();
703715
mComposerMap->update();
704716
mComposerMap->endCommand();
705717
}
706718

707-
void QgsComposerMapWidget::on_mDrawAnnotationCheckBox_stateChanged( int state )
719+
void QgsComposerMapWidget::on_mAnnotationDirectionComboBoxLeft_currentIndexChanged( const QString& text )
720+
{
721+
handleChangedAnnotationDirection( QgsComposerMap::Left, text );
722+
}
723+
724+
void QgsComposerMapWidget::on_mAnnotationDirectionComboBoxRight_currentIndexChanged( const QString& text )
725+
{
726+
handleChangedAnnotationDirection( QgsComposerMap::Right, text );
727+
}
728+
729+
void QgsComposerMapWidget::on_mAnnotationDirectionComboBoxTop_currentIndexChanged( const QString& text )
730+
{
731+
handleChangedAnnotationDirection( QgsComposerMap::Top, text );
732+
}
733+
734+
void QgsComposerMapWidget::on_mAnnotationDirectionComboBoxBottom_currentIndexChanged( const QString& text )
735+
{
736+
handleChangedAnnotationDirection( QgsComposerMap::Bottom, text );
737+
}
738+
739+
void QgsComposerMapWidget::on_mCoordinatePrecisionSpinBox_valueChanged( int value )
740+
{
741+
if ( !mComposerMap )
742+
{
743+
return;
744+
}
745+
mComposerMap->beginCommand( tr( "Changed annotation precision" ) );
746+
mComposerMap->setGridAnnotationPrecision( value );
747+
mComposerMap->updateBoundingRect();
748+
mComposerMap->update();
749+
mComposerMap->endCommand();
750+
}
751+
752+
void QgsComposerMapWidget::insertAnnotationPositionEntries( QComboBox* c )
753+
{
754+
c->insertItem( 0, tr( "Inside frame" ) );
755+
c->insertItem( 1, tr( "Outside frame" ) );
756+
c->insertItem( 2, tr( "Disabled" ) );
757+
}
758+
759+
void QgsComposerMapWidget::insertAnnotationDirectionEntries( QComboBox* c )
760+
{
761+
c->insertItem( 0, tr( "Horizontal" ) );
762+
c->insertItem( 1, tr( "Vertical" ) );
763+
}
764+
765+
void QgsComposerMapWidget::handleChangedAnnotationPosition( QgsComposerMap::Border border, const QString& text )
708766
{
709767
if ( !mComposerMap )
710768
{
711769
return;
712770
}
713771

714-
mComposerMap->beginCommand( tr( "Annotation toggled" ) );
715-
if ( state == Qt::Checked )
772+
mComposerMap->beginCommand( tr( "Annotation position changed" ) );
773+
if ( text == tr( "Inside frame" ) )
716774
{
717-
mComposerMap->setShowGridAnnotation( true );
775+
mComposerMap->setGridAnnotationPosition( QgsComposerMap::InsideMapFrame, border );
718776
}
719-
else
777+
else if ( text == tr( "Disabled" ) )
720778
{
721-
mComposerMap->setShowGridAnnotation( false );
779+
mComposerMap->setGridAnnotationPosition( QgsComposerMap::Disabled, border );
780+
}
781+
else //Outside frame
782+
{
783+
mComposerMap->setGridAnnotationPosition( QgsComposerMap::OutsideMapFrame, border );
722784
}
785+
723786
mComposerMap->updateBoundingRect();
724787
mComposerMap->update();
725788
mComposerMap->endCommand();
726789
}
727790

728-
void QgsComposerMapWidget::on_mAnnotationDirectionComboBox_currentIndexChanged( const QString& text )
791+
void QgsComposerMapWidget::handleChangedAnnotationDirection( QgsComposerMap::Border border, const QString& text )
729792
{
730793
if ( !mComposerMap )
731794
{
@@ -735,34 +798,51 @@ void QgsComposerMapWidget::on_mAnnotationDirectionComboBox_currentIndexChanged(
735798
mComposerMap->beginCommand( tr( "Changed annotation direction" ) );
736799
if ( text == tr( "Horizontal" ) )
737800
{
738-
mComposerMap->setGridAnnotationDirection( QgsComposerMap::Horizontal );
801+
mComposerMap->setGridAnnotationDirection( QgsComposerMap::Horizontal, border );
802+
}
803+
else //Vertical
804+
{
805+
mComposerMap->setGridAnnotationDirection( QgsComposerMap::Vertical, border );
739806
}
740-
else if ( text == tr( "Vertical" ) )
807+
mComposerMap->updateBoundingRect();
808+
mComposerMap->update();
809+
mComposerMap->endCommand();
810+
}
811+
812+
void QgsComposerMapWidget::initAnnotationPositionBox( QComboBox* c, QgsComposerMap::GridAnnotationPosition pos )
813+
{
814+
if ( !c )
741815
{
742-
mComposerMap->setGridAnnotationDirection( QgsComposerMap::Vertical );
816+
return;
743817
}
744-
else if ( text == tr( "Horizontal and Vertical" ) )
818+
819+
if ( pos == QgsComposerMap::InsideMapFrame )
745820
{
746-
mComposerMap->setGridAnnotationDirection( QgsComposerMap::HorizontalAndVertical );
821+
c->setCurrentIndex( c->findText( tr( "Inside frame" ) ) );
747822
}
748-
else //BoundaryDirection
823+
else if ( pos == QgsComposerMap::OutsideMapFrame )
749824
{
750-
mComposerMap->setGridAnnotationDirection( QgsComposerMap::BoundaryDirection );
825+
c->setCurrentIndex( c->findText( tr( "Outside frame" ) ) );
826+
}
827+
else //disabled
828+
{
829+
c->setCurrentIndex( c->findText( tr( "Disabled" ) ) );
751830
}
752-
mComposerMap->updateBoundingRect();
753-
mComposerMap->update();
754-
mComposerMap->endCommand();
755831
}
756832

757-
void QgsComposerMapWidget::on_mCoordinatePrecisionSpinBox_valueChanged( int value )
833+
void QgsComposerMapWidget::initAnnotationDirectionBox( QComboBox* c, QgsComposerMap::GridAnnotationDirection dir )
758834
{
759-
if ( !mComposerMap )
835+
if ( !c )
760836
{
761837
return;
762838
}
763-
mComposerMap->beginCommand( tr( "Changed annotation precision" ) );
764-
mComposerMap->setGridAnnotationPrecision( value );
765-
mComposerMap->updateBoundingRect();
766-
mComposerMap->update();
767-
mComposerMap->endCommand();
839+
840+
if ( dir == QgsComposerMap::Vertical )
841+
{
842+
c->setCurrentIndex( c->findText( tr( "Vertical" ) ) );
843+
}
844+
else //horizontal
845+
{
846+
c->setCurrentIndex( c->findText( tr( "Horizontal" ) ) );
847+
}
768848
}

‎src/app/composer/qgscomposermapwidget.h‎

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
#define QGSCOMPOSERMAPWIDGET_H
2020

2121
#include "ui_qgscomposermapwidgetbase.h"
22-
23-
class QgsComposerMap;
22+
#include "qgscomposermap.h"
2423

2524
/** \ingroup MapComposer
2625
* Input widget for the configuration of QgsComposerMap
@@ -61,9 +60,20 @@ class QgsComposerMapWidget: public QWidget, private Ui::QgsComposerMapWidgetBase
6160
void on_mCrossWidthSpinBox_valueChanged( double d );
6261
void on_mAnnotationFontButton_clicked();
6362
void on_mDistanceToMapFrameSpinBox_valueChanged( double d );
64-
void on_mAnnotationPositionComboBox_currentIndexChanged( const QString& text );
63+
64+
//annotation position
65+
void on_mAnnotationPositionLeftComboBox_currentIndexChanged( const QString& text );
66+
void on_mAnnotationPositionRightComboBox_currentIndexChanged( const QString& text );
67+
void on_mAnnotationPositionTopComboBox_currentIndexChanged( const QString& text );
68+
void on_mAnnotationPositionBottomComboBox_currentIndexChanged( const QString& text );
69+
70+
//annotation direction
71+
void on_mAnnotationDirectionComboBoxLeft_currentIndexChanged( const QString& text );
72+
void on_mAnnotationDirectionComboBoxRight_currentIndexChanged( const QString& text );
73+
void on_mAnnotationDirectionComboBoxTop_currentIndexChanged( const QString& text );
74+
void on_mAnnotationDirectionComboBoxBottom_currentIndexChanged( const QString& text );
75+
6576
void on_mDrawAnnotationCheckBox_stateChanged( int state );
66-
void on_mAnnotationDirectionComboBox_currentIndexChanged( const QString& text );
6777
void on_mCoordinatePrecisionSpinBox_valueChanged( int value );
6878

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

8393
/**Blocks / unblocks the signals of all GUI elements*/
8494
void blockAllSignals( bool b );
95+
96+
void handleChangedAnnotationPosition( QgsComposerMap::Border border, const QString& text );
97+
void handleChangedAnnotationDirection( QgsComposerMap::Border border, const QString& text );
98+
99+
void insertAnnotationPositionEntries( QComboBox* c );
100+
void insertAnnotationDirectionEntries( QComboBox* c );
101+
102+
void initAnnotationPositionBox( QComboBox* c, QgsComposerMap::GridAnnotationPosition pos );
103+
void initAnnotationDirectionBox( QComboBox* c, QgsComposerMap::GridAnnotationDirection dir );
85104
};
86105

87106
#endif

0 commit comments

Comments
 (0)