Skip to content

Commit

Permalink
[FEATURE][composer] Finer control of frame and annotation display
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nyalldawson committed Nov 4, 2014
1 parent 991f94d commit ac9220d
Show file tree
Hide file tree
Showing 12 changed files with 732 additions and 92 deletions.
50 changes: 48 additions & 2 deletions python/core/composer/qgscomposermapgrid.sip
Expand Up @@ -138,14 +138,25 @@ class QgsComposerMapGrid : QgsComposerMapItem
Markers, /*< draw markers at intersections of grid lines */
FrameAnnotationsOnly /*< no grid lines over the map, only draw frame and annotations */
};

/** Display settings for grid annotations and frames
*/
enum DisplayMode
{
ShowAll = 0, /*< show both latitude and longitude annotations/divisions */
LatitudeOnly, /*< show latitude/y annotations/divisions only */
LongitudeOnly, /*< show longitude/x annotations/divisions only */
HideAll /*< no annotations */
};

/** Position for grid annotations
*/
enum AnnotationPosition
{
InsideMapFrame,
InsideMapFrame = 0,
OutsideMapFrame, /*< draw annotations outside the map frame */
Disabled /*< disable annotation */
Disabled /*< disable annotation
* @deprecated in QGIS 2.7, use QgsComposerMapGrid::HideAll instead */
};

/** Direction of grid annotations
Expand Down Expand Up @@ -488,6 +499,25 @@ class QgsComposerMapGrid : QgsComposerMapItem
* @see setAnnotationPrecision
*/
int annotationPrecision() const;

/**Sets what types of grid annotations should be drawn for a specified side of the map frame,
* or whether grid annotations should be disabled for the side.
* @param display display mode for annotations
* @param border side of map for annotations
* @see annotationDisplay
* @note added in QGIS 2.7
*/
void setAnnotationDisplay( const DisplayMode display, const BorderSide border );

/**Gets the display mode for the grid annotations on a specified side of the map
* frame. This property also specifies whether annotations have been disabled
* from a side of the map frame.
* @param border side of map for annotations
* @returns display mode for grid annotations
* @see setAnnotationDisplay
* @note added in QGIS 2.7
*/
DisplayMode annotationDisplay( const BorderSide border ) const;

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

/**Sets what type of grid divisions should be used for frames on a specified side of the map.
* @param divisions grid divisions for frame
* @param border side of map for frame
* @see frameDivisions
* @note added in QGIS 2.7
*/
void setFrameDivisions( const DisplayMode divisions, const BorderSide border );

/**Gets the type of grid divisions which are used for frames on a specified side of the map.
* @param border side of map for frame
* @returns grid divisions for frame
* @see setFrameDivisions
* @note added in QGIS 2.7
*/
DisplayMode frameDivisions( const BorderSide border ) const;

/**Sets flags for grid frame sides. Setting these flags controls which sides
* of the map item the grid frame is drawn on.
* @param flags flags for grid frame sides
Expand Down
181 changes: 174 additions & 7 deletions src/app/composer/qgscomposermapwidget.cpp
Expand Up @@ -69,6 +69,11 @@ QgsComposerMapWidget::QgsComposerMapWidget( QgsComposerMap* composerMap ): QgsCo
mGridTypeComboBox->insertItem( 2, tr( "Markers" ) );
mGridTypeComboBox->insertItem( 3, tr( "Frame and annotations only" ) );

insertFrameDisplayEntries( mFrameDivisionsLeftComboBox );
insertFrameDisplayEntries( mFrameDivisionsRightComboBox );
insertFrameDisplayEntries( mFrameDivisionsTopComboBox );
insertFrameDisplayEntries( mFrameDivisionsBottomComboBox );

mAnnotationFormatComboBox->insertItem( 0, tr( "Decimal" ) );
mAnnotationFormatComboBox->insertItem( 1, tr( "Decimal with suffix" ) );
mAnnotationFormatComboBox->insertItem( 2, tr( "Degree, minute" ) );
Expand All @@ -78,11 +83,15 @@ QgsComposerMapWidget::QgsComposerMapWidget( QgsComposerMap* composerMap ): QgsCo
mAnnotationFormatComboBox->insertItem( 6, tr( "Degree, minute, second with suffix" ) );
mAnnotationFormatComboBox->insertItem( 7, tr( "Degree, minute, second aligned" ) );


mAnnotationFontColorButton->setColorDialogTitle( tr( "Select font color" ) );
mAnnotationFontColorButton->setAllowAlpha( true );
mAnnotationFontColorButton->setContext( "composer" );

insertAnnotationDisplayEntries( mAnnotationDisplayLeftComboBox );
insertAnnotationDisplayEntries( mAnnotationDisplayRightComboBox );
insertAnnotationDisplayEntries( mAnnotationDisplayTopComboBox );
insertAnnotationDisplayEntries( mAnnotationDisplayBottomComboBox );

insertAnnotationPositionEntries( mAnnotationPositionLeftComboBox );
insertAnnotationPositionEntries( mAnnotationPositionRightComboBox );
insertAnnotationPositionEntries( mAnnotationPositionTopComboBox );
Expand Down Expand Up @@ -757,6 +766,50 @@ void QgsComposerMapWidget::blockAllSignals( bool b )
blockOverviewItemsSignals( b );
}

void QgsComposerMapWidget::handleChangedFrameDisplay( QgsComposerMapGrid::BorderSide border, const QgsComposerMapGrid::DisplayMode mode )
{
QgsComposerMapGrid* grid = currentGrid();
if ( !grid )
{
return;
}

mComposerMap->beginCommand( tr( "Frame divisions changed" ) );
grid->setFrameDivisions( mode, border );
mComposerMap->endCommand();
}

void QgsComposerMapWidget::handleChangedAnnotationDisplay( QgsComposerMapGrid::BorderSide border, const QString &text )
{
QgsComposerMapGrid* grid = currentGrid();
if ( !grid )
{
return;
}

mComposerMap->beginCommand( tr( "Annotation display changed" ) );
if ( text == tr( "Show all" ) )
{
grid->setAnnotationDisplay( QgsComposerMapGrid::ShowAll, border );
}
else if ( text == tr( "Show latitude only" ) )
{
grid->setAnnotationDisplay( QgsComposerMapGrid::LatitudeOnly, border );
}
else if ( text == tr( "Show longitude only" ) )
{
grid->setAnnotationDisplay( QgsComposerMapGrid::LongitudeOnly, border );
}
else //disabled
{
grid->setAnnotationDisplay( QgsComposerMapGrid::HideAll, border );
}

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

void QgsComposerMapWidget::toggleFrameControls( bool frameEnabled, bool frameFillEnabled, bool frameSizeEnabled )
{
//set status of frame controls
Expand All @@ -772,6 +825,14 @@ void QgsComposerMapWidget::toggleFrameControls( bool frameEnabled, bool frameFil
mCheckGridRightSide->setEnabled( frameEnabled );
mCheckGridTopSide->setEnabled( frameEnabled );
mCheckGridBottomSide->setEnabled( frameEnabled );
mFrameDivisionsLeftComboBox->setEnabled( frameEnabled );
mFrameDivisionsRightComboBox->setEnabled( frameEnabled );
mFrameDivisionsTopComboBox->setEnabled( frameEnabled );
mFrameDivisionsBottomComboBox->setEnabled( frameEnabled );
mLeftDivisionsLabel->setEnabled( frameEnabled );
mRightDivisionsLabel->setEnabled( frameEnabled );
mTopDivisionsLabel->setEnabled( frameEnabled );
mBottomDivisionsLabel->setEnabled( frameEnabled );
}

void QgsComposerMapWidget::on_mUpdatePreviewButton_clicked()
Expand Down Expand Up @@ -849,7 +910,6 @@ 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 )
Expand All @@ -858,6 +918,40 @@ void QgsComposerMapWidget::insertAnnotationDirectionEntries( QComboBox* c )
c->insertItem( 1, tr( "Vertical" ) );
}

void QgsComposerMapWidget::initFrameDisplayBox( QComboBox *c, QgsComposerMapGrid::DisplayMode display )
{
if ( !c )
{
return;
}
c->setCurrentIndex( c->findData( display ) );
}

void QgsComposerMapWidget::initAnnotationDisplayBox( QComboBox *c, QgsComposerMapGrid::DisplayMode display )
{
if ( !c )
{
return;
}

if ( display == QgsComposerMapGrid::ShowAll )
{
c->setCurrentIndex( c->findText( tr( "Show all" ) ) );
}
else if ( display == QgsComposerMapGrid::LatitudeOnly )
{
c->setCurrentIndex( c->findText( tr( "Show latitude only" ) ) );
}
else if ( display == QgsComposerMapGrid::LongitudeOnly )
{
c->setCurrentIndex( c->findText( tr( "Show longitude only" ) ) );
}
else
{
c->setCurrentIndex( c->findText( tr( "Disabled" ) ) );
}
}

void QgsComposerMapWidget::handleChangedAnnotationPosition( QgsComposerMapGrid::BorderSide border, const QString& text )
{
QgsComposerMapGrid* grid = currentGrid();
Expand Down Expand Up @@ -907,6 +1001,21 @@ void QgsComposerMapWidget::handleChangedAnnotationDirection( QgsComposerMapGrid:
mComposerMap->endCommand();
}

void QgsComposerMapWidget::insertFrameDisplayEntries( QComboBox *c )
{
c->addItem( tr( "All" ), QgsComposerMapGrid::ShowAll );
c->addItem( tr( "Latitude/Y only" ), QgsComposerMapGrid::LatitudeOnly );
c->addItem( tr( "Longitude/X only" ), QgsComposerMapGrid::LongitudeOnly );
}

void QgsComposerMapWidget::insertAnnotationDisplayEntries( QComboBox *c )
{
c->insertItem( 0, tr( "Show all" ) );
c->insertItem( 1, tr( "Show latitude only" ) );
c->insertItem( 2, tr( "Show longitude only" ) );
c->insertItem( 3, tr( "Disabled" ) );
}

void QgsComposerMapWidget::initAnnotationPositionBox( QComboBox* c, QgsComposerMapGrid::AnnotationPosition pos )
{
if ( !c )
Expand All @@ -918,14 +1027,10 @@ void QgsComposerMapWidget::initAnnotationPositionBox( QComboBox* c, QgsComposerM
{
c->setCurrentIndex( c->findText( tr( "Inside frame" ) ) );
}
else if ( pos == QgsComposerMapGrid::OutsideMapFrame )
else
{
c->setCurrentIndex( c->findText( tr( "Outside frame" ) ) );
}
else //disabled
{
c->setCurrentIndex( c->findText( tr( "Disabled" ) ) );
}
}

void QgsComposerMapWidget::initAnnotationDirectionBox( QComboBox* c, QgsComposerMapGrid::AnnotationDirection dir )
Expand Down Expand Up @@ -1160,6 +1265,10 @@ void QgsComposerMapWidget::setGridItemsEnabled( bool enabled )
mGridFramePenColorButton->setEnabled( enabled );
mGridFrameFill1ColorButton->setEnabled( enabled );
mGridFrameFill2ColorButton->setEnabled( enabled );
mFrameDivisionsLeftComboBox->setEnabled( enabled );
mFrameDivisionsRightComboBox->setEnabled( enabled );
mFrameDivisionsTopComboBox->setEnabled( enabled );
mFrameDivisionsBottomComboBox->setEnabled( enabled );
}

void QgsComposerMapWidget::blockGridItemsSignals( bool block )
Expand All @@ -1185,16 +1294,24 @@ void QgsComposerMapWidget::blockGridItemsSignals( bool block )
mCheckGridRightSide->blockSignals( block );
mCheckGridTopSide->blockSignals( block );
mCheckGridBottomSide->blockSignals( block );
mFrameDivisionsLeftComboBox->blockSignals( block );
mFrameDivisionsRightComboBox->blockSignals( block );
mFrameDivisionsTopComboBox->blockSignals( block );
mFrameDivisionsBottomComboBox->blockSignals( block );

//grid annotation
mDrawAnnotationGroupBox->blockSignals( block );
mAnnotationFormatComboBox->blockSignals( block );
mAnnotationDisplayLeftComboBox->blockSignals( block );
mAnnotationPositionLeftComboBox->blockSignals( block );
mAnnotationDirectionComboBoxLeft->blockSignals( block );
mAnnotationDisplayRightComboBox->blockSignals( block );
mAnnotationPositionRightComboBox->blockSignals( block );
mAnnotationDirectionComboBoxRight->blockSignals( block );
mAnnotationDisplayTopComboBox->blockSignals( block );
mAnnotationPositionTopComboBox->blockSignals( block );
mAnnotationDirectionComboBoxTop->blockSignals( block );
mAnnotationDisplayBottomComboBox->blockSignals( block );
mAnnotationPositionBottomComboBox->blockSignals( block );
mAnnotationDirectionComboBoxBottom->blockSignals( block );
mDistanceToMapFrameSpinBox->blockSignals( block );
Expand Down Expand Up @@ -1310,6 +1427,11 @@ void QgsComposerMapWidget::setGridItems( const QgsComposerMapGrid* grid )
mCheckGridTopSide->setChecked( grid->testFrameSideFlag( QgsComposerMapGrid::FrameTop ) );
mCheckGridBottomSide->setChecked( grid->testFrameSideFlag( QgsComposerMapGrid::FrameBottom ) );

initFrameDisplayBox( mFrameDivisionsLeftComboBox, grid->frameDivisions( QgsComposerMapGrid::Left ) );
initFrameDisplayBox( mFrameDivisionsRightComboBox, grid->frameDivisions( QgsComposerMapGrid::Right ) );
initFrameDisplayBox( mFrameDivisionsTopComboBox, grid->frameDivisions( QgsComposerMapGrid::Top ) );
initFrameDisplayBox( mFrameDivisionsBottomComboBox, grid->frameDivisions( QgsComposerMapGrid::Bottom ) );

//line style
updateGridLineSymbolMarker( grid );
//marker style
Expand All @@ -1318,6 +1440,11 @@ void QgsComposerMapWidget::setGridItems( const QgsComposerMapGrid* grid )
mGridBlendComboBox->setBlendMode( grid->blendMode() );

mDrawAnnotationGroupBox->setChecked( grid->annotationEnabled() );
initAnnotationDisplayBox( mAnnotationDisplayLeftComboBox, grid->annotationDisplay( QgsComposerMapGrid::Left ) );
initAnnotationDisplayBox( mAnnotationDisplayRightComboBox, grid->annotationDisplay( QgsComposerMapGrid::Right ) );
initAnnotationDisplayBox( mAnnotationDisplayTopComboBox, grid->annotationDisplay( QgsComposerMapGrid::Top ) );
initAnnotationDisplayBox( mAnnotationDisplayBottomComboBox, grid->annotationDisplay( QgsComposerMapGrid::Bottom ) );

initAnnotationPositionBox( mAnnotationPositionLeftComboBox, grid->annotationPosition( QgsComposerMapGrid::Left ) );
initAnnotationPositionBox( mAnnotationPositionRightComboBox, grid->annotationPosition( QgsComposerMapGrid::Right ) );
initAnnotationPositionBox( mAnnotationPositionTopComboBox, grid->annotationPosition( QgsComposerMapGrid::Top ) );
Expand Down Expand Up @@ -1598,6 +1725,26 @@ void QgsComposerMapWidget::on_mCheckGridBottomSide_toggled( bool checked )
mComposerMap->endCommand();
}

void QgsComposerMapWidget::on_mFrameDivisionsLeftComboBox_currentIndexChanged( int index )
{
handleChangedFrameDisplay( QgsComposerMapGrid::Left, ( QgsComposerMapGrid::DisplayMode ) mFrameDivisionsLeftComboBox->itemData( index ).toInt() );
}

void QgsComposerMapWidget::on_mFrameDivisionsRightComboBox_currentIndexChanged( int index )
{
handleChangedFrameDisplay( QgsComposerMapGrid::Right, ( QgsComposerMapGrid::DisplayMode ) mFrameDivisionsRightComboBox->itemData( index ).toInt() );
}

void QgsComposerMapWidget::on_mFrameDivisionsTopComboBox_currentIndexChanged( int index )
{
handleChangedFrameDisplay( QgsComposerMapGrid::Top, ( QgsComposerMapGrid::DisplayMode ) mFrameDivisionsTopComboBox->itemData( index ).toInt() );
}

void QgsComposerMapWidget::on_mFrameDivisionsBottomComboBox_currentIndexChanged( int index )
{
handleChangedFrameDisplay( QgsComposerMapGrid::Bottom, ( QgsComposerMapGrid::DisplayMode ) mFrameDivisionsBottomComboBox->itemData( index ).toInt() );
}

void QgsComposerMapWidget::on_mGridFramePenSizeSpinBox_valueChanged( double d )
{
QgsComposerMapGrid* grid = currentGrid();
Expand Down Expand Up @@ -1839,6 +1986,26 @@ void QgsComposerMapWidget::on_mDrawAnnotationGroupBox_toggled( bool state )
mComposerMap->endCommand();
}

void QgsComposerMapWidget::on_mAnnotationDisplayLeftComboBox_currentIndexChanged( const QString &text )
{
handleChangedAnnotationDisplay( QgsComposerMapGrid::Left, text );
}

void QgsComposerMapWidget::on_mAnnotationDisplayRightComboBox_currentIndexChanged( const QString &text )
{
handleChangedAnnotationDisplay( QgsComposerMapGrid::Right, text );
}

void QgsComposerMapWidget::on_mAnnotationDisplayTopComboBox_currentIndexChanged( const QString &text )
{
handleChangedAnnotationDisplay( QgsComposerMapGrid::Top, text );
}

void QgsComposerMapWidget::on_mAnnotationDisplayBottomComboBox_currentIndexChanged( const QString &text )
{
handleChangedAnnotationDisplay( QgsComposerMapGrid::Bottom, text );
}

void QgsComposerMapWidget::on_mAnnotationPositionLeftComboBox_currentIndexChanged( const QString& text )
{
handleChangedAnnotationPosition( QgsComposerMapGrid::Left, text );
Expand Down

0 comments on commit ac9220d

Please sign in to comment.