mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-12-21 08:28:44 +00:00
CHANGED: #1471 The property browser widget can now actually change properties.
This commit is contained in:
parent
607a3f188a
commit
d562a50ceb
4 changed files with 72 additions and 1 deletions
|
@ -237,7 +237,33 @@ inline bool fromString(const std::string &str, uint64 &val) { bool ret = sscanf(
|
||||||
inline bool fromString(const std::string &str, sint64 &val) { bool ret = sscanf(str.c_str(), "%"NL_I64"d", &val) == 1; if (!ret) val = 0; return ret; }
|
inline bool fromString(const std::string &str, sint64 &val) { bool ret = sscanf(str.c_str(), "%"NL_I64"d", &val) == 1; if (!ret) val = 0; return ret; }
|
||||||
inline bool fromString(const std::string &str, float &val) { bool ret = sscanf(str.c_str(), "%f", &val) == 1; if (!ret) val = 0.0f; return ret; }
|
inline bool fromString(const std::string &str, float &val) { bool ret = sscanf(str.c_str(), "%f", &val) == 1; if (!ret) val = 0.0f; return ret; }
|
||||||
inline bool fromString(const std::string &str, double &val) { bool ret = sscanf(str.c_str(), "%lf", &val) == 1; if (!ret) val = 0.0; return ret; }
|
inline bool fromString(const std::string &str, double &val) { bool ret = sscanf(str.c_str(), "%lf", &val) == 1; if (!ret) val = 0.0; return ret; }
|
||||||
inline bool fromString(const std::string &str, bool &val) { val = (str.length() == 1) && str[0] != '0'; return (str.length() == 1) && (str[0] == '0' || str[0] == '1'); }
|
|
||||||
|
inline bool fromString(const std::string &str, bool &val)
|
||||||
|
{
|
||||||
|
if( str.length() == 1 )
|
||||||
|
{
|
||||||
|
if( str[ 0 ] == '1' )
|
||||||
|
val = true;
|
||||||
|
else
|
||||||
|
if( str[ 0 ] == '0' )
|
||||||
|
val = false;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if( str == "true" )
|
||||||
|
val = true;
|
||||||
|
else
|
||||||
|
if( str == "false" )
|
||||||
|
val = false;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
inline bool fromString(const std::string &str, std::string &val) { val = str; return true; }
|
inline bool fromString(const std::string &str, std::string &val) { val = str; return true; }
|
||||||
|
|
||||||
// stl vectors of bool use bit reference and not real bools, so define the operator for bit reference
|
// stl vectors of bool use bit reference and not real bools, so define the operator for bit reference
|
||||||
|
|
|
@ -166,6 +166,7 @@ namespace NLGUI
|
||||||
if( name == "id" )
|
if( name == "id" )
|
||||||
{
|
{
|
||||||
setIdRecurse( stripId( value ) );
|
setIdRecurse( stripId( value ) );
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if( name == "active" )
|
if( name == "active" )
|
||||||
|
@ -173,6 +174,7 @@ namespace NLGUI
|
||||||
bool b;
|
bool b;
|
||||||
if( fromString( value, b ) )
|
if( fromString( value, b ) )
|
||||||
setActive( b );
|
setActive( b );
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if( name == "x" )
|
if( name == "x" )
|
||||||
|
@ -180,6 +182,7 @@ namespace NLGUI
|
||||||
sint32 x;
|
sint32 x;
|
||||||
if( fromString( value, x ) )
|
if( fromString( value, x ) )
|
||||||
setX( x );
|
setX( x );
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if( name == "y" )
|
if( name == "y" )
|
||||||
|
@ -187,6 +190,7 @@ namespace NLGUI
|
||||||
sint32 y;
|
sint32 y;
|
||||||
if( fromString( value, y ) )
|
if( fromString( value, y ) )
|
||||||
setY( y );
|
setY( y );
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if( name == "w" )
|
if( name == "w" )
|
||||||
|
@ -194,6 +198,7 @@ namespace NLGUI
|
||||||
sint32 w;
|
sint32 w;
|
||||||
if( fromString( value, w ) )
|
if( fromString( value, w ) )
|
||||||
setW( w );
|
setW( w );
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if( name == "h" )
|
if( name == "h" )
|
||||||
|
@ -201,25 +206,30 @@ namespace NLGUI
|
||||||
sint32 h;
|
sint32 h;
|
||||||
if( fromString( value, h ) )
|
if( fromString( value, h ) )
|
||||||
setH( h );
|
setH( h );
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if( name == "posref" )
|
if( name == "posref" )
|
||||||
{
|
{
|
||||||
convertHotSpotCouple( value.c_str(), _ParentPosRef, _PosRef );
|
convertHotSpotCouple( value.c_str(), _ParentPosRef, _PosRef );
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if( name == "sizeref" )
|
if( name == "sizeref" )
|
||||||
{
|
{
|
||||||
parseSizeRef( value.c_str() );
|
parseSizeRef( value.c_str() );
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
if( name == "posparent" )
|
if( name == "posparent" )
|
||||||
{
|
{
|
||||||
setPosParent( value );
|
setPosParent( value );
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if( name == "sizeparent" )
|
if( name == "sizeparent" )
|
||||||
{
|
{
|
||||||
setSizeParent( value );
|
setSizeParent( value );
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if( name == "global_color" )
|
if( name == "global_color" )
|
||||||
|
@ -227,6 +237,7 @@ namespace NLGUI
|
||||||
bool b;
|
bool b;
|
||||||
if( fromString( value, b ) )
|
if( fromString( value, b ) )
|
||||||
setModulateGlobalColor( b );
|
setModulateGlobalColor( b );
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if( name == "render_layer" )
|
if( name == "render_layer" )
|
||||||
|
@ -234,6 +245,7 @@ namespace NLGUI
|
||||||
sint8 l;
|
sint8 l;
|
||||||
if( fromString( value, l ) )
|
if( fromString( value, l ) )
|
||||||
setRenderLayer( l );
|
setRenderLayer( l );
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if( name == "avoid_resize_parent" )
|
if( name == "avoid_resize_parent" )
|
||||||
|
@ -241,6 +253,7 @@ namespace NLGUI
|
||||||
bool b;
|
bool b;
|
||||||
if( fromString( value, b ) )
|
if( fromString( value, b ) )
|
||||||
setAvoidResizeParent( b );
|
setAvoidResizeParent( b );
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
nlwarning( "Tried to set invalid property '%s' for widget '%s'", name.c_str(), _Id.c_str() );
|
nlwarning( "Tried to set invalid property '%s' for widget '%s'", name.c_str(), _Id.c_str() );
|
||||||
|
|
|
@ -58,12 +58,17 @@ namespace GUIEditor
|
||||||
{
|
{
|
||||||
if( browser == NULL )
|
if( browser == NULL )
|
||||||
return;
|
return;
|
||||||
|
disconnect( propertyMgr, SIGNAL( propertyChanged( QtProperty* ) ),
|
||||||
|
this, SLOT( onPropertyChanged( QtProperty* ) ) );
|
||||||
|
|
||||||
browser->clear();
|
browser->clear();
|
||||||
|
|
||||||
CInterfaceElement *e = CWidgetManager::getInstance()->getElementFromId( id );
|
CInterfaceElement *e = CWidgetManager::getInstance()->getElementFromId( id );
|
||||||
if( e == NULL )
|
if( e == NULL )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
currentElement = id;
|
||||||
|
|
||||||
std::string n;
|
std::string n;
|
||||||
n = typeid( *e ).name();
|
n = typeid( *e ).name();
|
||||||
std::string::size_type i = n.find_last_of( ':' );
|
std::string::size_type i = n.find_last_of( ':' );
|
||||||
|
@ -71,6 +76,27 @@ namespace GUIEditor
|
||||||
n = n.substr( i + 1, n.size() - 1 );
|
n = n.substr( i + 1, n.size() - 1 );
|
||||||
|
|
||||||
setupProperties( n, e );
|
setupProperties( n, e );
|
||||||
|
connect( propertyMgr, SIGNAL( propertyChanged( QtProperty* ) ),
|
||||||
|
this, SLOT( onPropertyChanged( QtProperty* ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
void CPropBrowserCtrl::onPropertyChanged( QtProperty *prop )
|
||||||
|
{
|
||||||
|
QString propName = prop->propertyName();
|
||||||
|
QString propValue = prop->valueText();
|
||||||
|
|
||||||
|
// for some reason booleans cannot be extracted from a QtProperty :(
|
||||||
|
if( propValue.isEmpty() )
|
||||||
|
{
|
||||||
|
QtVariantProperty *p = propertyMgr->variantProperty( prop );
|
||||||
|
if( p != NULL )
|
||||||
|
propValue = p->value().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
CInterfaceElement *e = CWidgetManager::getInstance()->getElementFromId( currentElement );
|
||||||
|
if( e == NULL )
|
||||||
|
return;
|
||||||
|
e->setProperty( propName.toStdString(), propValue.toStdString() );
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPropBrowserCtrl::setupProperties( const std::string &type, const CInterfaceElement *element )
|
void CPropBrowserCtrl::setupProperties( const std::string &type, const CInterfaceElement *element )
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
|
|
||||||
class QtTreePropertyBrowser;
|
class QtTreePropertyBrowser;
|
||||||
class QtVariantPropertyManager;
|
class QtVariantPropertyManager;
|
||||||
|
class QtProperty;
|
||||||
|
|
||||||
namespace NLGUI
|
namespace NLGUI
|
||||||
{
|
{
|
||||||
|
@ -49,6 +50,9 @@ namespace GUIEditor
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void onSelectionChanged( std::string &id );
|
void onSelectionChanged( std::string &id );
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void onPropertyChanged( QtProperty *prop );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setupProperties( const std::string &type, const NLGUI::CInterfaceElement *element );
|
void setupProperties( const std::string &type, const NLGUI::CInterfaceElement *element );
|
||||||
void setupProperty( const SPropEntry &prop, const NLGUI::CInterfaceElement *element );
|
void setupProperty( const SPropEntry &prop, const NLGUI::CInterfaceElement *element );
|
||||||
|
@ -56,6 +60,8 @@ namespace GUIEditor
|
||||||
QtTreePropertyBrowser *browser;
|
QtTreePropertyBrowser *browser;
|
||||||
QtVariantPropertyManager *propertyMgr;
|
QtVariantPropertyManager *propertyMgr;
|
||||||
std::map< std::string, SWidgetInfo > widgetInfo;
|
std::map< std::string, SWidgetInfo > widgetInfo;
|
||||||
|
|
||||||
|
std::string currentElement;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue