[Marble-commits] KDE/kdeedu/marble/src/lib
Dennis Nienhüser
earthwings at gentoo.org
Sun Apr 3 14:38:46 CEST 2011
SVN commit 1226962 by nienhueser:
More reliable detection that all search runners have finished. Fixes endless spinning of search progress animation.
M +27 -12 MarbleRunnerManager.cpp
M +5 -0 MarbleRunnerManager.h
M +4 -3 RunnerTask.cpp
M +6 -1 RunnerTask.h
--- trunk/KDE/kdeedu/marble/src/lib/MarbleRunnerManager.cpp #1226961:1226962
@@ -25,6 +25,7 @@
#include <QtCore/QString>
#include <QtCore/QVector>
#include <QtCore/QThreadPool>
+#include <QtCore/QTimer>
namespace Marble
{
@@ -34,11 +35,11 @@
class MarbleRunnerManagerPrivate
{
public:
+ MarbleRunnerManager* q;
QString m_lastSearchTerm;
QMutex m_modelMutex;
MarbleModel * m_marbleModel;
MarblePlacemarkModel *m_model;
- int m_searchTasks;
QVector<GeoDataPlacemark*> m_placemarkContainer;
QVector<GeoDataDocument*> m_routingResult;
QList<GeoDataCoordinates> m_reverseGeocodingResults;
@@ -46,16 +47,21 @@
bool m_workOffline;
PluginManager* m_pluginManager;
- MarbleRunnerManagerPrivate( PluginManager* pluginManager );
+ MarbleRunnerManagerPrivate( MarbleRunnerManager* parent, PluginManager* pluginManager );
~MarbleRunnerManagerPrivate();
QList<RunnerPlugin*> plugins( RunnerPlugin::Capability capability );
+
+ QList<RunnerTask*> m_searchTasks;
+
+ void cleanupSearchTask( RunnerTask* task );
};
-MarbleRunnerManagerPrivate::MarbleRunnerManagerPrivate( PluginManager* pluginManager ) :
+
+MarbleRunnerManagerPrivate::MarbleRunnerManagerPrivate( MarbleRunnerManager* parent, PluginManager* pluginManager ) :
+ q( parent ),
m_marbleModel( 0 ),
m_model( new MarblePlacemarkModel ),
- m_searchTasks( 0 ),
m_routeRequest( 0 ),
m_workOffline( false ),
m_pluginManager( pluginManager )
@@ -99,8 +105,17 @@
return result;
}
+void MarbleRunnerManagerPrivate::cleanupSearchTask( RunnerTask* task )
+{
+ m_searchTasks.removeAll( task );
+
+ if ( m_searchTasks.isEmpty() ) {
+ emit q->searchFinished( m_lastSearchTerm );
+ }
+}
+
MarbleRunnerManager::MarbleRunnerManager( PluginManager* pluginManager, QObject *parent )
- : QObject( parent ), d( new MarbleRunnerManagerPrivate( pluginManager ) )
+ : QObject( parent ), d( new MarbleRunnerManagerPrivate( this, pluginManager ) )
{
// nothing to do
}
@@ -137,8 +152,10 @@
d->m_lastSearchTerm = searchTerm;
+ qDeleteAll( d->m_searchTasks );
+ d->m_searchTasks.clear();
+
d->m_modelMutex.lock();
- d->m_searchTasks = 0;
d->m_model->removePlacemarks( "MarbleRunnerManager", 0, d->m_placemarkContainer.size() );
qDeleteAll( d->m_placemarkContainer );
d->m_placemarkContainer.clear();
@@ -151,7 +168,10 @@
connect( runner, SIGNAL( searchFinished( QVector<GeoDataPlacemark*> ) ),
this, SLOT( addSearchResult( QVector<GeoDataPlacemark*> ) ) );
runner->setModel( d->m_marbleModel );
- QThreadPool::globalInstance()->start( new SearchTask( runner, searchTerm ) );
+ SearchTask* task = new SearchTask( runner, searchTerm );
+ connect( task, SIGNAL( finished( RunnerTask* ) ), this, SLOT( cleanupSearchTask( RunnerTask* ) ) );
+ d->m_searchTasks << task;
+ QThreadPool::globalInstance()->start( task );
}
}
@@ -162,17 +182,12 @@
return;
d->m_modelMutex.lock();
- --d->m_searchTasks;
int start = d->m_placemarkContainer.size();
d->m_placemarkContainer << result;
d->m_model->addPlacemarks( start, result.size() );
d->m_modelMutex.unlock();
emit searchResultChanged( d->m_model );
-
- if ( d->m_searchTasks <= 0 ) {
- emit searchFinished( d->m_lastSearchTerm );
}
-}
void MarbleRunnerManager::setModel( MarbleModel * model )
{
--- trunk/KDE/kdeedu/marble/src/lib/MarbleRunnerManager.h #1226961:1226962
@@ -28,6 +28,7 @@
class MarbleModel;
class PluginManager;
class RouteRequest;
+class RunnerTask;
class MarbleRunnerManagerPrivate;
class MARBLE_EXPORT MarbleRunnerManager : public QObject
@@ -114,6 +115,10 @@
void addRoutingResult( GeoDataDocument* route );
private:
+ Q_PRIVATE_SLOT( d, void cleanupSearchTask( RunnerTask* task ) );
+
+ friend class MarbleRunnerManagerPrivate;
+
MarbleRunnerManagerPrivate* const d;
};
--- trunk/KDE/kdeedu/marble/src/lib/RunnerTask.cpp #1226961:1226962
@@ -30,11 +30,10 @@
watchdog.stop(); // completed within timeout
} else {
mDebug() << "Timeout reached while waiting for result. Killing the runner.";
- /** @todo: Report back to MarbleRunnerManager to announce finish without
- * results, if needed
- */
runner()->deleteLater();
}
+
+ emit finished( this );
}
MarbleAbstractRunner* RunnerTask::runner()
@@ -82,3 +81,5 @@
}
}
+
+#include "RunnerTask.moc"
--- trunk/KDE/kdeedu/marble/src/lib/RunnerTask.h #1226961:1226962
@@ -27,8 +27,10 @@
* search, reverse geocoding or routing -- in the run() function and waits for the
* result in a local event loop.
*/
-class RunnerTask : public QRunnable
+class RunnerTask : public QObject, public QRunnable
{
+ Q_OBJECT
+
public:
/** Constructor. The runner instance given will be used to execute the actual task */
explicit RunnerTask( MarbleAbstractRunner* runner );
@@ -36,6 +38,9 @@
/** Overriding QRunnable to execute the runner task in a local event loop */
virtual void run();
+Q_SIGNALS:
+ void finished( RunnerTask* task );
+
protected:
/** Derived classes should execute their task and quit the provided event loop when done */
virtual void runTask( QEventLoop *localEventLoop ) = 0;
More information about the Marble-commits
mailing list