Skip to content

Commit ac9220d

Browse files
committedNov 4, 2014
[FEATURE][composer] Finer control of frame and annotation display
Previously, for rotated maps or reprojected grids, the composer would draw all coordinates for every map side. This resulted in a mix of latitude/y and longitude/x coordinates showing on a side. This change allows users to control whether they want all coordinates, latitude only or longitude only for each map frame side. Similar options have also been added for controlling how a map grid frame is divided. In related news... the composer map dialog is now the ugliest, most cluttered and un-user friendly dialog in all of QGIS. I'd love suggestions/mockups from the UX team for ways this could be improved.
1 parent 991f94d commit ac9220d

File tree

12 files changed

+732
-92
lines changed

12 files changed

+732
-92
lines changed
 

‎python/core/composer/qgscomposermapgrid.sip

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,25 @@ class QgsComposerMapGrid : QgsComposerMapItem
138138
Markers, /*< draw markers at intersections of grid lines */
139139
FrameAnnotationsOnly /*< no grid lines over the map, only draw frame and annotations */
140140
};
141+
142+
/** Display settings for grid annotations and frames
143+
*/
144+
enum DisplayMode
145+
{
146+
ShowAll = 0, /*< show both latitude and longitude annotations/divisions */
147+
LatitudeOnly, /*< show latitude/y annotations/divisions only */
148+
LongitudeOnly, /*< show longitude/x annotations/divisions only */
149+
HideAll /*< no annotations */
150+
};
141151

142152
/** Position for grid annotations
143153
*/
144154
enum AnnotationPosition
145155
{
146-
InsideMapFrame,
156+
InsideMapFrame = 0,
147157
OutsideMapFrame, /*< draw annotations outside the map frame */
148-
Disabled /*< disable annotation */
158+
Disabled /*< disable annotation
159+
* @deprecated in QGIS 2.7, use QgsComposerMapGrid::HideAll instead */
149160
};
150161

151162
/** Direction of grid annotations
@@ -488,6 +499,25 @@ class QgsComposerMapGrid : QgsComposerMapItem
488499
* @see setAnnotationPrecision
489500
*/
490501
int annotationPrecision() const;
502+
503+
/**Sets what types of grid annotations should be drawn for a specified side of the map frame,
504+
* or whether grid annotations should be disabled for the side.
505+
* @param display display mode for annotations
506+
* @param border side of map for annotations
507+
* @see annotationDisplay
508+
* @note added in QGIS 2.7
509+
*/
510+
void setAnnotationDisplay( const DisplayMode display, const BorderSide border );
511+
512+
/**Gets the display mode for the grid annotations on a specified side of the map
513+
* frame. This property also specifies whether annotations have been disabled
514+
* from a side of the map frame.
515+
* @param border side of map for annotations
516+
* @returns display mode for grid annotations
517+
* @see setAnnotationDisplay
518+
* @note added in QGIS 2.7
519+
*/
520+
DisplayMode annotationDisplay( const BorderSide border ) const;
491521

492522
/**Sets the position for the grid annotations on a specified side of the map
493523
* frame.
@@ -565,6 +595,22 @@ class QgsComposerMapGrid : QgsComposerMapItem
565595
*/
566596
FrameStyle frameStyle() const;
567597

598+
/**Sets what type of grid divisions should be used for frames on a specified side of the map.
599+
* @param divisions grid divisions for frame
600+
* @param border side of map for frame
601+
* @see frameDivisions
602+
* @note added in QGIS 2.7
603+
*/
604+
void setFrameDivisions( const DisplayMode divisions, const BorderSide border );
605+
606+
/**Gets the type of grid divisions which are used for frames on a specified side of the map.
607+
* @param border side of map for frame
608+
* @returns grid divisions for frame
609+
* @see setFrameDivisions
610+
* @note added in QGIS 2.7
611+
*/
612+
DisplayMode frameDivisions( const BorderSide border ) const;
613+
568614
/**Sets flags for grid frame sides. Setting these flags controls which sides
569615
* of the map item the grid frame is drawn on.
570616
* @param flags flags for grid frame sides

‎src/app/composer/qgscomposermapwidget.cpp

Lines changed: 174 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ QgsComposerMapWidget::QgsComposerMapWidget( QgsComposerMap* composerMap ): QgsCo
6969
mGridTypeComboBox->insertItem( 2, tr( "Markers" ) );
7070
mGridTypeComboBox->insertItem( 3, tr( "Frame and annotations only" ) );
7171

72+
insertFrameDisplayEntries( mFrameDivisionsLeftComboBox );
73+
insertFrameDisplayEntries( mFrameDivisionsRightComboBox );
74+
insertFrameDisplayEntries( mFrameDivisionsTopComboBox );
75+
insertFrameDisplayEntries( mFrameDivisionsBottomComboBox );
76+
7277
mAnnotationFormatComboBox->insertItem( 0, tr( "Decimal" ) );
7378
mAnnotationFormatComboBox->insertItem( 1, tr( "Decimal with suffix" ) );
7479
mAnnotationFormatComboBox->insertItem( 2, tr( "Degree, minute" ) );
@@ -78,11 +83,15 @@ QgsComposerMapWidget::QgsComposerMapWidget( QgsComposerMap* composerMap ): QgsCo
7883
mAnnotationFormatComboBox->insertItem( 6, tr( "Degree, minute, second with suffix" ) );
7984
mAnnotationFormatComboBox->insertItem( 7, tr( "Degree, minute, second aligned" ) );
8085

81-
8286
mAnnotationFontColorButton->setColorDialogTitle( tr( "Select font color" ) );
8387
mAnnotationFontColorButton->setAllowAlpha( true );
8488
mAnnotationFontColorButton->setContext( "composer" );
8589

90+
insertAnnotationDisplayEntries( mAnnotationDisplayLeftComboBox );
91+
insertAnnotationDisplayEntries( mAnnotationDisplayRightComboBox );
92+
insertAnnotationDisplayEntries( mAnnotationDisplayTopComboBox );
93+
insertAnnotationDisplayEntries( mAnnotationDisplayBottomComboBox );
94+
8695
insertAnnotationPositionEntries( mAnnotationPositionLeftComboBox );
8796
insertAnnotationPositionEntries( mAnnotationPositionRightComboBox );
8897
insertAnnotationPositionEntries( mAnnotationPositionTopComboBox );
@@ -757,6 +766,50 @@ void QgsComposerMapWidget::blockAllSignals( bool b )
757766
blockOverviewItemsSignals( b );
758767
}
759768

769+
void QgsComposerMapWidget::handleChangedFrameDisplay( QgsComposerMapGrid::BorderSide border, const QgsComposerMapGrid::DisplayMode mode )
770+
{
771+
QgsComposerMapGrid* grid = currentGrid();
772+
if ( !grid )
773+
{
774+
return;
775+
}
776+
777+
mComposerMap->beginCommand( tr( "Frame divisions changed" ) );
778+
grid->setFrameDivisions( mode, border );
779+
mComposerMap->endCommand();
780+
}
781+
782+
void QgsComposerMapWidget::handleChangedAnnotationDisplay( QgsComposerMapGrid::BorderSide border, const QString &text )
783+
{
784+
QgsComposerMapGrid* grid = currentGrid();
785+
if ( !grid )
786+
{
787+
return;
788+
}
789+
790+
mComposerMap->beginCommand( tr( "Annotation display changed" ) );
791+
if ( text == tr( "Show all" ) )
792+
{
793+
grid->setAnnotationDisplay( QgsComposerMapGrid::ShowAll, border );
794+
}
795+
else if ( text == tr( "Show latitude only" ) )
796+
{
797+
grid->setAnnotationDisplay( QgsComposerMapGrid::LatitudeOnly, border );
798+
}
799+
else if ( text == tr( "Show longitude only" ) )
800+
{
801+
grid->setAnnotationDisplay( QgsComposerMapGrid::LongitudeOnly, border );
802+
}
803+
else //disabled
804+
{
805+
grid->setAnnotationDisplay( QgsComposerMapGrid::HideAll, border );
806+
}
807+
808+
mComposerMap->updateBoundingRect();
809+
mComposerMap->update();
810+
mComposerMap->endCommand();
811+
}
812+
760813
void QgsComposerMapWidget::toggleFrameControls( bool frameEnabled, bool frameFillEnabled, bool frameSizeEnabled )
761814
{
762815
//set status of frame controls
@@ -772,6 +825,14 @@ void QgsComposerMapWidget::toggleFrameControls( bool frameEnabled, bool frameFil
772825
mCheckGridRightSide->setEnabled( frameEnabled );
773826
mCheckGridTopSide->setEnabled( frameEnabled );
774827
mCheckGridBottomSide->setEnabled( frameEnabled );
828+
mFrameDivisionsLeftComboBox->setEnabled( frameEnabled );
829+
mFrameDivisionsRightComboBox->setEnabled( frameEnabled );
830+
mFrameDivisionsTopComboBox->setEnabled( frameEnabled );
831+
mFrameDivisionsBottomComboBox->setEnabled( frameEnabled );
832+
mLeftDivisionsLabel->setEnabled( frameEnabled );
833+
mRightDivisionsLabel->setEnabled( frameEnabled );
834+
mTopDivisionsLabel->setEnabled( frameEnabled );
835+
mBottomDivisionsLabel->setEnabled( frameEnabled );
775836
}
776837

777838
void QgsComposerMapWidget::on_mUpdatePreviewButton_clicked()
@@ -849,7 +910,6 @@ void QgsComposerMapWidget::insertAnnotationPositionEntries( QComboBox* c )
849910
{
850911
c->insertItem( 0, tr( "Inside frame" ) );
851912
c->insertItem( 1, tr( "Outside frame" ) );
852-
c->insertItem( 2, tr( "Disabled" ) );
853913
}
854914

855915
void QgsComposerMapWidget::insertAnnotationDirectionEntries( QComboBox* c )
@@ -858,6 +918,40 @@ void QgsComposerMapWidget::insertAnnotationDirectionEntries( QComboBox* c )
858918
c->insertItem( 1, tr( "Vertical" ) );
859919
}
860920

921+
void QgsComposerMapWidget::initFrameDisplayBox( QComboBox *c, QgsComposerMapGrid::DisplayMode display )
922+
{
923+
if ( !c )
924+
{
925+
return;
926+
}
927+
c->setCurrentIndex( c->findData( display ) );
928+
}
929+
930+
void QgsComposerMapWidget::initAnnotationDisplayBox( QComboBox *c, QgsComposerMapGrid::DisplayMode display )
931+
{
932+
if ( !c )
933+
{
934+
return;
935+
}
936+
937+
if ( display == QgsComposerMapGrid::ShowAll )
938+
{
939+
c->setCurrentIndex( c->findText( tr( "Show all" ) ) );
940+
}
941+
else if ( display == QgsComposerMapGrid::LatitudeOnly )
942+
{
943+
c->setCurrentIndex( c->findText( tr( "Show latitude only" ) ) );
944+
}
945+
else if ( display == QgsComposerMapGrid::LongitudeOnly )
946+
{
947+
c->setCurrentIndex( c->findText( tr( "Show longitude only" ) ) );
948+
}
949+
else
950+
{
951+
c->setCurrentIndex( c->findText( tr( "Disabled" ) ) );
952+
}
953+
}
954+
861955
void QgsComposerMapWidget::handleChangedAnnotationPosition( QgsComposerMapGrid::BorderSide border, const QString& text )
862956
{
863957
QgsComposerMapGrid* grid = currentGrid();
@@ -907,6 +1001,21 @@ void QgsComposerMapWidget::handleChangedAnnotationDirection( QgsComposerMapGrid:
9071001
mComposerMap->endCommand();
9081002
}
9091003

1004+
void QgsComposerMapWidget::insertFrameDisplayEntries( QComboBox *c )
1005+
{
1006+
c->addItem( tr( "All" ), QgsComposerMapGrid::ShowAll );
1007+
c->addItem( tr( "Latitude/Y only" ), QgsComposerMapGrid::LatitudeOnly );
1008+
c->addItem( tr( "Longitude/X only" ), QgsComposerMapGrid::LongitudeOnly );
1009+
}
1010+
1011+
void QgsComposerMapWidget::insertAnnotationDisplayEntries( QComboBox *c )
1012+
{
1013+
c->insertItem( 0, tr( "Show all" ) );
1014+
c->insertItem( 1, tr( "Show latitude only" ) );
1015+
c->insertItem( 2, tr( "Show longitude only" ) );
1016+
c->insertItem( 3, tr( "Disabled" ) );
1017+
}
1018+
9101019
void QgsComposerMapWidget::initAnnotationPositionBox( QComboBox* c, QgsComposerMapGrid::AnnotationPosition pos )
9111020
{
9121021
if ( !c )
@@ -918,14 +1027,10 @@ void QgsComposerMapWidget::initAnnotationPositionBox( QComboBox* c, QgsComposerM
9181027
{
9191028
c->setCurrentIndex( c->findText( tr( "Inside frame" ) ) );
9201029
}
921-
else if ( pos == QgsComposerMapGrid::OutsideMapFrame )
1030+
else
9221031
{
9231032
c->setCurrentIndex( c->findText( tr( "Outside frame" ) ) );
9241033
}
925-
else //disabled
926-
{
927-
c->setCurrentIndex( c->findText( tr( "Disabled" ) ) );
928-
}
9291034
}
9301035

9311036
void QgsComposerMapWidget::initAnnotationDirectionBox( QComboBox* c, QgsComposerMapGrid::AnnotationDirection dir )
@@ -1160,6 +1265,10 @@ void QgsComposerMapWidget::setGridItemsEnabled( bool enabled )
11601265
mGridFramePenColorButton->setEnabled( enabled );
11611266
mGridFrameFill1ColorButton->setEnabled( enabled );
11621267
mGridFrameFill2ColorButton->setEnabled( enabled );
1268+
mFrameDivisionsLeftComboBox->setEnabled( enabled );
1269+
mFrameDivisionsRightComboBox->setEnabled( enabled );
1270+
mFrameDivisionsTopComboBox->setEnabled( enabled );
1271+
mFrameDivisionsBottomComboBox->setEnabled( enabled );
11631272
}
11641273

11651274
void QgsComposerMapWidget::blockGridItemsSignals( bool block )
@@ -1185,16 +1294,24 @@ void QgsComposerMapWidget::blockGridItemsSignals( bool block )
11851294
mCheckGridRightSide->blockSignals( block );
11861295
mCheckGridTopSide->blockSignals( block );
11871296
mCheckGridBottomSide->blockSignals( block );
1297+
mFrameDivisionsLeftComboBox->blockSignals( block );
1298+
mFrameDivisionsRightComboBox->blockSignals( block );
1299+
mFrameDivisionsTopComboBox->blockSignals( block );
1300+
mFrameDivisionsBottomComboBox->blockSignals( block );
11881301

11891302
//grid annotation
11901303
mDrawAnnotationGroupBox->blockSignals( block );
11911304
mAnnotationFormatComboBox->blockSignals( block );
1305+
mAnnotationDisplayLeftComboBox->blockSignals( block );
11921306
mAnnotationPositionLeftComboBox->blockSignals( block );
11931307
mAnnotationDirectionComboBoxLeft->blockSignals( block );
1308+
mAnnotationDisplayRightComboBox->blockSignals( block );
11941309
mAnnotationPositionRightComboBox->blockSignals( block );
11951310
mAnnotationDirectionComboBoxRight->blockSignals( block );
1311+
mAnnotationDisplayTopComboBox->blockSignals( block );
11961312
mAnnotationPositionTopComboBox->blockSignals( block );
11971313
mAnnotationDirectionComboBoxTop->blockSignals( block );
1314+
mAnnotationDisplayBottomComboBox->blockSignals( block );
11981315
mAnnotationPositionBottomComboBox->blockSignals( block );
11991316
mAnnotationDirectionComboBoxBottom->blockSignals( block );
12001317
mDistanceToMapFrameSpinBox->blockSignals( block );
@@ -1310,6 +1427,11 @@ void QgsComposerMapWidget::setGridItems( const QgsComposerMapGrid* grid )
13101427
mCheckGridTopSide->setChecked( grid->testFrameSideFlag( QgsComposerMapGrid::FrameTop ) );
13111428
mCheckGridBottomSide->setChecked( grid->testFrameSideFlag( QgsComposerMapGrid::FrameBottom ) );
13121429

1430+
initFrameDisplayBox( mFrameDivisionsLeftComboBox, grid->frameDivisions( QgsComposerMapGrid::Left ) );
1431+
initFrameDisplayBox( mFrameDivisionsRightComboBox, grid->frameDivisions( QgsComposerMapGrid::Right ) );
1432+
initFrameDisplayBox( mFrameDivisionsTopComboBox, grid->frameDivisions( QgsComposerMapGrid::Top ) );
1433+
initFrameDisplayBox( mFrameDivisionsBottomComboBox, grid->frameDivisions( QgsComposerMapGrid::Bottom ) );
1434+
13131435
//line style
13141436
updateGridLineSymbolMarker( grid );
13151437
//marker style
@@ -1318,6 +1440,11 @@ void QgsComposerMapWidget::setGridItems( const QgsComposerMapGrid* grid )
13181440
mGridBlendComboBox->setBlendMode( grid->blendMode() );
13191441

13201442
mDrawAnnotationGroupBox->setChecked( grid->annotationEnabled() );
1443+
initAnnotationDisplayBox( mAnnotationDisplayLeftComboBox, grid->annotationDisplay( QgsComposerMapGrid::Left ) );
1444+
initAnnotationDisplayBox( mAnnotationDisplayRightComboBox, grid->annotationDisplay( QgsComposerMapGrid::Right ) );
1445+
initAnnotationDisplayBox( mAnnotationDisplayTopComboBox, grid->annotationDisplay( QgsComposerMapGrid::Top ) );
1446+
initAnnotationDisplayBox( mAnnotationDisplayBottomComboBox, grid->annotationDisplay( QgsComposerMapGrid::Bottom ) );
1447+
13211448
initAnnotationPositionBox( mAnnotationPositionLeftComboBox, grid->annotationPosition( QgsComposerMapGrid::Left ) );
13221449
initAnnotationPositionBox( mAnnotationPositionRightComboBox, grid->annotationPosition( QgsComposerMapGrid::Right ) );
13231450
initAnnotationPositionBox( mAnnotationPositionTopComboBox, grid->annotationPosition( QgsComposerMapGrid::Top ) );
@@ -1598,6 +1725,26 @@ void QgsComposerMapWidget::on_mCheckGridBottomSide_toggled( bool checked )
15981725
mComposerMap->endCommand();
15991726
}
16001727

1728+
void QgsComposerMapWidget::on_mFrameDivisionsLeftComboBox_currentIndexChanged( int index )
1729+
{
1730+
handleChangedFrameDisplay( QgsComposerMapGrid::Left, ( QgsComposerMapGrid::DisplayMode ) mFrameDivisionsLeftComboBox->itemData( index ).toInt() );
1731+
}
1732+
1733+
void QgsComposerMapWidget::on_mFrameDivisionsRightComboBox_currentIndexChanged( int index )
1734+
{
1735+
handleChangedFrameDisplay( QgsComposerMapGrid::Right, ( QgsComposerMapGrid::DisplayMode ) mFrameDivisionsRightComboBox->itemData( index ).toInt() );
1736+
}
1737+
1738+
void QgsComposerMapWidget::on_mFrameDivisionsTopComboBox_currentIndexChanged( int index )
1739+
{
1740+
handleChangedFrameDisplay( QgsComposerMapGrid::Top, ( QgsComposerMapGrid::DisplayMode ) mFrameDivisionsTopComboBox->itemData( index ).toInt() );
1741+
}
1742+
1743+
void QgsComposerMapWidget::on_mFrameDivisionsBottomComboBox_currentIndexChanged( int index )
1744+
{
1745+
handleChangedFrameDisplay( QgsComposerMapGrid::Bottom, ( QgsComposerMapGrid::DisplayMode ) mFrameDivisionsBottomComboBox->itemData( index ).toInt() );
1746+
}
1747+
16011748
void QgsComposerMapWidget::on_mGridFramePenSizeSpinBox_valueChanged( double d )
16021749
{
16031750
QgsComposerMapGrid* grid = currentGrid();
@@ -1839,6 +1986,26 @@ void QgsComposerMapWidget::on_mDrawAnnotationGroupBox_toggled( bool state )
18391986
mComposerMap->endCommand();
18401987
}
18411988

1989+
void QgsComposerMapWidget::on_mAnnotationDisplayLeftComboBox_currentIndexChanged( const QString &text )
1990+
{
1991+
handleChangedAnnotationDisplay( QgsComposerMapGrid::Left, text );
1992+
}
1993+
1994+
void QgsComposerMapWidget::on_mAnnotationDisplayRightComboBox_currentIndexChanged( const QString &text )
1995+
{
1996+
handleChangedAnnotationDisplay( QgsComposerMapGrid::Right, text );
1997+
}
1998+
1999+
void QgsComposerMapWidget::on_mAnnotationDisplayTopComboBox_currentIndexChanged( const QString &text )
2000+
{
2001+
handleChangedAnnotationDisplay( QgsComposerMapGrid::Top, text );
2002+
}
2003+
2004+
void QgsComposerMapWidget::on_mAnnotationDisplayBottomComboBox_currentIndexChanged( const QString &text )
2005+
{
2006+
handleChangedAnnotationDisplay( QgsComposerMapGrid::Bottom, text );
2007+
}
2008+
18422009
void QgsComposerMapWidget::on_mAnnotationPositionLeftComboBox_currentIndexChanged( const QString& text )
18432010
{
18442011
handleChangedAnnotationPosition( QgsComposerMapGrid::Left, text );

0 commit comments

Comments
 (0)
Please sign in to comment.