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

don't create RenderPlugins in PluginManager, just return the factory objects

* allows for accessing RenderPlugin metadata w/o having to create + destroy new instances
parent df889a58
......@@ -46,7 +46,7 @@ bool zValueLessThan( const LayerInterface * const one, const LayerInterface * co
class LayerManagerPrivate
{
public:
LayerManagerPrivate( const MarbleModel* model );
LayerManagerPrivate();
~LayerManagerPrivate();
GeoSceneDocument *m_mapTheme;
......@@ -59,9 +59,9 @@ class LayerManagerPrivate
bool m_showBackground;
};
LayerManagerPrivate::LayerManagerPrivate( const MarbleModel* model )
LayerManagerPrivate::LayerManagerPrivate()
: m_mapTheme( 0 ),
m_renderPlugins( model->pluginManager()->createRenderPlugins( model ) ),
m_renderPlugins(),
m_showBackground( true )
{
}
......@@ -74,11 +74,13 @@ LayerManagerPrivate::~LayerManagerPrivate()
LayerManager::LayerManager( const MarbleModel* model, QObject *parent )
: QObject( parent ),
d( new LayerManagerPrivate( model ) )
d( new LayerManagerPrivate )
{
foreach ( const RenderPlugin *factory, model->pluginManager()->renderPlugins() ) {
RenderPlugin *const renderPlugin = factory->newInstance( model );
Q_ASSERT( renderPlugin && "Plugin returned null when requesting a new instance." );
d->m_renderPlugins.append( renderPlugin );
// get float items and data plugins
foreach( RenderPlugin * renderPlugin, d->m_renderPlugins ) {
connect( renderPlugin, SIGNAL( settingsChanged( QString ) ),
this, SIGNAL( pluginSettingsChanged() ) );
connect( renderPlugin, SIGNAL( settingsChanged( QString ) ),
......@@ -86,11 +88,13 @@ LayerManager::LayerManager( const MarbleModel* model, QObject *parent )
connect( renderPlugin, SIGNAL( repaintNeeded( QRegion ) ),
this, SIGNAL( repaintNeeded( QRegion ) ) );
// get float items ...
AbstractFloatItem * const floatItem =
qobject_cast<AbstractFloatItem *>( renderPlugin );
if ( floatItem )
d->m_floatItems.append( floatItem );
// ... and data plugins
AbstractDataPlugin * const dataPlugin =
qobject_cast<AbstractDataPlugin *>( renderPlugin );
if( dataPlugin )
......
......@@ -78,19 +78,10 @@ QList<T*> createPlugins( const QList<const T*> &factories )
return result;
}
QList<RenderPlugin *> PluginManager::createRenderPlugins( const MarbleModel *marbleModel ) const
QList<const RenderPlugin *> PluginManager::renderPlugins() const
{
d->loadPlugins();
QList<RenderPlugin *> result;
foreach ( const RenderPlugin *factory, d->m_renderPluginTemplates ) {
RenderPlugin *instance = factory->newInstance( marbleModel );
Q_ASSERT( instance && "Plugin returned null when requesting a new instance." );
result.append( instance );
}
return result;
return d->m_renderPluginTemplates;
}
QList<NetworkPlugin *> PluginManager::createNetworkPlugins() const
......
......@@ -20,7 +20,6 @@ namespace Marble
{
class RenderPlugin;
class MarbleModel;
class NetworkPlugin;
class PositionProviderPlugin;
class AbstractFloatItem;
......@@ -32,7 +31,7 @@ class RunnerPlugin;
*
* Ownership policy for plugins:
*
* On every invocation of createRenderPlugins, createNetworkPlugins and
* On every invocation of createNetworkPlugins and
* createFloatItems the PluginManager creates new objects and transfers
* ownership to the calling site. In order to create
* the objects, the PluginManager internally has a list of the plugins
......@@ -48,10 +47,13 @@ class MARBLE_EXPORT PluginManager
~PluginManager();
/**
* This methods creates a new set of plugins and transfers ownership
* of them to the client.
* @brief Returns all available RenderPlugins.
*
* Ownership of the items remains in PluginManager.
* In order to use the RenderPlugins, first create new instances using
* RenderPlugin::newInstance().
*/
QList<RenderPlugin *> createRenderPlugins( const MarbleModel *marbleModel ) const;
QList<const RenderPlugin *> renderPlugins() const;
/**
* This methods creates a new set of plugins and transfers ownership
......
......@@ -31,10 +31,8 @@ void PluginManagerTest::loadPlugins()
const int pluginNumber = MarbleDirs::pluginEntryList( "", QDir::Files ).size();
MarbleModel model;
PluginManager pm;
const int renderPlugins = pm.createRenderPlugins( &model ).size();
const int renderPlugins = pm.renderPlugins().size();
const int networkPlugins = pm.createNetworkPlugins().size();
const int positionPlugins = pm.createPositionProviderPlugins().size();
const int runnerPlugins = pm.runnerPlugins().size();
......
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