Skip to content
Permalink
Browse files

[layouts] Add more unit choices to scalebars

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 20, 2017
1 parent 3c4fae0 commit af59c535a99f7b015f904acc620fcd8ffd6128f4
Showing with 17 additions and 42 deletions.
  1. +10 −35 src/app/layout/qgslayoutscalebarwidget.cpp
  2. +7 −7 src/core/layout/qgslayoutitemscalebar.cpp
@@ -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 );
@@ -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 )
{
@@ -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() );
@@ -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 )
{
@@ -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();
@@ -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

0 comments on commit af59c53

Please sign in to comment.
You can’t perform that action at this time.