Skip to content

Commit

Permalink
[layouts] Don't show degrees based annotation formats as options
Browse files Browse the repository at this point in the history
for grids which are not latitude/longitude based

I.e. if the grid crs isn't geographic, then only show the decimal
formatting options. The degrees based formatting options will only
produce meaningless/confusing results in this situation!
  • Loading branch information
nyalldawson committed Nov 22, 2020
1 parent c9265b4 commit b6f3da3
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 10 deletions.
66 changes: 56 additions & 10 deletions src/gui/layout/qgslayoutmapgridwidget.cpp
Expand Up @@ -133,16 +133,6 @@ QgsLayoutMapGridWidget::QgsLayoutMapGridWidget( QgsLayoutItemMapGrid *mapGrid, Q
insertFrameDisplayEntries( mFrameDivisionsTopComboBox );
insertFrameDisplayEntries( mFrameDivisionsBottomComboBox );

mAnnotationFormatComboBox->addItem( tr( "Decimal" ), QgsLayoutItemMapGrid::Decimal );
mAnnotationFormatComboBox->addItem( tr( "Decimal with Suffix" ), QgsLayoutItemMapGrid::DecimalWithSuffix );
mAnnotationFormatComboBox->addItem( tr( "Degree, Minute" ), QgsLayoutItemMapGrid::DegreeMinuteNoSuffix );
mAnnotationFormatComboBox->addItem( tr( "Degree, Minute with Suffix" ), QgsLayoutItemMapGrid::DegreeMinute );
mAnnotationFormatComboBox->addItem( tr( "Degree, Minute Aligned" ), QgsLayoutItemMapGrid::DegreeMinutePadded );
mAnnotationFormatComboBox->addItem( tr( "Degree, Minute, Second" ), QgsLayoutItemMapGrid::DegreeMinuteSecondNoSuffix );
mAnnotationFormatComboBox->addItem( tr( "Degree, Minute, Second with Suffix" ), QgsLayoutItemMapGrid::DegreeMinuteSecond );
mAnnotationFormatComboBox->addItem( tr( "Degree, Minute, Second Aligned" ), QgsLayoutItemMapGrid::DegreeMinuteSecondPadded );
mAnnotationFormatComboBox->addItem( tr( "Custom" ), QgsLayoutItemMapGrid::CustomFormat );

insertAnnotationDisplayEntries( mAnnotationDisplayLeftComboBox );
insertAnnotationDisplayEntries( mAnnotationDisplayRightComboBox );
insertAnnotationDisplayEntries( mAnnotationDisplayTopComboBox );
Expand Down Expand Up @@ -201,6 +191,9 @@ QgsLayoutMapGridWidget::QgsLayoutMapGridWidget( QgsLayoutItemMapGrid *mapGrid, Q
registerDataDefinedButton( mFrameDivisionsTopDDBtn, QgsLayoutObject::MapGridFrameDivisionsTop );
registerDataDefinedButton( mFrameDivisionsBottomDDBtn, QgsLayoutObject::MapGridFrameDivisionsBottom );

// call to initially populate mAnnotationFormatComboBox
onCrsChanged();

updateGuiElements();

blockAllSignals( false );
Expand All @@ -220,6 +213,8 @@ QgsLayoutMapGridWidget::QgsLayoutMapGridWidget( QgsLayoutItemMapGrid *mapGrid, Q
}
mAnnotationFontButton->setLayer( coverageLayer() );
mAnnotationFontButton->registerExpressionContextGenerator( mMapGrid );

connect( mMapGrid, &QgsLayoutItemMapGrid::crsChanged, this, &QgsLayoutMapGridWidget::onCrsChanged );
}

void QgsLayoutMapGridWidget::populateDataDefinedButtons()
Expand Down Expand Up @@ -1079,6 +1074,55 @@ void QgsLayoutMapGridWidget::annotationTextFormatChanged()
mMap->update();
}

