• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

marble

  • sources
  • kde-4.14
  • kdeedu
  • marble
  • src
  • plugins
  • render
  • elevationprofilefloatitem
ElevationProfilePlotAxis.cpp
Go to the documentation of this file.
1 //
2 // This file is part of the Marble Virtual Globe.
3 //
4 // This program is free software licensed under the GNU LGPL. You can
5 // find a copy of this license in LICENSE.txt in the top directory of
6 // the source code.
7 //
8 // Copyright 2011-2012 Florian Eßer <f.esser@rwth-aachen.de>
9 //
10 
11 #include "ElevationProfilePlotAxis.h"
12 
13 #include "MarbleLocale.h"
14 #include "MarbleMath.h"
15 
16 #include <qmath.h>
17 
18 namespace Marble
19 {
20 
21 ElevationProfilePlotAxis::ElevationProfilePlotAxis()
22  : m_minValue( 0.0 ),
23  m_maxValue ( 0.0 ),
24  m_displayScale( 1.0 ),
25  m_pixelLength ( 0 ),
26  m_minTickCount( 2 ),
27  m_maxTickCount( 5 ),
28  m_unitString( QString() )
29 {
30  // nothing to do...
31 }
32 
33 void ElevationProfilePlotAxis::setRange( const qreal& minValue, const qreal& maxValue )
34 {
35  m_minValue = minValue;
36  m_maxValue = maxValue;
37  update();
38 }
39 
40 void ElevationProfilePlotAxis::setLength( const int& length )
41 {
42  m_pixelLength = length;
43  update();
44 }
45 
46 void ElevationProfilePlotAxis::setTickCount( const int min, const int max )
47 {
48  m_minTickCount = min;
49  m_maxTickCount = max;
50 }
51 
52 void ElevationProfilePlotAxis::update()
53 {
54  updateTicks();
55  updateScale();
56 }
57 
58 qreal ElevationProfilePlotAxis::minValue() const
59 {
60  return m_minValue;
61 }
62 
63 qreal ElevationProfilePlotAxis::maxValue() const
64 {
65  return m_maxValue;
66 }
67 
68 qreal ElevationProfilePlotAxis::range() const
69 {
70  return m_maxValue - m_minValue;
71 }
72 
73 qreal ElevationProfilePlotAxis::scale() const
74 {
75  return m_displayScale;
76 }
77 
78 QString ElevationProfilePlotAxis::unit() const
79 {
80  return m_unitString;
81 }
82 
83 AxisTickList ElevationProfilePlotAxis::ticks() const
84 {
85  return m_ticks;
86 }
87 
88 void ElevationProfilePlotAxis::updateTicks()
89 {
90  m_ticks.clear();
91  if( range() == 0 ) {
92  return;
93  }
94 
95  QList<int> niceIntervals;
96  niceIntervals << 10 << 20 << 25 << 30 << 50;
97 
98  const int exponent = qRound( log10( range() ) );
99  const qreal factor = qPow( 10, 2 - exponent );
100  const qreal tickRange = range() * factor;
101 
102  qreal stepWidth = niceIntervals.last();
103  qreal error = tickRange;
104  foreach ( const int i, niceIntervals ) {
105  const qreal numTicks = tickRange / i;
106  if ( numTicks < m_minTickCount || numTicks > m_maxTickCount ) {
107  continue;
108  }
109  const qreal newError = qAbs( numTicks - qRound( numTicks ) );
110  if ( newError < error ) {
111  error = newError;
112  stepWidth = i;
113  }
114  }
115  stepWidth /= factor;
116 
117  qreal offset = 0;
118  if ( fmod( m_minValue, stepWidth ) != 0 ) {
119  offset = stepWidth - fmod( m_minValue, stepWidth );
120  }
121 
122  qreal val = m_minValue + offset;
123  int pos = m_pixelLength / range() * offset;
124  m_ticks << AxisTick( pos, val );
125  while( val < m_maxValue ) {
126  val += stepWidth;
127  pos += m_pixelLength / range() * stepWidth;
128  if ( pos > m_pixelLength ) {
129  break;
130  }
131  m_ticks << AxisTick( pos, val );
132  }
133 }
134 
135 void ElevationProfilePlotAxis::updateScale()
136 {
137  MarbleLocale::MeasurementSystem measurementSystem;
138  measurementSystem = MarbleGlobal::getInstance()->locale()->measurementSystem();
139  switch ( measurementSystem ) {
140  case MarbleLocale::MetricSystem:
141  if ( range() >= 10 * KM2METER ) {
142  m_unitString = tr( "km" );
143  m_displayScale = METER2KM;
144  } else {
145  m_unitString = tr( "m" );
146  m_displayScale = 1.0;
147  }
148  break;
149  case MarbleLocale::ImperialSystem:
150  // FIXME: Do these values make sense?
151  if ( range() >= 10 * KM2METER * MI2KM ) {
152  m_unitString = tr( "mi" );
153  m_displayScale = METER2KM * KM2MI;
154  } else {
155  m_unitString = tr( "ft" );
156  m_displayScale = M2FT;
157  }
158  break;
159 
160  case MarbleLocale::NauticalSystem:
161  m_unitString = tr("nm");
162  m_displayScale = METER2KM * KM2NM;
163  break;
164  }
165 }
166 
167 }
168 
169 #include "ElevationProfilePlotAxis.moc"
Marble::ElevationProfilePlotAxis::setTickCount
void setTickCount(const int min, const int max)
Definition: ElevationProfilePlotAxis.cpp:46
QList::clear
void clear()
Marble::ElevationProfilePlotAxis::minValue
qreal minValue() const
Definition: ElevationProfilePlotAxis.cpp:58
Marble::MarbleLocale::NauticalSystem
Definition: MarbleLocale.h:40
Marble::MarbleLocale::measurementSystem
MarbleLocale::MeasurementSystem measurementSystem() const
Definition: MarbleLocale.cpp:45
MarbleMath.h
Marble::ElevationProfilePlotAxis::unit
QString unit() const
Definition: ElevationProfilePlotAxis.cpp:78
Marble::ElevationProfilePlotAxis::setRange
void setRange(const qreal &minValue, const qreal &maxValue)
Definition: ElevationProfilePlotAxis.cpp:33
Marble::KM2METER
const qreal KM2METER
Definition: MarbleGlobal.h:223
Marble::ElevationProfilePlotAxis::maxValue
qreal maxValue() const
Definition: ElevationProfilePlotAxis.cpp:63
Marble::MarbleLocale::MeasurementSystem
MeasurementSystem
Definition: MarbleLocale.h:37
QObject::tr
QString tr(const char *sourceText, const char *disambiguation, int n)
Marble::ElevationProfilePlotAxis::range
qreal range() const
Definition: ElevationProfilePlotAxis.cpp:68
Marble::M2FT
const qreal M2FT
Definition: MarbleGlobal.h:211
Marble::MarbleGlobal::locale
MarbleLocale * locale() const
Definition: MarbleGlobal.cpp:43
QString
QList
MarbleLocale.h
Marble::METER2KM
const qreal METER2KM
Definition: MarbleGlobal.h:224
Marble::KM2MI
const qreal KM2MI
Definition: MarbleGlobal.h:203
Marble::ElevationProfilePlotAxis::scale
qreal scale() const
Definition: ElevationProfilePlotAxis.cpp:73
Marble::MarbleGlobal::getInstance
static MarbleGlobal * getInstance()
Definition: MarbleGlobal.cpp:37
Marble::MarbleLocale::MetricSystem
Definition: MarbleLocale.h:38
Marble::MI2KM
const qreal MI2KM
Definition: MarbleGlobal.h:202
QList::last
T & last()
Marble::MarbleLocale::ImperialSystem
Definition: MarbleLocale.h:39
Marble::KM2NM
const qreal KM2NM
Definition: MarbleGlobal.h:207
Marble::ElevationProfilePlotAxis::setLength
void setLength(const int &length)
Definition: ElevationProfilePlotAxis.cpp:40
Marble::ElevationProfilePlotAxis::ticks
AxisTickList ticks() const
Definition: ElevationProfilePlotAxis.cpp:83
Marble::ElevationProfilePlotAxis::update
void update()
Definition: ElevationProfilePlotAxis.cpp:52
Marble::ElevationProfilePlotAxis::ElevationProfilePlotAxis
ElevationProfilePlotAxis()
Definition: ElevationProfilePlotAxis.cpp:21
ElevationProfilePlotAxis.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:13:39 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

marble

Skip menu "marble"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal