Commit 008f705e authored by Frédéric Larue's avatar Frédéric Larue

Modification of UIData to make it allocate by itself display options when they are required.

parent d7ad060a
......@@ -373,19 +373,7 @@ DisplayableInterface* GLViewer::addDisplayable( GenericUIData *m )
{
makeCurrent();
if( !m->GetDisplayOptions() )
{
UIParamSet *params = new UIParamSet( m->GetBaseName(), NULL );
displayable->declareParameters( *params );
if( displayable->isAnimated() )
params->Add( new UIParamAnimation() );
params->updateChildrenLists( m );
m->SetDisplayOptions( params );
}
else if( displayable->isAnimated() && !m->GetDisplayOptions()->GetAnimationCtrl() )
if( displayable->isAnimated() && !m->GetDisplayOptions()->GetAnimationCtrl() )
m->GetDisplayOptions()->Add( new UIParamAnimation() );
connect( m->GetDisplayOptions(), SIGNAL(parameterUpdated(UIParam*)), this, SLOT(update()) );
......
......@@ -385,7 +385,10 @@ void UIMainWindow::loadPlugins()
QVector<QString> acceptedTypes;
dispFactory->acceptedDataTypes( acceptedTypes );
for( auto &type : acceptedTypes )
m_DisplayableFactoryByTypes[ type ] = dispFactory;
{
UIDataFactories[type]->SetDisplayPlugin( dispFactory );
m_DisplayableFactoryByTypes[type] = dispFactory;
}
}
ExportInterface *exporter = qobject_cast<ExportInterface*>( plugin );
......@@ -1180,13 +1183,8 @@ bool UIMainWindow::loadProjectOptions( const QString &filePath, UIProject *proje
QString id = attr.value("Id").toString();
QString value = attr.value("Value").toString();
GenericUIData *d = project->GetByFilename( source );
if( d )
{
if( !d->GetDisplayOptions() )
m_DisplayableFactoryByTypes[ d->GetTypeString() ]->allocateDisplayOptions( d );
d->GetDisplayOptions()->SetValueString( id, value );
}
if( GenericUIData *d = project->GetByFilename(source) )
d->SetDisplayOptionValue( id, value );
break;
}
......
......@@ -197,14 +197,21 @@ public:
/** Creates an instance of a displayer object with the correct type. */
virtual DisplayableInterface* newDisplayer( GenericUIData *m, GLViewer *v ) const = 0;
inline void allocateDisplayOptions( GenericUIData *d ) const
inline UIParamSet* allocateDisplayOptions( GenericUIData *d ) const
{
DisplayableInterface *disp = newDisplayer( d, NULL );
UIParamSet *params = new UIParamSet( d->GetBaseName(), NULL );
disp->declareParameters( *params );
if( disp->isAnimated() )
params->Add( new UIParamAnimation() );
params->updateChildrenLists( d );
d->SetDisplayOptions( params );
delete disp;
return params;
}
};
......
......@@ -6,6 +6,7 @@
*/
#include <Interfaces/DisplayableInterface.h>
#include "UIData.h"
......@@ -18,6 +19,7 @@ QMap<QString,GenericUIDataBuilder*> UIDATA_API UIDataFactories;
GenericUIData::GenericUIData( const QString &typeString, const QString &filename ) :
m_TypeString( typeString ),
m_Factory(UIDataFactories[typeString]),
m_DisplayOptions( NULL ),
m_Parent( NULL ),
m_Project( NULL ),
......@@ -106,6 +108,21 @@ void GenericUIData::SetProject( UIProject *proj )
}
UIParamSet* GenericUIData::GetDisplayOptions() const
{
if( !m_DisplayOptions && GetFactory()->GetDisplayPlugin() )
m_DisplayOptions = GetFactory()->GetDisplayPlugin()->allocateDisplayOptions( (GenericUIData*) this );
return m_DisplayOptions;
}
void GenericUIData::SetDisplayOptionValue( const QString &paramName, const QString &valueString )
{
if( UIParamSet* opt = GetDisplayOptions() )
opt->SetValueString( paramName, valueString );
}
void GenericUIData::SetParent( GenericUIData* p )
{
if( p != m_Parent )
......
......@@ -17,6 +17,40 @@
#include <QtCore>
#include "../UIParam/UIParamSet.h"
class GenericUIData;
class DisplayableFactoryInterface;
class UIDATA_API GenericUIDataBuilder
{
QString m_TypeString;
DisplayableFactoryInterface *m_DisplayPlugin;
public:
inline GenericUIDataBuilder( const QString& typeString ) : m_TypeString(typeString), m_DisplayPlugin(NULL) {}
inline void SetDisplayPlugin( DisplayableFactoryInterface *plugin ) { m_DisplayPlugin = plugin; }
inline DisplayableFactoryInterface* GetDisplayPlugin() const { return m_DisplayPlugin; }
inline const QString& GetTypeString() const { return m_TypeString; }
virtual GenericUIData* Create( void* content, const QString& filename ) = 0;
};
template <typename T>
class UIDataBuilder : public GenericUIDataBuilder
{
public:
inline UIDataBuilder( const QString& typeString ) : GenericUIDataBuilder(typeString) {}
virtual GenericUIData* Create( void* content, const QString& filename );
};
extern QMap<QString,GenericUIDataBuilder*> UIDATA_API UIDataFactories;
......@@ -28,13 +62,14 @@ protected:
using UIDataList = QList< GenericUIData* >;
QString m_TypeString;
GenericUIDataBuilder *m_Factory;
QString m_Path;
QString m_FileName;
QString m_BaseName;
QString m_Suffix;
UIParamSet* m_DisplayOptions;
mutable UIParamSet* m_DisplayOptions;
UIProject* m_Project;
GenericUIData* m_Parent;
......@@ -49,6 +84,7 @@ public:
virtual ~GenericUIData();
inline const QString& GetTypeString() const { return m_TypeString; }
inline GenericUIDataBuilder*GetFactory() const { return m_Factory; }
inline const QString& GetPath() const { return m_Path; }
inline const QString& GetFileName() const { return m_FileName; }
......@@ -69,8 +105,8 @@ public:
template <typename T>
inline bool IsOfType() const;
inline UIParamSet* GetDisplayOptions() const { return m_DisplayOptions; }
inline void SetDisplayOptions( UIParamSet *params ) { m_DisplayOptions = params; }
UIParamSet* GetDisplayOptions() const;
void SetDisplayOptionValue( const QString &paramName, const QString &valueString );
inline bool HasParent() const { return m_Parent != NULL; }
void SetParent( GenericUIData* p );
......@@ -90,31 +126,6 @@ public:
class UIDATA_API GenericUIDataBuilder
{
QString m_TypeString;
public:
inline GenericUIDataBuilder( const QString& typeString ) : m_TypeString( typeString ) {}
inline const QString& GetTypeString() const { return m_TypeString; }
virtual GenericUIData* Create( void* content, const QString& filename ) = 0;
};
template <typename T>
class UIDataBuilder : public GenericUIDataBuilder
{
public:
inline UIDataBuilder( const QString& typeString ) : GenericUIDataBuilder( typeString ) {}
virtual GenericUIData* Create( void* content, const QString& filename );
};
extern QMap<QString,GenericUIDataBuilder*> UIDATA_API UIDataFactories;
template <typename T>
class UIDATA_API UIData : public GenericUIData
{
......
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