void QgsLayoutMapGridWidget::onCrsChanged()
{
mBlockAnnotationFormatUpdates++;
const QgsLayoutItemMapGrid::AnnotationFormat prevFormat = static_cast< QgsLayoutItemMapGrid::AnnotationFormat >( mAnnotationFormatComboBox->currentData().toInt() );

mAnnotationFormatComboBox->clear();
mAnnotationFormatComboBox->addItem( tr( "Decimal" ), QgsLayoutItemMapGrid::Decimal );
mAnnotationFormatComboBox->addItem( tr( "Decimal with Suffix" ), QgsLayoutItemMapGrid::DecimalWithSuffix );

// only show degree based options for geographic CRSes
const QgsCoordinateReferenceSystem crs = mMapGrid->crs().isValid() ? mMapGrid->crs() : mMap->crs();
switch ( crs.mapUnits() )
{
case QgsUnitTypes::DistanceMeters:
case QgsUnitTypes::DistanceKilometers:
case QgsUnitTypes::DistanceFeet:
case QgsUnitTypes::DistanceNauticalMiles:
case QgsUnitTypes::DistanceYards:
case QgsUnitTypes::DistanceMiles:
case QgsUnitTypes::DistanceCentimeters:
case QgsUnitTypes::DistanceMillimeters:
break;

case QgsUnitTypes::DistanceDegrees:
case QgsUnitTypes::DistanceUnknownUnit:
mAnnotationFormatComboBox->addItem( tr( "Degree, Minute" ), QgsLayoutItemMapGrid::DegreeMinuteNoSuffix );
mAnnotationFormatComboBox->addItem( tr( "Degree, Minute with Suffix" ), QgsLayoutItemMapGrid::DegreeMinute );
mAnnotationFormatComboBox->addItem( tr( "Degree, Minute Aligned" ), QgsLayoutItemMapGrid::DegreeMinutePadded );
mAnnotationFormatComboBox->addItem( tr( "Degree, Minute, Second" ), QgsLayoutItemMapGrid::DegreeMinuteSecondNoSuffix );
mAnnotationFormatComboBox->addItem( tr( "Degree, Minute, Second with Suffix" ), QgsLayoutItemMapGrid::DegreeMinuteSecond );
mAnnotationFormatComboBox->addItem( tr( "Degree, Minute, Second Aligned" ), QgsLayoutItemMapGrid::DegreeMinuteSecondPadded );
break;
}
mAnnotationFormatComboBox->addItem( tr( "Custom" ), QgsLayoutItemMapGrid::CustomFormat );

const int prevIndex = mAnnotationFormatComboBox->findData( prevFormat );
if ( prevIndex >= 0 )
mAnnotationFormatComboBox->setCurrentIndex( prevIndex );
else
mAnnotationFormatComboBox->setCurrentIndex( 0 );
mBlockAnnotationFormatUpdates--;

const QgsLayoutItemMapGrid::AnnotationFormat newFormat = static_cast< QgsLayoutItemMapGrid::AnnotationFormat >( mAnnotationFormatComboBox->currentData().toInt() );
if ( newFormat != prevFormat )
{
mAnnotationFormatComboBox_currentIndexChanged( mAnnotationFormatComboBox->currentIndex() );
}
}

void QgsLayoutMapGridWidget::mGridBlendComboBox_currentIndexChanged( int index )
{
Q_UNUSED( index )
Expand Down Expand Up @@ -1335,6 +1379,8 @@ void QgsLayoutMapGridWidget::mAnnotationFormatComboBox_currentIndexChanged( int
{
return;
}
if ( mBlockAnnotationFormatUpdates )
return;

mMap->beginCommand( tr( "Change Annotation Format" ) );

Expand Down
2 changes: 2 additions & 0 deletions src/gui/layout/qgslayoutmapgridwidget.h
Expand Up @@ -124,10 +124,12 @@ class GUI_EXPORT QgsLayoutMapGridWidget: public QgsLayoutItemBaseWidget, private
void minIntervalChanged( double interval );
void maxIntervalChanged( double interval );
void annotationTextFormatChanged();
void onCrsChanged();

private:
QPointer< QgsLayoutItemMap > mMap;
QPointer< QgsLayoutItemMapGrid > mMapGrid;
int mBlockAnnotationFormatUpdates = 0;

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

0 comments on commit b6f3da3

Please sign in to comment.