Skip to content

Commit

Permalink
[layouts] Add more unit choices to scalebars
Browse files Browse the repository at this point in the history
Explicitly add options for kilometers, miles, etc as the current
UX for setting these is too confusing!

Fixes #16921
  • Loading branch information
nyalldawson committed Nov 24, 2017
1 parent 3c4fae0 commit af59c53
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 42 deletions.
45 changes: 10 additions & 35 deletions src/app/layout/qgslayoutscalebarwidget.cpp
Expand Up @@ -78,10 +78,13 @@ QgsLayoutScaleBarWidget::QgsLayoutScaleBarWidget( QgsLayoutItemScaleBar *scaleBa
mAlignmentComboBox->insertItem( 2, tr( "Right" ) );

//units combo box
mUnitsComboBox->insertItem( 0, tr( "Map units" ), QgsUnitTypes::DistanceUnknownUnit );
mUnitsComboBox->insertItem( 1, tr( "Meters" ), QgsUnitTypes::DistanceMeters );
mUnitsComboBox->insertItem( 2, tr( "Feet" ), QgsUnitTypes::DistanceFeet );
mUnitsComboBox->insertItem( 3, tr( "Nautical Miles" ), QgsUnitTypes::DistanceNauticalMiles );
mUnitsComboBox->addItem( tr( "Map units" ), QgsUnitTypes::DistanceUnknownUnit );
mUnitsComboBox->addItem( tr( "Meters" ), QgsUnitTypes::DistanceMeters );
mUnitsComboBox->addItem( tr( "Kilometers" ), QgsUnitTypes::DistanceKilometers );
mUnitsComboBox->addItem( tr( "Feet" ), QgsUnitTypes::DistanceFeet );
mUnitsComboBox->addItem( tr( "Yards" ), QgsUnitTypes::DistanceYards );
mUnitsComboBox->addItem( tr( "Miles" ), QgsUnitTypes::DistanceMiles );
mUnitsComboBox->addItem( tr( "Nautical Miles" ), QgsUnitTypes::DistanceNauticalMiles );

mFillColorButton->setColorDialogTitle( tr( "Select Fill Color" ) );
mFillColorButton->setAllowOpacity( true );
Expand Down Expand Up @@ -193,7 +196,7 @@ void QgsLayoutScaleBarWidget::setGuiElements()
mAlignmentComboBox->setCurrentIndex( ( int )( mScalebar->alignment() ) );

//units
mUnitsComboBox->setCurrentIndex( mUnitsComboBox->findData( ( int )mScalebar->units() ) );
mUnitsComboBox->setCurrentIndex( mUnitsComboBox->findData( static_cast< int >( mScalebar->units() ) ) );

if ( mScalebar->segmentSizeMode() == QgsScaleBarSettings::SegmentSizeFixed )
{
Expand Down Expand Up @@ -546,36 +549,8 @@ void QgsLayoutScaleBarWidget::mUnitsComboBox_currentIndexChanged( int index )
}

disconnectUpdateSignal();
mScalebar->setUnits( ( QgsUnitTypes::DistanceUnit )unitData.toInt() );
switch ( mUnitsComboBox->currentIndex() )
{
case 0:
{
mScalebar->beginCommand( tr( "Set Scalebar Units" ) );
mScalebar->applyDefaultSize( QgsUnitTypes::DistanceUnknownUnit );
break;
}
case 2:
{
mScalebar->beginCommand( tr( "Set Scalebar Units" ) );
mScalebar->applyDefaultSize( QgsUnitTypes::DistanceFeet );
break;
}
case 3:
{
mScalebar->beginCommand( tr( "Set Scalebar Units" ) );
mScalebar->applyDefaultSize( QgsUnitTypes::DistanceNauticalMiles );
break;
}
case 1:
default:
{
mScalebar->beginCommand( tr( "Set Scalebar Units" ) );
mScalebar->applyDefaultSize( QgsUnitTypes::DistanceMeters );
break;
}
}

mScalebar->beginCommand( tr( "Set Scalebar Units" ) );
mScalebar->applyDefaultSize( static_cast< QgsUnitTypes::DistanceUnit >( unitData.toInt() ) );
mScalebar->update();

mUnitLabelLineEdit->setText( mScalebar->unitLabel() );
Expand Down
14 changes: 7 additions & 7 deletions src/core/layout/qgslayoutitemscalebar.cpp
Expand Up @@ -423,13 +423,13 @@ void QgsLayoutItemScaleBar::applyDefaultSettings()

void QgsLayoutItemScaleBar::applyDefaultSize( QgsUnitTypes::DistanceUnit units )
{
mSettings.setUnits( units );
if ( mMap )
{
setUnits( units );
double upperMagnitudeMultiplier = 1.0;
double widthInSelectedUnits = mapWidth();
double initialUnitsPerSegment = widthInSelectedUnits / 10.0; //default scalebar width equals half the map width
setUnitsPerSegment( initialUnitsPerSegment );
mSettings.setUnitsPerSegment( initialUnitsPerSegment );

switch ( units )
{
Expand Down Expand Up @@ -483,11 +483,11 @@ void QgsLayoutItemScaleBar::applyDefaultSize( QgsUnitTypes::DistanceUnit units )
{
unitsPerSegment = unitsPerSegment * multiplier;
}
setUnitsPerSegment( unitsPerSegment );
setMapUnitsPerScaleBarUnit( upperMagnitudeMultiplier );
mSettings.setUnitsPerSegment( unitsPerSegment );
mSettings.setMapUnitsPerScaleBarUnit( upperMagnitudeMultiplier );

setNumberOfSegments( 4 );
setNumberOfSegmentsLeft( 2 );
mSettings.setNumberOfSegments( 4 );
mSettings.setNumberOfSegmentsLeft( 2 );
}

refreshSegmentMillimeters();
Expand Down Expand Up @@ -611,7 +611,7 @@ bool QgsLayoutItemScaleBar::writePropertiesToElement( QDomElement &composerScale
//map id
if ( mMap )
{
composerScaleBarElem.setAttribute( QStringLiteral( "mapId" ), mMap->id() );
composerScaleBarElem.setAttribute( QStringLiteral( "mapUuid" ), mMap->uuid() );
}

//colors
Expand Down

0 comments on commit af59c53

Please sign in to comment.