[Marble-commits] KDE/kdeedu/marble
Dennis Nienhüser
earthwings at gentoo.org
Thu Feb 3 21:05:39 CET 2011
SVN commit 1218689 by nienhueser:
Move distance calculation to Coordinate. Merge the lon(), lat() methods into coordinate().
M +2 -3 examples/qml/where-is-that/where-is-that.qml
M +9 -0 src/plugins/declarative/Coordinate.cpp
M +3 -0 src/plugins/declarative/Coordinate.h
M +5 -20 src/plugins/declarative/MarbleDeclarativeWidget.cpp
M +4 -15 src/plugins/declarative/MarbleDeclarativeWidget.h
--- trunk/KDE/kdeedu/marble/examples/qml/where-is-that/where-is-that.qml #1218688:1218689
@@ -230,9 +230,8 @@
{
var flon = questionModel.get(questionView.currentIndex).lon
var flat = questionModel.get(questionView.currentIndex).lat
- var tlon = map.lon( pointer.x, pointer.y )
- var tlat = map.lat( pointer.x, pointer.y )
- var dist = map.distance( flon, flat, tlon, tlat ) / 1000
+ var coordinate = map.coordinate( pointer.x, pointer.y )
+ var dist = coordinate.distance( flon, flat ) / 1000
messages.text = "Target distance: " + dist.toFixed(1) + " km"
}
--- trunk/KDE/kdeedu/marble/src/plugins/declarative/Coordinate.cpp #1218688:1218689
@@ -10,6 +10,8 @@
#include "Coordinate.h"
+#include "MarbleMath.h"
+
namespace Marble
{
namespace Declarative
@@ -66,7 +68,14 @@
m_coordinate = coordinates;
}
+qreal Coordinate::distance( qreal longitude, qreal latitude ) const
+{
+ GeoDataCoordinates::Unit deg = GeoDataCoordinates::Degree;
+ GeoDataCoordinates other( longitude, latitude, 0, deg );
+ return EARTH_RADIUS * distanceSphere( coordinates(), other );
}
+
}
+}
#include "Coordinate.moc"
--- trunk/KDE/kdeedu/marble/src/plugins/declarative/Coordinate.h #1218688:1218689
@@ -62,6 +62,9 @@
/** Change all coordinates at once */
void setCoordinates( const GeoDataCoordinates &coordinates );
+ /** Distance (in meter) to the given coordinate */
+ Q_INVOKABLE qreal distance( qreal longitude, qreal latitude ) const;
+
Q_SIGNALS:
void longitudeChanged();
void latitudeChanged();
--- trunk/KDE/kdeedu/marble/src/plugins/declarative/MarbleDeclarativeWidget.cpp #1218688:1218689
@@ -11,6 +11,7 @@
#include "MarbleDeclarativeWidget.h"
#include "MapTheme.h"
+#include "Coordinate.h"
#include "GeoDataCoordinates.h"
#include "MarbleWidget.h"
@@ -139,30 +140,14 @@
return result;
}
-qreal MarbleWidget::lon( int x, int y ) const
+Coordinate *MarbleWidget::coordinate( int x, int y )
{
- qreal result( 0.0 );
- qreal lat( 0.0 );
- m_marbleWidget->geoCoordinates( x, y, result, lat );
- return result;
+ qreal lat( 0.0 ), lon( 0.0 );
+ m_marbleWidget->geoCoordinates( x, y, lon, lat );
+ return new Coordinate( lon, lat, 0.0, this );
}
-qreal MarbleWidget::lat( int x, int y ) const
-{
- qreal lon( 0.0 );
- qreal result( 0.0 );
- m_marbleWidget->geoCoordinates( x, y, lon, result );
- return result;
}
-
-qreal MarbleWidget::distance( qreal flon, qreal flat, qreal tlon, qreal tlat )
-{
- GeoDataCoordinates::Unit deg = GeoDataCoordinates::Degree;
- return EARTH_RADIUS * distanceSphere( GeoDataCoordinates( flon, flat, 0, deg ),
- GeoDataCoordinates( tlon, tlat, 0, deg ) );
}
-}
-}
-
#include "MarbleDeclarativeWidget.moc"
--- trunk/KDE/kdeedu/marble/src/plugins/declarative/MarbleDeclarativeWidget.h #1218688:1218689
@@ -21,6 +21,8 @@
namespace Declarative
{
+class Coordinate;
+
/**
* Wraps a Marble::MarbleWidget, providing access to important properties and methods
*
@@ -102,23 +104,10 @@
qreal screenY( qreal lon, qreal lat ) const;
/**
- * Longitude of the given screen position
- * @todo FIXME: Introduce GeoDataCoordinates and use QPoint
+ * Returns the coordinate at the given screen position
*/
- qreal lon( int x, int y ) const;
+ Marble::Declarative::Coordinate *coordinate( int x, int y );
- /**
- * Latitude of the given screen position
- * @todo FIXME: Introduce GeoDataCoordinates and use QPoint
- */
- qreal lat( int x, int y ) const;
-
- /**
- * Distance between two coordinates
- * @todo FIXME: Introduce GeoDataCoordinates
- */
- qreal distance( qreal flon, qreal flat, qreal tlon, qreal tlat );
-
private:
/** Wrapped MarbleWidget */
Marble::MarbleWidget* m_marbleWidget;
More information about the Marble-commits
mailing list