Property values can now be changed.

--HG--
branch : gsoc2013-dfighter
hg/feature/gsoc2013-dfighter
dfighter1985 12 years ago
parent 9ee24b3b93
commit ea06a2c656

@ -54,7 +54,7 @@ namespace NL3D
public: public:
void addProperty( const SDynMaterialProp &prop ); void addProperty( const SDynMaterialProp &prop );
void removeProperty( const std::string &name ); void removeProperty( const std::string &name );
void changeProperty( const std::string &name, const SDynMaterialProp &prop ); bool changeProperty( const std::string &name, const SDynMaterialProp &prop );
void setName( const std::string &n ){ name = n; } void setName( const std::string &n ){ name = n; }
void getName( std::string &n ) const { n = name; } void getName( std::string &n ) const { n = name; }
void serial( NLMISC::IStream &f ); void serial( NLMISC::IStream &f );

@ -115,7 +115,7 @@ namespace NL3D
properties.erase( itr ); properties.erase( itr );
} }
void SRenderPass::changeProperty( const std::string &name, const SDynMaterialProp &prop ) bool SRenderPass::changeProperty( const std::string &name, const SDynMaterialProp &prop )
{ {
std::vector< SDynMaterialProp >::iterator itr = properties.begin(); std::vector< SDynMaterialProp >::iterator itr = properties.begin();
while( itr != properties.end() ) while( itr != properties.end() )
@ -125,12 +125,14 @@ namespace NL3D
++itr; ++itr;
} }
if( itr == properties.end() ) if( itr == properties.end() )
return; return false;
itr->prop = prop.prop; itr->prop = prop.prop;
itr->label = prop.label; itr->label = prop.label;
itr->type = prop.type; itr->type = prop.type;
itr->value = prop.value; itr->value = prop.value;
return true;
} }

@ -97,9 +97,39 @@ namespace MaterialEditor
pass->setName( name ); pass->setName( name );
} }
bool CRenderPassProxy::getProperty( const std::string &name, SMatProp &p )
{
uint32 count = pass->count();
uint32 i = 0;
for( i = 0; i < count; i++ )
{
if( pass->getProperty( i )->prop == name )
break;
}
if( i == count )
return false;
const NL3D::SDynMaterialProp *prop = pass->getProperty( i );
p.id = prop->prop;
p.label = prop->label;
p.type = prop->type;
p.value = prop->value;
return true;
}
bool CRenderPassProxy::changeProperty( const SMatProp &p )
{
NL3D::SDynMaterialProp prop;
prop.prop = p.id;
prop.label = p.label;
prop.type = p.type;
prop.value = p.value;
return pass->changeProperty( prop.prop, prop );
}
void CNelMaterialProxy::getPassList( std::vector< std::string > &l ) void CNelMaterialProxy::getPassList( std::vector< std::string > &l )
{ {

@ -72,6 +72,9 @@ namespace MaterialEditor
void getName( std::string &name ); void getName( std::string &name );
void setName( const std::string &name ); void setName( const std::string &name );
bool getProperty( const std::string &name, SMatProp &p );
bool changeProperty( const SMatProp &p );
private: private:
NL3D::SRenderPass *pass; NL3D::SRenderPass *pass;
}; };

@ -158,6 +158,8 @@ namespace MaterialEditor
nel3dIface = NULL; nel3dIface = NULL;
manager = new QtVariantPropertyManager(); manager = new QtVariantPropertyManager();
factory = new QtVariantEditorFactory(); factory = new QtVariantEditorFactory();
setupConnections();
} }
CPropBrowserCtrl::~CPropBrowserCtrl() CPropBrowserCtrl::~CPropBrowserCtrl()
@ -183,6 +185,8 @@ namespace MaterialEditor
void CPropBrowserCtrl::setupConnections() void CPropBrowserCtrl::setupConnections()
{ {
connect( manager, SIGNAL( valueChanged( QtProperty*, const QVariant& ) ),
this, SLOT( onValueChanged( QtProperty*, const QVariant& ) ) );
} }
void CPropBrowserCtrl::onPropsChanged() void CPropBrowserCtrl::onPropsChanged()
@ -194,6 +198,7 @@ namespace MaterialEditor
void CPropBrowserCtrl::clearProps() void CPropBrowserCtrl::clearProps()
{ {
browser->clear(); browser->clear();
propToId.clear();
} }
void CPropBrowserCtrl::loadPropsForPass( const QString &pass ) void CPropBrowserCtrl::loadPropsForPass( const QString &pass )
@ -228,9 +233,34 @@ namespace MaterialEditor
browser->addProperty( vp ); browser->addProperty( vp );
propToId[ vp ] = prop.id;
++itr; ++itr;
} }
} }
void CPropBrowserCtrl::onValueChanged( QtProperty *p, const QVariant &v )
{
QString label = p->propertyName();
std::string value = p->valueText().toUtf8().data();
CNelMaterialProxy m = nel3dIface->getMaterial();
CRenderPassProxy pass = m.getPass( currentPass.toUtf8().data() );
std::map< QtProperty*, std::string >::const_iterator itr
= propToId.find( p );
if( itr == propToId.end() )
return;
SMatProp prop;
bool ok = pass.getProperty( itr->second, prop );
if( !ok )
return;
prop.value = value;
pass.changeProperty( prop );
}
} }

@ -19,10 +19,13 @@
#define PROP_BROWSER_CTRL_H #define PROP_BROWSER_CTRL_H
#include <QObject> #include <QObject>
#include <QVariant>
#include <map>
class QtTreePropertyBrowser; class QtTreePropertyBrowser;
class QtVariantPropertyManager; class QtVariantPropertyManager;
class QtVariantEditorFactory; class QtVariantEditorFactory;
class QtProperty;
namespace MaterialEditor namespace MaterialEditor
{ {
@ -41,6 +44,9 @@ namespace MaterialEditor
void clearProps(); void clearProps();
void loadPropsForPass( const QString &pass ); void loadPropsForPass( const QString &pass );
private Q_SLOTS:
void onValueChanged( QtProperty *p, const QVariant &v );
private: private:
QtTreePropertyBrowser *browser; QtTreePropertyBrowser *browser;
QtVariantPropertyManager *manager; QtVariantPropertyManager *manager;
@ -48,6 +54,8 @@ namespace MaterialEditor
CNel3DInterface *nel3dIface; CNel3DInterface *nel3dIface;
QString currentPass; QString currentPass;
std::map< QtProperty*, std::string > propToId;
}; };
} }

Loading…
Cancel
Save