[Marble-commits] KDE/kdeedu/marble/src/lib/routing
Dennis Nienhüser
earthwings at gentoo.org
Fri Apr 30 22:54:18 CEST 2010
SVN commit 1121225 by nienhueser:
Parse errors reported by ORS and report it in the map and the list widget (often "no street within 300 meters" occurs)
M +4 -1 RoutingLayer.cpp
M +13 -0 RoutingManager.cpp
M +29 -0 RoutingModel.cpp
M +7 -1 RoutingModel.h
M +1 -1 RoutingProxyModel.cpp
--- trunk/KDE/kdeedu/marble/src/lib/routing/RoutingLayer.cpp #1121224:1121225
@@ -222,7 +222,6 @@
RoutingModel::RoutingItemType type = qVariantValue<RoutingModel::RoutingItemType>( index.data( RoutingModel::TypeRole ) );
if ( type == RoutingModel::Instruction ) {
-
painter->setBrush( QBrush( QColor::fromRgb( 136, 138, 133, 200 ) ) ); // gray, oxygen palette
QModelIndex proxyIndex = m_proxyModel->mapFromSource( index );
if ( m_selectionModel->selection().contains( proxyIndex ) ) {
@@ -237,6 +236,10 @@
QRegion region = painter->regionFromEllipse( pos, 12, 12 );
m_instructionRegions.push_front( ModelRegion( index, region ) );
painter->drawEllipse( pos, 8, 8 );
+ } else if ( type == RoutingModel::Error ) {
+ painter->setPen( QColor( Qt::white ) );
+ painter->setBrush( QBrush( QColor::fromRgb( 226, 8, 0, 200 ) ) ); // red, oxygen palette
+ painter->drawAnnotation( pos, index.data().toString(), QSize( 180, 80 ), 10, 30, 15, 15 );
}
}
}
--- trunk/KDE/kdeedu/marble/src/lib/routing/RoutingManager.cpp #1121224:1121225
@@ -77,10 +77,23 @@
void RoutingManager::updateRoute()
{
if ( d->m_route && d->m_route->size() > 1 ) {
+ int realSize = 0;
+ for ( int i = 0; i < d->m_route->size(); ++i ) {
+ // Sort out dummy targets
+ if ( d->m_route->at( i ).longitude() != 0.0 && d->m_route->at( i ).latitude() != 0.0 ) {
+ ++realSize;
+ }
+ }
+
+ if ( realSize > 1 ) {
emit stateChanged( Downloading, d->m_route );
d->m_routingProvider->retrieveDirections( d->m_route );
+ } else {
+ d->m_routingModel->clear();
+ emit stateChanged( Retrieved, d->m_route );
}
}
+}
} // namespace Marble
--- trunk/KDE/kdeedu/marble/src/lib/routing/RoutingModel.cpp #1121224:1121225
@@ -138,6 +138,29 @@
QDomElement root = xml.documentElement();
+ QDomNodeList errors = root.elementsByTagName( "xls:Error" );
+ if ( errors.size() > 0 ) {
+ for ( unsigned int i = 0; i < errors.length(); ++i ) {
+ QDomNode node = errors.item( i );
+ QString errorMessage = node.attributes().namedItem( "message" ).nodeValue();
+ QRegExp regexp = QRegExp( "^(.*) Please Check your Position: (-?[0-9]+.[0-9]+) (-?[0-9]+.[0-9]+) !" );
+ if ( regexp.indexIn( errorMessage ) == 0 ) {
+ RouteElement element;
+ GeoDataCoordinates position;
+ if ( regexp.capturedTexts().size() == 4 ) {
+ element.description = regexp.capturedTexts().at( 1 );
+ position.setLongitude( regexp.capturedTexts().at( 2 ).toDouble(), GeoDataCoordinates::Degree );
+ position.setLatitude( regexp.capturedTexts().at( 3 ).toDouble(), GeoDataCoordinates::Degree );
+ element.position = position;
+ element.type = Error;
+ d->m_route.push_back( element );
+ }
+ } else {
+ mDebug() << "Error message " << errorMessage << " not parsable.";
+ }
+ }
+ }
+
QDomNodeList summary = root.elementsByTagName( "xls:RouteSummary" );
if ( summary.size() > 0 ) {
QDomNodeList time = summary.item( 0 ).toElement().elementsByTagName( "xls:TotalTime" );
@@ -256,6 +279,12 @@
device->write( content.toLocal8Bit() );
}
+void RoutingModel::clear()
+{
+ d->m_route.clear();
+ reset();
+}
+
} // namespace Marble
#include "RoutingModel.moc"
--- trunk/KDE/kdeedu/marble/src/lib/routing/RoutingModel.h #1121224:1121225
@@ -40,7 +40,8 @@
enum RoutingItemType {
WayPoint,
- Instruction
+ Instruction,
+ Error
};
/** Constructor */
@@ -94,6 +95,11 @@
*/
void exportGpx( QIODevice *device ) const;
+ /**
+ * Clear any data held in the model
+ */
+ void clear();
+
private:
RoutingModelPrivate *const d;
};
--- trunk/KDE/kdeedu/marble/src/lib/routing/RoutingProxyModel.cpp #1121224:1121225
@@ -31,7 +31,7 @@
QModelIndex index = sourceModel()->index( source_row, 0 );
RoutingModel::RoutingItemType type = qVariantValue<RoutingModel::RoutingItemType>( index.data( RoutingModel::TypeRole ) );
- return type == RoutingModel::Instruction;
+ return type == RoutingModel::Instruction || type == RoutingModel::Error;
}
} // namespace Marble
More information about the Marble-commits
mailing list