mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-17 00:04:02 -04:00
[composer] Add nautical miles support to scalebar, more rational default scale
This commit is contained in:
parent
926a676555
commit
4fd3b1fb07
@ -23,7 +23,8 @@ class QgsComposerScaleBar: QgsComposerItem
|
|||||||
{
|
{
|
||||||
MapUnits = 0,
|
MapUnits = 0,
|
||||||
Meters,
|
Meters,
|
||||||
Feet
|
Feet,
|
||||||
|
NauticalMiles
|
||||||
};
|
};
|
||||||
|
|
||||||
QgsComposerScaleBar( QgsComposition* composition /TransferThis/ );
|
QgsComposerScaleBar( QgsComposition* composition /TransferThis/ );
|
||||||
@ -95,7 +96,7 @@ class QgsComposerScaleBar: QgsComposerItem
|
|||||||
void applyDefaultSettings();
|
void applyDefaultSettings();
|
||||||
/**Apply default size (scale bar 1/5 of map item width)
|
/**Apply default size (scale bar 1/5 of map item width)
|
||||||
@note this method was added in version 1.7*/
|
@note this method was added in version 1.7*/
|
||||||
void applyDefaultSize();
|
void applyDefaultSize( ScaleBarUnits u = Meters );
|
||||||
|
|
||||||
/**Sets style by name
|
/**Sets style by name
|
||||||
@param styleName (untranslated) style name. Possibilities are: 'Single Box', 'Double Box', 'Line Ticks Middle', 'Line Ticks Down', 'Line Ticks Up', 'Numeric'*/
|
@param styleName (untranslated) style name. Possibilities are: 'Single Box', 'Double Box', 'Line Ticks Middle', 'Line Ticks Down', 'Line Ticks Up', 'Numeric'*/
|
||||||
|
@ -51,7 +51,7 @@ QgsComposerScaleBarWidget::QgsComposerScaleBarWidget( QgsComposerScaleBar* scale
|
|||||||
mUnitsComboBox->insertItem( 0, tr( "Map units" ), 0 );
|
mUnitsComboBox->insertItem( 0, tr( "Map units" ), 0 );
|
||||||
mUnitsComboBox->insertItem( 1, tr( "Meters" ), 1 );
|
mUnitsComboBox->insertItem( 1, tr( "Meters" ), 1 );
|
||||||
mUnitsComboBox->insertItem( 2, tr( "Feet" ), 2 );
|
mUnitsComboBox->insertItem( 2, tr( "Feet" ), 2 );
|
||||||
|
mUnitsComboBox->insertItem( 3, tr( "Nautical Miles" ), 3 );
|
||||||
blockMemberSignals( false );
|
blockMemberSignals( false );
|
||||||
setGuiElements(); //set the GUI elements to the state of scaleBar
|
setGuiElements(); //set the GUI elements to the state of scaleBar
|
||||||
}
|
}
|
||||||
@ -532,9 +532,37 @@ void QgsComposerScaleBarWidget::on_mUnitsComboBox_currentIndexChanged( int index
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mComposerScaleBar->beginCommand( tr( "Scalebar unit changed" ) );
|
|
||||||
disconnectUpdateSignal();
|
disconnectUpdateSignal();
|
||||||
mComposerScaleBar->setUnits(( QgsComposerScaleBar::ScaleBarUnits )unitData.toInt() );
|
mComposerScaleBar->setUnits(( QgsComposerScaleBar::ScaleBarUnits )unitData.toInt() );
|
||||||
|
switch ( mUnitsComboBox->currentIndex() )
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
{
|
||||||
|
mComposerScaleBar->beginCommand( tr( "Scalebar changed to map units" ) );
|
||||||
|
mComposerScaleBar->applyDefaultSize( QgsComposerScaleBar::MapUnits );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 2:
|
||||||
|
{
|
||||||
|
mComposerScaleBar->beginCommand( tr( "Scalebar changed to feet" ) );
|
||||||
|
mComposerScaleBar->applyDefaultSize( QgsComposerScaleBar::Feet );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 3:
|
||||||
|
{
|
||||||
|
mComposerScaleBar->beginCommand( tr( "Scalebar changed to nautical miles" ) );
|
||||||
|
mComposerScaleBar->applyDefaultSize( QgsComposerScaleBar::NauticalMiles );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 1:
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
mComposerScaleBar->beginCommand( tr( "Scalebar changed to meters" ) );
|
||||||
|
mComposerScaleBar->applyDefaultSize( QgsComposerScaleBar::Meters );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mComposerScaleBar->update();
|
mComposerScaleBar->update();
|
||||||
connectUpdateSignal();
|
connectUpdateSignal();
|
||||||
mComposerScaleBar->endCommand();
|
mComposerScaleBar->endCommand();
|
||||||
|
@ -194,10 +194,14 @@ double QgsComposerScaleBar::mapWidth() const
|
|||||||
da.setEllipsoid( QgsProject::instance()->readEntry( "Measure", "/Ellipsoid", "WGS84" ) );
|
da.setEllipsoid( QgsProject::instance()->readEntry( "Measure", "/Ellipsoid", "WGS84" ) );
|
||||||
|
|
||||||
double measure = da.measureLine( QgsPoint( composerMapRect.xMinimum(), composerMapRect.yMinimum() ), QgsPoint( composerMapRect.xMaximum(), composerMapRect.yMinimum() ) );
|
double measure = da.measureLine( QgsPoint( composerMapRect.xMinimum(), composerMapRect.yMinimum() ), QgsPoint( composerMapRect.xMaximum(), composerMapRect.yMinimum() ) );
|
||||||
if ( mUnits == Feet )
|
if ( mUnits == QgsComposerScaleBar::Feet )
|
||||||
{
|
{
|
||||||
measure /= 0.3048;
|
measure /= 0.3048;
|
||||||
}
|
}
|
||||||
|
else if ( mUnits == QgsComposerScaleBar::NauticalMiles )
|
||||||
|
{
|
||||||
|
measure /= 1852.0;
|
||||||
|
}
|
||||||
return measure;
|
return measure;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -250,25 +254,71 @@ void QgsComposerScaleBar::applyDefaultSettings()
|
|||||||
emit itemChanged();
|
emit itemChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsComposerScaleBar::applyDefaultSize()
|
void QgsComposerScaleBar::applyDefaultSize( QgsComposerScaleBar::ScaleBarUnits u )
|
||||||
{
|
{
|
||||||
if ( mComposerMap )
|
if ( mComposerMap )
|
||||||
{
|
{
|
||||||
setUnits( Meters );
|
setUnits( u );
|
||||||
double widthMeter = mapWidth();
|
double upperMagnitudeMultiplier;
|
||||||
int nUnitsPerSegment = widthMeter / 10.0; //default scalebar width equals half the map width
|
double widthInSelectedUnits = mapWidth();
|
||||||
setNumUnitsPerSegment( nUnitsPerSegment );
|
double initialUnitsPerSegment = widthInSelectedUnits / 10.0; //default scalebar width equals half the map width
|
||||||
|
setNumUnitsPerSegment( initialUnitsPerSegment );
|
||||||
|
|
||||||
if ( nUnitsPerSegment > 1000 )
|
switch ( mUnits )
|
||||||
{
|
{
|
||||||
setNumUnitsPerSegment(( int )( numUnitsPerSegment() / 1000.0 + 0.5 ) * 1000 );
|
case MapUnits:
|
||||||
setUnitLabeling( tr( "km" ) );
|
{
|
||||||
setNumMapUnitsPerScaleBarUnit( 1000 );
|
upperMagnitudeMultiplier = 1.0;
|
||||||
|
setUnitLabeling( tr( "units" ) );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Meters:
|
||||||
|
{
|
||||||
|
if ( initialUnitsPerSegment > 1000.0 )
|
||||||
|
{
|
||||||
|
upperMagnitudeMultiplier = 1000.0;
|
||||||
|
setUnitLabeling( tr( "km" ) );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
upperMagnitudeMultiplier = 1.0;
|
||||||
|
setUnitLabeling( tr( "m" ) );
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Feet:
|
||||||
|
{
|
||||||
|
if ( initialUnitsPerSegment > 5419.95 )
|
||||||
|
{
|
||||||
|
upperMagnitudeMultiplier = 5419.95;
|
||||||
|
setUnitLabeling( tr( "miles" ) );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
upperMagnitudeMultiplier = 1.0;
|
||||||
|
setUnitLabeling( tr( "ft" ) );
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case NauticalMiles:
|
||||||
|
{
|
||||||
|
upperMagnitudeMultiplier = 1;
|
||||||
|
setUnitLabeling( tr( "Nm" ) );
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
double segmentWidth = initialUnitsPerSegment / upperMagnitudeMultiplier;
|
||||||
|
int segmentMagnitude = floor( log10( segmentWidth ) );
|
||||||
|
double unitsPerSegment = upperMagnitudeMultiplier * ( pow( 10, segmentMagnitude ) );
|
||||||
|
double multiplier = floor(( widthInSelectedUnits / ( unitsPerSegment * 10 ) ) / 2.5 ) * 2.5;
|
||||||
|
|
||||||
|
if ( multiplier > 0 )
|
||||||
{
|
{
|
||||||
setUnitLabeling( tr( "m" ) );
|
unitsPerSegment = unitsPerSegment * multiplier;
|
||||||
}
|
}
|
||||||
|
setNumUnitsPerSegment( unitsPerSegment );
|
||||||
|
setNumMapUnitsPerScaleBarUnit( upperMagnitudeMultiplier );
|
||||||
|
|
||||||
setNumSegments( 4 );
|
setNumSegments( 4 );
|
||||||
setNumSegmentsLeft( 2 );
|
setNumSegmentsLeft( 2 );
|
||||||
|
@ -46,7 +46,8 @@ class CORE_EXPORT QgsComposerScaleBar: public QgsComposerItem
|
|||||||
{
|
{
|
||||||
MapUnits = 0,
|
MapUnits = 0,
|
||||||
Meters,
|
Meters,
|
||||||
Feet
|
Feet,
|
||||||
|
NauticalMiles
|
||||||
};
|
};
|
||||||
|
|
||||||
QgsComposerScaleBar( QgsComposition* composition );
|
QgsComposerScaleBar( QgsComposition* composition );
|
||||||
@ -118,7 +119,7 @@ class CORE_EXPORT QgsComposerScaleBar: public QgsComposerItem
|
|||||||
void applyDefaultSettings();
|
void applyDefaultSettings();
|
||||||
/**Apply default size (scale bar 1/5 of map item width)
|
/**Apply default size (scale bar 1/5 of map item width)
|
||||||
@note this method was added in version 1.7*/
|
@note this method was added in version 1.7*/
|
||||||
void applyDefaultSize();
|
void applyDefaultSize( ScaleBarUnits u = Meters );
|
||||||
|
|
||||||
/**Sets style by name
|
/**Sets style by name
|
||||||
@param styleName (untranslated) style name. Possibilities are: 'Single Box', 'Double Box', 'Line Ticks Middle', 'Line Ticks Down', 'Line Ticks Up', 'Numeric'*/
|
@param styleName (untranslated) style name. Possibilities are: 'Single Box', 'Double Box', 'Line Ticks Middle', 'Line Ticks Down', 'Line Ticks Up', 'Numeric'*/
|
||||||
@ -203,8 +204,9 @@ class CORE_EXPORT QgsComposerScaleBar: public QgsComposerItem
|
|||||||
/**Calculates with of a segment in mm and stores it in mSegmentMillimeters*/
|
/**Calculates with of a segment in mm and stores it in mSegmentMillimeters*/
|
||||||
void refreshSegmentMillimeters();
|
void refreshSegmentMillimeters();
|
||||||
|
|
||||||
/**Returns diagonal of composer map in selected units (map units / meters / feet)*/
|
/**Returns diagonal of composer map in selected units (map units / meters / feet / nautical miles)*/
|
||||||
double mapWidth() const;
|
double mapWidth() const;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //QGSCOMPOSERSCALEBAR_H
|
#endif //QGSCOMPOSERSCALEBAR_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user