Commit a22716de authored by Bernhard Beschow's avatar Bernhard Beschow
Browse files

remove RoutingTask base class for simplicity

* also, more specific type-checking is performed during compilation
parent 2712b7e9
......@@ -62,10 +62,10 @@ public:
template<typename T>
QList<T*> plugins( const QList<T*> &plugins );
QList<RunnerTask*> m_searchTasks;
QList<RunnerTask*> m_reverseTasks;
QList<RunnerTask*> m_routingTasks;
QList<RunnerTask*> m_parsingTasks;
QList<SearchTask*> m_searchTasks;
QList<ReverseGeocodingTask*> m_reverseTasks;
QList<RoutingTask*> m_routingTasks;
QList<ParsingTask*> m_parsingTasks;
int m_watchdogTimer;
void addSearchResult( QVector<GeoDataPlacemark*> result );
......@@ -73,10 +73,10 @@ public:
void addRoutingResult( GeoDataDocument* route );
void addParsingResult( GeoDataDocument* document, const QString& error = QString() );
void cleanupSearchTask( RunnerTask* task );
void cleanupReverseGeocodingTask( RunnerTask* task );
void cleanupRoutingTask( RunnerTask* task );
void cleanupParsingTask( RunnerTask* task );
void cleanupSearchTask( SearchTask* task );
void cleanupReverseGeocodingTask( ReverseGeocodingTask* task );
void cleanupRoutingTask( RoutingTask* task );
void cleanupParsingTask( ParsingTask* task );
};
......@@ -124,7 +124,7 @@ QList<T*> MarbleRunnerManagerPrivate::plugins( const QList<T*> &plugins )
return result;
}
void MarbleRunnerManagerPrivate::cleanupSearchTask( RunnerTask* task )
void MarbleRunnerManagerPrivate::cleanupSearchTask( SearchTask* task )
{
m_searchTasks.removeAll( task );
mDebug() << "removing search task" << m_searchTasks.size() << (long)task;
......@@ -138,7 +138,7 @@ void MarbleRunnerManagerPrivate::cleanupSearchTask( RunnerTask* task )
}
}
void MarbleRunnerManagerPrivate::cleanupReverseGeocodingTask( RunnerTask* task )
void MarbleRunnerManagerPrivate::cleanupReverseGeocodingTask( ReverseGeocodingTask* task )
{
m_reverseTasks.removeAll( task );
mDebug() << "removing task " << m_reverseTasks.size() << " " << (long)task;
......@@ -147,7 +147,7 @@ void MarbleRunnerManagerPrivate::cleanupReverseGeocodingTask( RunnerTask* task )
}
}
void MarbleRunnerManagerPrivate::cleanupRoutingTask( RunnerTask* task )
void MarbleRunnerManagerPrivate::cleanupRoutingTask( RoutingTask* task )
{
m_routingTasks.removeAll( task );
mDebug() << "removing task " << m_routingTasks.size() << " " << (long)task;
......@@ -160,7 +160,7 @@ void MarbleRunnerManagerPrivate::cleanupRoutingTask( RunnerTask* task )
}
}
void MarbleRunnerManagerPrivate::cleanupParsingTask( RunnerTask* task )
void MarbleRunnerManagerPrivate::cleanupParsingTask( ParsingTask* task )
{
m_parsingTasks.removeAll( task );
mDebug() << "removing task " << m_parsingTasks.size() << " " << (long)task;
......@@ -213,7 +213,7 @@ void MarbleRunnerManager::findPlacemarks( const QString &searchTerm, const GeoDa
QList<const SearchRunnerPlugin*> plugins = d->plugins( d->m_pluginManager->searchRunnerPlugins() );
foreach( const SearchRunnerPlugin* plugin, plugins ) {
SearchTask* task = new SearchTask( plugin->newRunner(), this, d->m_marbleModel, searchTerm, preferred );
connect( task, SIGNAL( finished( RunnerTask* ) ), this, SLOT( cleanupSearchTask( RunnerTask* ) ) );
connect( task, SIGNAL( finished( SearchTask * ) ), this, SLOT( cleanupSearchTask( SearchTask * ) ) );
d->m_searchTasks << task;
mDebug() << "search task " << plugin->nameId() << " " << (long)task;
QThreadPool::globalInstance()->start( task );
......@@ -282,7 +282,7 @@ void MarbleRunnerManager::reverseGeocoding( const GeoDataCoordinates &coordinate
QList<const ReverseGeocodingRunnerPlugin*> plugins = d->plugins( d->m_pluginManager->reverseGeocodingRunnerPlugins() );
foreach( const ReverseGeocodingRunnerPlugin* plugin, plugins ) {
ReverseGeocodingTask* task = new ReverseGeocodingTask( plugin->newRunner(), this, d->m_marbleModel, coordinates );
connect( task, SIGNAL( finished( RunnerTask* ) ), this, SLOT( cleanupReverseGeocodingTask(RunnerTask*) ) );
connect( task, SIGNAL( finished( ReverseGeocodingTask * ) ), this, SLOT( cleanupReverseGeocodingTask( ReverseGeocodingTask * ) ) );
mDebug() << "reverse task " << plugin->nameId() << " " << (long)task;
d->m_reverseTasks << task;
QThreadPool::globalInstance()->start( task );
......@@ -336,7 +336,7 @@ void MarbleRunnerManager::retrieveRoute( const RouteRequest *request )
}
RoutingTask* task = new RoutingTask( plugin->newRunner(), this, d->m_marbleModel, request );
connect( task, SIGNAL( finished( RunnerTask* ) ), this, SLOT( cleanupRoutingTask( RunnerTask* ) ) );
connect( task, SIGNAL( finished( RoutingTask * ) ), this, SLOT( cleanupRoutingTask( RoutingTask * ) ) );
mDebug() << "route task " << plugin->nameId() << " " << (long)task;
d->m_routingTasks << task;
QThreadPool::globalInstance()->start( task );
......@@ -379,18 +379,18 @@ void MarbleRunnerManager::parseFile( const QString &fileName, DocumentRole role
const QString suffix = fileInfo.suffix().toLower();
const QString completeSuffix = fileInfo.completeSuffix().toLower();
QList<RunnerTask *> parsingTasks;
QList<ParsingTask *> parsingTasks;
foreach( const ParseRunnerPlugin *plugin, plugins ) {
QStringList const extensions = plugin->fileExtensions();
if ( extensions.isEmpty() || extensions.contains( suffix ) || extensions.contains( completeSuffix ) ) {
ParsingTask *task = new ParsingTask( plugin->newRunner(), this, fileName, role );
connect( task, SIGNAL( finished( RunnerTask* ) ), this, SLOT( cleanupParsingTask(RunnerTask*) ) );
connect( task, SIGNAL( finished( ParsingTask * ) ), this, SLOT( cleanupParsingTask( ParsingTask * ) ) );
mDebug() << "parse task " << plugin->nameId() << " " << (long)task;
parsingTasks << task;
}
}
foreach ( RunnerTask *task, parsingTasks ) {
foreach ( ParsingTask *task, parsingTasks ) {
d->m_parsingTasks << task;
QThreadPool::globalInstance()->start( task );
}
......
......@@ -30,7 +30,10 @@ class GeoDataPlacemark;
class MarbleModel;
class PluginManager;
class RouteRequest;
class RunnerTask;
class ParsingTask;
class ReverseGeocodingTask;
class RoutingTask;
class SearchTask;
class MarbleRunnerManagerPrivate;
class MARBLE_EXPORT MarbleRunnerManager : public QObject
......@@ -151,10 +154,10 @@ private:
Q_PRIVATE_SLOT( d, void addRoutingResult( GeoDataDocument* route ) )
Q_PRIVATE_SLOT( d, void addParsingResult( GeoDataDocument* document, const QString& error = QString() ) )
Q_PRIVATE_SLOT( d, void cleanupSearchTask( RunnerTask* task ) )
Q_PRIVATE_SLOT( d, void cleanupReverseGeocodingTask( RunnerTask* task ) )
Q_PRIVATE_SLOT( d, void cleanupRoutingTask( RunnerTask* task ) )
Q_PRIVATE_SLOT( d, void cleanupParsingTask( RunnerTask* task ) )
Q_PRIVATE_SLOT( d, void cleanupSearchTask( SearchTask* task ) )
Q_PRIVATE_SLOT( d, void cleanupReverseGeocodingTask( ReverseGeocodingTask* task ) )
Q_PRIVATE_SLOT( d, void cleanupRoutingTask( RoutingTask* task ) )
Q_PRIVATE_SLOT( d, void cleanupParsingTask( ParsingTask* task ) )
friend class MarbleRunnerManagerPrivate;
......
......@@ -20,26 +20,8 @@
namespace Marble
{
RunnerTask::RunnerTask( MarbleRunnerManager *manager ) :
m_manager( manager )
{
// nothing to do
}
void RunnerTask::run()
{
runTask();
emit finished( this );
}
MarbleRunnerManager *RunnerTask::manager()
{
return m_manager;
}
SearchTask::SearchTask( MarbleAbstractRunner *runner, MarbleRunnerManager *manager, MarbleModel *model, const QString &searchTerm, const GeoDataLatLonAltBox &preferred ) :
RunnerTask( manager ),
QObject(),
m_runner( runner ),
m_searchTerm( searchTerm ),
m_preferredBbox( preferred )
......@@ -49,14 +31,16 @@ SearchTask::SearchTask( MarbleAbstractRunner *runner, MarbleRunnerManager *manag
m_runner->setModel( model );
}
void SearchTask::runTask()
void SearchTask::run()
{
m_runner->search( m_searchTerm, m_preferredBbox );
m_runner->deleteLater();
emit finished( this );
}
ReverseGeocodingTask::ReverseGeocodingTask( MarbleAbstractRunner *runner, MarbleRunnerManager *manager, MarbleModel *model, const GeoDataCoordinates &coordinates ) :
RunnerTask( manager ),
QObject(),
m_runner( runner ),
m_coordinates( coordinates )
{
......@@ -65,14 +49,16 @@ ReverseGeocodingTask::ReverseGeocodingTask( MarbleAbstractRunner *runner, Marble
m_runner->setModel( model );
}
void ReverseGeocodingTask::runTask()
void ReverseGeocodingTask::run()
{
m_runner->reverseGeocoding( m_coordinates );
m_runner->deleteLater();
emit finished( this );
}
RoutingTask::RoutingTask( MarbleAbstractRunner *runner, MarbleRunnerManager *manager, MarbleModel *model, const RouteRequest* routeRequest ) :
RunnerTask( manager ),
QObject(),
m_runner( runner ),
m_routeRequest( routeRequest )
{
......@@ -81,14 +67,16 @@ RoutingTask::RoutingTask( MarbleAbstractRunner *runner, MarbleRunnerManager *man
m_runner->setModel( model );
}
void RoutingTask::runTask()
void RoutingTask::run()
{
m_runner->retrieveRoute( m_routeRequest );
m_runner->deleteLater();
emit finished( this );
}
ParsingTask::ParsingTask( MarbleAbstractRunner *runner, MarbleRunnerManager *manager, const QString& fileName, DocumentRole role ) :
RunnerTask( manager ),
QObject(),
m_runner( runner ),
m_fileName( fileName ),
m_role( role )
......@@ -97,10 +85,12 @@ ParsingTask::ParsingTask( MarbleAbstractRunner *runner, MarbleRunnerManager *man
manager, SLOT( addParsingResult( GeoDataDocument*, QString ) ) );
}
void ParsingTask::runTask()
void ParsingTask::run()
{
m_runner->parseFile( m_fileName, m_role );
m_runner->deleteLater();
emit finished( this );
}
}
......
......@@ -26,44 +26,21 @@ class RouteRequest;
class MarbleAbstractRunner;
class MarbleRunnerManager;
/**
* An abstract QRunnable that executes one of the MarbleAbstractRunner tasks -- placemark
* search, reverse geocoding or routing -- in the run() function and waits for the
* result in a local event loop.
*/
class RunnerTask : public QObject, public QRunnable
{
Q_OBJECT
public:
/** Constructor. The runner instance given will be used to execute the actual task */
explicit RunnerTask( MarbleRunnerManager *manager );
/** 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() = 0;
MarbleRunnerManager *manager();
private:
MarbleRunnerManager *const m_manager;
};
/** A RunnerTask that executes a placemark search */
class SearchTask : public RunnerTask
class SearchTask : public QObject, public QRunnable
{
Q_OBJECT
public:
SearchTask( MarbleAbstractRunner *runner, MarbleRunnerManager *manager, MarbleModel *model, const QString &searchTerm, const GeoDataLatLonAltBox &preferred );
virtual void runTask();
/**
* @reimp
*/
void run();
Q_SIGNALS:
void finished( SearchTask *task );
private:
MarbleAbstractRunner *const m_runner;
......@@ -72,14 +49,20 @@ private:
};
/** A RunnerTask that executes reverse geocoding */
class ReverseGeocodingTask : public RunnerTask
class ReverseGeocodingTask : public QObject, public QRunnable
{
Q_OBJECT
public:
ReverseGeocodingTask( MarbleAbstractRunner *runner, MarbleRunnerManager *manager, MarbleModel *model, const GeoDataCoordinates &coordinates );
virtual void runTask();
/**
* @reimp
*/
void run();
Q_SIGNALS:
void finished( ReverseGeocodingTask *task );
private:
MarbleAbstractRunner *const m_runner;
......@@ -88,14 +71,20 @@ private:
/** A RunnerTask that executes a route calculation */
class RoutingTask : public RunnerTask
class RoutingTask : public QObject, public QRunnable
{
Q_OBJECT
public:
RoutingTask( MarbleAbstractRunner *runner, MarbleRunnerManager *manager, MarbleModel *model, const RouteRequest* routeRequest );
virtual void runTask();
/**
* @reimp
*/
void run();
Q_SIGNALS:
void finished( RoutingTask *task );
private:
MarbleAbstractRunner *const m_runner;
......@@ -103,14 +92,20 @@ private:
};
/** A RunnerTask that executes a file Parsing */
class ParsingTask : public RunnerTask
class ParsingTask : public QObject, public QRunnable
{
Q_OBJECT
public:
ParsingTask( MarbleAbstractRunner *runner, MarbleRunnerManager *manager, const QString& fileName, DocumentRole role );
virtual void runTask();
/**
* @reimp
*/
void run();
Q_SIGNALS:
void finished( ParsingTask *task );
private:
MarbleAbstractRunner *const m_runner;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment