[Marble-commits] KDE/kdeedu/marble/src/lib
Dennis Nienhüser
earthwings at gentoo.org
Sun Apr 3 14:38:48 CEST 2011
SVN commit 1226963 by nienhueser:
Detect when routing delivers no result and tell the user about it. Also inform him about the number of results. Fixes endless spinning of 'Get Directions' progress animation.
M +24 -2 MarbleRunnerManager.cpp
M +2 -0 MarbleRunnerManager.h
M +3 -1 routing/RoutingManager.cpp
M +26 -0 routing/RoutingWidget.cpp
M +3 -0 routing/RoutingWidget.h
M +7 -0 routing/RoutingWidget.ui
--- trunk/KDE/kdeedu/marble/src/lib/MarbleRunnerManager.cpp #1226962:1226963
@@ -54,8 +54,11 @@
QList<RunnerPlugin*> plugins( RunnerPlugin::Capability capability );
QList<RunnerTask*> m_searchTasks;
+ QList<RunnerTask*> m_routingTasks;
void cleanupSearchTask( RunnerTask* task );
+
+ void cleanupRoutingTask( RunnerTask* task );
};
MarbleRunnerManagerPrivate::MarbleRunnerManagerPrivate( MarbleRunnerManager* parent, PluginManager* pluginManager ) :
@@ -114,6 +117,15 @@
}
}
+void MarbleRunnerManagerPrivate::cleanupRoutingTask( RunnerTask* task )
+{
+ m_routingTasks.removeAll( task );
+
+ if ( m_routingTasks.isEmpty() && m_routingResult.isEmpty() ) {
+ emit q->routeRetrieved( 0 );
+ }
+}
+
MarbleRunnerManager::MarbleRunnerManager( PluginManager* pluginManager, QObject *parent )
: QObject( parent ), d( new MarbleRunnerManagerPrivate( this, pluginManager ) )
{
@@ -212,29 +224,39 @@
{
RoutingProfile profile = request->routingProfile();
+ qDeleteAll( d->m_routingTasks );
+ d->m_routingTasks.clear();
d->m_routingResult.clear();
+
d->m_routeRequest = request;
QList<RunnerPlugin*> plugins = d->plugins( RunnerPlugin::Routing );
+ bool started = false;
foreach( RunnerPlugin* plugin, plugins ) {
if ( !profile.pluginSettings().contains( plugin->nameId() ) ) {
continue;
}
+ started = true;
MarbleAbstractRunner* runner = plugin->newRunner();
connect( runner, SIGNAL( routeCalculated( GeoDataDocument* ) ),
this, SLOT( addRoutingResult( GeoDataDocument* ) ) );
runner->setModel( d->m_marbleModel );
- QThreadPool::globalInstance()->start( new RoutingTask( runner, request ) );
+ RoutingTask* task = new RoutingTask( runner, request );
+ d->m_routingTasks << task;
+ connect( task, SIGNAL( finished( RunnerTask* ) ), this, SLOT( cleanupRoutingTask( RunnerTask* ) ) );
+ QThreadPool::globalInstance()->start( task );
}
- if ( plugins.isEmpty() ) {
+ if ( !started ) {
mDebug() << "No routing plugins found, cannot retrieve a route";
+ d->cleanupRoutingTask( 0 );
}
}
void MarbleRunnerManager::addRoutingResult( GeoDataDocument* route )
{
if ( route ) {
+ d->m_routingResult.push_back( route );
emit routeRetrieved( route );
}
}
--- trunk/KDE/kdeedu/marble/src/lib/MarbleRunnerManager.h #1226962:1226963
@@ -117,6 +117,8 @@
private:
Q_PRIVATE_SLOT( d, void cleanupSearchTask( RunnerTask* task ) );
+ Q_PRIVATE_SLOT( d, void cleanupRoutingTask( RunnerTask* task ) );
+
friend class MarbleRunnerManagerPrivate;
MarbleRunnerManagerPrivate* const d;
--- trunk/KDE/kdeedu/marble/src/lib/routing/RoutingManager.cpp #1226962:1226963
@@ -274,10 +274,12 @@
void RoutingManager::retrieveRoute( GeoDataDocument* route )
{
+ if ( route ) {
d->m_alternativeRoutesModel->addRoute( route );
+ }
if ( !d->m_haveRoute ) {
- d->m_haveRoute = true;
+ d->m_haveRoute = route != 0;
emit stateChanged( Retrieved, d->m_routeRequest );
}
--- trunk/KDE/kdeedu/marble/src/lib/routing/RoutingWidget.cpp #1226962:1226963
@@ -204,6 +204,8 @@
this, SLOT( pointSelectionCanceled() ) );
connect( d->m_routingManager, SIGNAL( stateChanged( RoutingManager::State, RouteRequest* ) ),
this, SLOT( updateRouteState( RoutingManager::State, RouteRequest* ) ) );
+ connect( d->m_routingManager, SIGNAL( routeRetrieved( GeoDataDocument* ) ),
+ this, SLOT( indicateRoutingFailure( GeoDataDocument* ) ) );
connect( d->m_routeRequest, SIGNAL( positionAdded( int ) ),
this, SLOT( insertInputWidget( int ) ) );
connect( d->m_routeRequest, SIGNAL( positionRemoved( int ) ),
@@ -244,6 +246,7 @@
addInputWidget();
}
//d->m_ui.descriptionLabel->setVisible( false );
+ d->m_ui.resultLabel->setVisible( false );
setShowDirectionsButtonVisible( false );
if ( MarbleGlobal::getInstance()->profiles() & MarbleGlobal::SmallScreen ) {
@@ -322,8 +325,15 @@
MarblePlacemarkModel *model = widget->searchResultModel();
if ( model->rowCount() ) {
+ QString const results = tr( "%n placemarks", "", model->rowCount() );
+ d->m_ui.resultLabel->setText( results );
+ d->m_ui.resultLabel->setVisible( true );
// Make sure we have a selection
activatePlacemark( model->index( 0, 0 ) );
+ } else {
+ QString const results = tr( "No placemark" );
+ d->m_ui.resultLabel->setText( "<font color=\"red\">" + results + "</font>" );
+ d->m_ui.resultLabel->setVisible( true );
}
GeoDataLineString placemarks;
@@ -499,6 +509,7 @@
d->m_currentFrame = ( d->m_currentFrame + 1 ) % d->m_progressAnimation.size();
QIcon frame = d->m_progressAnimation[d->m_currentFrame];
d->m_ui.searchButton->setIcon( frame );
+ d->m_ui.resultLabel->setVisible( false );
}
}
@@ -552,6 +563,10 @@
d->m_progressTimer.stop();
d->m_ui.searchButton->setIcon( QIcon() );
+
+ QString const results = tr( "%n routes", "", d->m_ui.routeComboBox->count() );
+ d->m_ui.resultLabel->setText( results );
+ d->m_ui.resultLabel->setVisible( true );
}
void RoutingWidget::setShowDirectionsButtonVisible( bool visible )
@@ -601,6 +616,17 @@
}
}
+void RoutingWidget::indicateRoutingFailure( GeoDataDocument* route )
+{
+ if ( !route ) {
+ d->m_progressTimer.stop();
+ d->m_ui.searchButton->setIcon( QIcon() );
+ QString const results = tr( "No route" );
+ d->m_ui.resultLabel->setText( "<font color=\"red\">" + results + "</font>" );
+ d->m_ui.resultLabel->setVisible( true );
+ }
+}
+
} // namespace Marble
#include "RoutingWidget.moc"
--- trunk/KDE/kdeedu/marble/src/lib/routing/RoutingWidget.h #1226962:1226963
@@ -126,6 +126,9 @@
/** Update the route request with the given profile */
void setRoutingProfile( int index );
+ /** Determine route retrieval failures and inform the user */
+ void indicateRoutingFailure( GeoDataDocument* route );
+
private:
RoutingWidgetPrivate *const d;
};
--- trunk/KDE/kdeedu/marble/src/lib/routing/RoutingWidget.ui #1226962:1226963
@@ -98,6 +98,13 @@
</spacer>
</item>
<item>
+ <widget class="QLabel" name="resultLabel">
+ <property name="text">
+ <string>No results.</string>
+ </property>
+ </widget>
+ </item>
+ <item>
<widget class="QPushButton" name="showInstructionsButton">
<property name="text">
<string>Show Directions</string>
More information about the Marble-commits
mailing list