[Marble-commits] KDE/kdeedu/marble/src/lib/gps
Thibaut Gridel
tgridel at free.fr
Sun Jun 6 21:25:41 CEST 2010
SVN commit 1135201 by tgridel:
positiontracking: react to positionprovider signal to get position
update and draw do graphic job only
M +37 -40 PositionTracking.cpp
M +4 -13 PositionTracking.h
--- trunk/KDE/kdeedu/marble/src/lib/gps/PositionTracking.cpp #1135200:1135201
@@ -56,15 +56,6 @@
QPointF position;
QPointF previousPosition;
- //FIXME: this is a workaround for dealing with NAN values. we need to protect against that in the future
- m_gpsCurrentPosition->setPosition( GeoDataCoordinates ( m_gpsCurrentPosition->position().longitude(GeoDataCoordinates::Degree),
- m_gpsCurrentPosition->position().latitude( GeoDataCoordinates::Degree ),
- m_gpsCurrentPosition->position().altitude(), GeoDataCoordinates::Degree ) );
- m_gpsPreviousPosition->setPosition( GeoDataCoordinates ( m_gpsPreviousPosition->position().longitude(GeoDataCoordinates::Degree),
- m_gpsPreviousPosition->position().latitude( GeoDataCoordinates::Degree ),
- m_gpsPreviousPosition->position().altitude(), GeoDataCoordinates::Degree) );
-
-
m_gpsCurrentPosition->getPixelPos( canvasSize, viewParams, &position );
m_gpsPreviousPosition->getPixelPos( canvasSize, viewParams, &previousPosition );
@@ -89,24 +80,6 @@
}
-QRegion PositionTracking::genRegion( const QSize &canvasSize,
- ViewParams *viewParams )
-{
- construct( canvasSize, viewParams );
-
- QRegion dirty;
- QList<QPolygonF> items;
- items << m_previousDraw << m_currentDraw;
- foreach(const QPolygonF &polygon, items)
- {
- QRect rect = polygon.boundingRect().toRect();
- rect.adjust( -5, -5, 10, 10 );
- dirty |= rect ;
- }
-
- return dirty;
-}
-
void PositionTracking::updateSpeed( TrackPoint* previous, TrackPoint* next )
{
//This function makes the assumption that the update stage happens once
@@ -118,13 +91,13 @@
m_speed = distance * 60 * 60;
}
-bool PositionTracking::update(const QSize &canvasSize, ViewParams *viewParams,
- QRegion ®)
+void PositionTracking::setPosition( GeoDataCoordinates position,
+ GeoDataAccuracy accuracy )
{
if ( m_positionProvider && m_positionProvider->status() ==
PositionProviderStatusAvailable )
{
- m_gpsTracking->setPosition( m_positionProvider->position() );
+ m_gpsTracking->setPosition( position );
m_gpsTracking->setPosition( GeoDataCoordinates ( m_gpsTracking->position().longitude(GeoDataCoordinates::Degree),
m_gpsTracking->position().latitude( GeoDataCoordinates::Degree ),
m_gpsTracking->position().altitude(), GeoDataCoordinates::Degree ) );
@@ -135,11 +108,6 @@
m_gpsTrack->append( m_gpsTrackSeg );
}
- //updateSpeed updates the speed to radians and needs
- //to be multiplied by the radius
- updateSpeed( m_gpsPreviousPosition, m_gpsTracking );
- m_speed *= viewParams->radius();
-
//if the position has moved then update the current position
if ( !( m_gpsPreviousPosition->position() ==
m_gpsTracking->position() ) )
@@ -147,21 +115,48 @@
m_gpsTrackSeg->append( m_gpsPreviousPosition );
m_gpsPreviousPosition = m_gpsCurrentPosition;
m_gpsCurrentPosition = new TrackPoint( *m_gpsTracking );
- reg = genRegion( canvasSize, viewParams );
- // mDebug() << "Dirty region: " << reg;
emit gpsLocation( m_gpsTracking->position(), m_speed );
- return true;
- } else {
- return false;
}
} else {
if ( m_gpsTrackSeg && m_gpsTrackSeg->count() > 0 ) {
m_gpsTrackSeg = 0;
}
}
+}
+bool PositionTracking::update(const QSize &canvasSize, ViewParams *viewParams,
+ QRegion ®)
+{
+ if ( m_positionProvider && m_positionProvider->status() ==
+ PositionProviderStatusAvailable )
+ {
+ //updateSpeed updates the speed to radians and needs
+ //to be multiplied by the radius
+ updateSpeed( m_gpsPreviousPosition, m_gpsTracking );
+ m_speed *= viewParams->radius();
+
+ //if the position has moved then update the current position
+ if ( !( m_gpsPreviousPosition->position() ==
+ m_gpsTracking->position() ) )
+ {
+ construct( canvasSize, viewParams );
+
+ QList<QPolygonF> items;
+ items << m_previousDraw << m_currentDraw;
+ foreach(const QPolygonF &polygon, items)
+ {
+ QRect rect = polygon.boundingRect().toRect();
+ rect.adjust( -5, -5, 10, 10 );
+ reg |= rect ;
+ }
+
+ return true;
+ } else {
return false;
}
+ }
+ return false;
+}
void PositionTracking::draw( ClipPainter *painter,
const QSize &canvasSize,
@@ -192,6 +187,8 @@
mDebug() << "Initializing position provider:" << m_positionProvider->name();
connect( m_positionProvider, SIGNAL( statusChanged( PositionProviderStatus ) ),
this, SIGNAL( statusChanged(PositionProviderStatus ) ) );
+ connect( m_positionProvider, SIGNAL(positionChanged(GeoDataCoordinates,GeoDataAccuracy)),
+ this, SLOT(setPosition(GeoDataCoordinates,GeoDataAccuracy)));
m_positionProvider->initialize();
}
}
--- trunk/KDE/kdeedu/marble/src/lib/gps/PositionTracking.h #1135200:1135201
@@ -64,19 +64,6 @@
void construct ( const QSize &canvasSize,
ViewParams *viewParams );
- /**
- * generates the region of the view that needs to be updated when
- * the provided position changes. it is a union of the old
- * position with the new one.
- *
- * @param canvasSize current size of view.
- * @param radius current radius
- * @param invRotAxis current Quaternion representation of globe.
- * @return QRegion representation of where on the view needs to be
- * updated.
- */
- QRegion genRegion( const QSize &canvasSize,
- ViewParams *viewParams );
void draw( ClipPainter *painter,
const QSize &canvasSize,
@@ -95,6 +82,10 @@
void statusChanged( PositionProviderStatus status );
+public slots:
+ void setPosition( GeoDataCoordinates position,
+ GeoDataAccuracy accuracy );
+
private:
void updateSpeed( TrackPoint* previous, TrackPoint* next );
More information about the Marble-commits
mailing list