Commit 9e73cf09 authored by Bernhard Beschow's avatar Bernhard Beschow
Browse files

don't create new PositionProviderPlugin instances in PluginManager, just return the factory objects

* avoids having to delete all unused plugin instances
* allows for accessing plugin metadata w/o having to create + destroy new instances
parent 3b6b523a
......@@ -1147,16 +1147,14 @@ void MainWindow::readSettings(const QVariantMap& overrideSettings)
if ( !positionProvider.isEmpty() ) {
PositionTracking* tracking = m_controlView->marbleModel()->positionTracking();
const PluginManager* pluginManager = m_controlView->marbleModel()->pluginManager();
QList<PositionProviderPlugin*> plugins = pluginManager->createPositionProviderPlugins();
foreach( PositionProviderPlugin* plugin, plugins ) {
foreach( const PositionProviderPlugin* plugin, pluginManager->positionProviderPlugins() ) {
if ( plugin->nameId() == positionProvider ) {
plugins.removeOne( plugin );
plugin->setMarbleModel( m_controlView->marbleModel() );
tracking->setPositionProviderPlugin( plugin );
PositionProviderPlugin* instance = plugin->newInstance();
instance->setMarbleModel( m_controlView->marbleModel() );
tracking->setPositionProviderPlugin( instance );
break;
}
}
qDeleteAll( plugins );
}
settings.endGroup();
......
......@@ -49,7 +49,7 @@ class CurrentLocationWidgetPrivate
MarbleWidget *m_widget;
AutoNavigation *m_adjustNavigation;
QList<PositionProviderPlugin*> m_positionProviderPlugins;
QList<const PositionProviderPlugin*> m_positionProviderPlugins;
GeoDataCoordinates m_currentPosition;
QString m_lastOpenPath;
......@@ -109,7 +109,7 @@ void CurrentLocationWidget::setMarbleWidget( MarbleWidget *widget )
d->m_widget->model()->routingManager()->setAutoNavigation( d->m_adjustNavigation );
const PluginManager* pluginManager = d->m_widget->model()->pluginManager();
d->m_positionProviderPlugins = pluginManager->createPositionProviderPlugins();
d->m_positionProviderPlugins = pluginManager->positionProviderPlugins();
foreach( const PositionProviderPlugin *plugin, d->m_positionProviderPlugins ) {
d->m_currentLocationUi.positionTrackingComboBox->addItem( plugin->guiString() );
}
......@@ -293,7 +293,7 @@ void CurrentLocationWidgetPrivate::changePositionProvider( const QString &provid
bool hasProvider = ( provider != QObject::tr("Disabled") );
if ( hasProvider ) {
foreach( PositionProviderPlugin* plugin, m_positionProviderPlugins ) {
foreach( const PositionProviderPlugin* plugin, m_positionProviderPlugins ) {
if ( plugin->guiString() == provider ) {
m_currentLocationUi.locationLabel->setEnabled( true );
PositionProviderPlugin* instance = plugin->newInstance();
......
......@@ -90,10 +90,10 @@ QList<NetworkPlugin *> PluginManager::createNetworkPlugins() const
return createPlugins( d->m_networkPluginTemplates );
}
QList<PositionProviderPlugin *> PluginManager::createPositionProviderPlugins() const
QList<const PositionProviderPlugin *> PluginManager::positionProviderPlugins() const
{
d->loadPlugins();
return createPlugins( d->m_positionProviderPluginTemplates );
return d->m_positionProviderPluginTemplates;
}
QList<RunnerPlugin *> PluginManager::runnerPlugins() const
......
......@@ -62,10 +62,13 @@ class MARBLE_EXPORT PluginManager
QList<NetworkPlugin *> createNetworkPlugins() const;
/**
* This methods creates a new set of plugins and transfers ownership
* of them to the client.
* @brief Returns all available PositionProviderPlugins.
*
* Ownership of the items remains in PluginManager.
* In order to use the PositionProviderPlugins, first create new instances using
* PositionProviderPlugin::newInstance().
*/
QList<PositionProviderPlugin *> createPositionProviderPlugins() const;
QList<const PositionProviderPlugin *> positionProviderPlugins() const;
/**
* Returns all runner plugins.
......
......@@ -403,17 +403,16 @@ void RoutingManager::setGuidanceModeEnabled( bool enabled )
}
PositionTracking* tracking = d->m_marbleModel->positionTracking();
PositionProviderPlugin* plugin = tracking->positionProviderPlugin();
if ( !plugin && enabled ) {
PositionProviderPlugin* positionProvider = tracking->positionProviderPlugin();
if ( !positionProvider && enabled ) {
const PluginManager* pluginManager = d->m_marbleModel->pluginManager();
QList<PositionProviderPlugin*> plugins = pluginManager->createPositionProviderPlugins();
QList<const PositionProviderPlugin*> plugins = pluginManager->positionProviderPlugins();
if ( plugins.size() > 0 ) {
plugin = plugins.takeFirst();
positionProvider = plugins.first()->newInstance();
}
qDeleteAll( plugins );
tracking->setPositionProviderPlugin( plugin );
tracking->setPositionProviderPlugin( positionProvider );
d->m_shutdownPositionTracking = true;
} else if ( plugin && !enabled && d->m_shutdownPositionTracking ) {
} else if ( positionProvider && !enabled && d->m_shutdownPositionTracking ) {
d->m_shutdownPositionTracking = false;
tracking->setPositionProviderPlugin( 0 );
}
......
......@@ -528,16 +528,14 @@ void MarblePart::readSettings()
if ( !positionProvider.isEmpty() ) {
PositionTracking* tracking = m_controlView->marbleModel()->positionTracking();
const PluginManager* pluginManager = m_controlView->marbleModel()->pluginManager();
QList<PositionProviderPlugin*> plugins = pluginManager->createPositionProviderPlugins();
foreach( PositionProviderPlugin* plugin, plugins ) {
foreach( const PositionProviderPlugin* plugin, pluginManager->positionProviderPlugins() ) {
if ( plugin->nameId() == positionProvider ) {
plugins.removeOne( plugin );
plugin->setMarbleModel( m_controlView->marbleModel() );
tracking->setPositionProviderPlugin( plugin );
PositionProviderPlugin* instance = plugin->newInstance();
instance->setMarbleModel( m_controlView->marbleModel() );
tracking->setPositionProviderPlugin( instance );
break;
}
}
qDeleteAll( plugins );
}
readStatusBarSettings();
......
......@@ -89,8 +89,7 @@ void PositionSource::start()
}
const Marble::PluginManager* pluginManager = m_marbleModel->pluginManager();
QList<Marble::PositionProviderPlugin*> plugins = pluginManager->createPositionProviderPlugins();
foreach( const Marble::PositionProviderPlugin *plugin, plugins ) {
foreach( const Marble::PositionProviderPlugin *plugin, pluginManager->positionProviderPlugins() ) {
if ( m_source.isEmpty() || plugin->nameId() == m_source ) {
Marble::PositionProviderPlugin* instance = plugin->newInstance();
instance->setMarbleModel( m_marbleModel );
......
......@@ -346,11 +346,10 @@ void RoutingPluginPrivate::togglePositionTracking( bool enabled )
PositionProviderPlugin* plugin = 0;
if ( enabled ) {
const PluginManager* pluginManager = m_marbleWidget->model()->pluginManager();
QList<PositionProviderPlugin*> plugins = pluginManager->createPositionProviderPlugins();
QList<const PositionProviderPlugin*> plugins = pluginManager->positionProviderPlugins();
if ( plugins.size() > 0 ) {
plugin = plugins.takeFirst();
plugin = plugins.first()->newInstance();
}
qDeleteAll( plugins );
}
m_parent->marbleModel()->positionTracking()->setPositionProviderPlugin( plugin );
}
......
......@@ -66,17 +66,11 @@ PlacemarkPositionProviderPluginTest::PlacemarkPositionProviderPluginTest() :
PositionProviderPlugin *PlacemarkPositionProviderPluginTest::createUninitializedPlugin( const PluginManager *pluginManager )
{
QList<PositionProviderPlugin *> plugins = pluginManager->createPositionProviderPlugins();
while ( !plugins.isEmpty() ) {
PositionProviderPlugin *const plugin = plugins.takeFirst();
foreach ( const PositionProviderPlugin *plugin, pluginManager->positionProviderPlugins() ) {
if ( plugin->nameId() == "Placemark" ) {
qDeleteAll( plugins );
return plugin;
PositionProviderPlugin *instance = plugin->newInstance();
return instance;
}
delete plugin;
}
return 0;
......
......@@ -34,7 +34,7 @@ void PluginManagerTest::loadPlugins()
PluginManager pm;
const int renderPlugins = pm.renderPlugins().size();
const int networkPlugins = pm.createNetworkPlugins().size();
const int positionPlugins = pm.createPositionProviderPlugins().size();
const int positionPlugins = pm.positionProviderPlugins().size();
const int runnerPlugins = pm.runnerPlugins().size();
QCOMPARE( renderPlugins + networkPlugins + positionPlugins + runnerPlugins, pluginNumber );
......
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