ADDED: #1471 Implemented basic framework for querying widget properties. Not yet fully implemented.

This commit is contained in:
dfighter1985 2012-07-26 20:12:24 +02:00
parent edae208629
commit 14ac62dbad
12 changed files with 177 additions and 48 deletions

View file

@ -59,6 +59,8 @@ namespace NLGUI
// special parse
virtual bool parse(xmlNodePtr cur, CInterfaceGroup *parentGroup);
std::string getProperty( const std::string &name ) const;
/// Handle all events (implemented by derived classes) (return true to signal event handled)
virtual bool handleEvent (const NLGUI::CEventDescriptor &event);

View file

@ -125,6 +125,8 @@ namespace NLGUI
/// Parse the element and initalize it
virtual bool parse (xmlNodePtr cur, CInterfaceGroup *parentGroup);
virtual std::string getProperty( const std::string &name ) const;
/// Debug info on memory
virtual uint32 getMemory () { return (uint32)(sizeof(*this)+_Id.size()); }

View file

@ -41,6 +41,8 @@ namespace NLGUI
/// Coming from CInterfaceElement
virtual bool parse(xmlNodePtr cur, CInterfaceGroup * parentGroup);
std::string getProperty( const std::string &name ) const;
virtual uint32 getMemory ();
virtual CInterfaceElement* getElement (const std::string &id);

View file

@ -145,6 +145,21 @@ namespace NLGUI
return true;
}
std::string CCtrlBase::getProperty( const std::string &name ) const
{
if( name == "on_tooltip" )
{
return _OnContextHelp.toString();
}
else
if( name == "on_tooltip_params" )
{
return _OnContextHelpParams.toString();
}
return CInterfaceElement::getProperty( name );
}
// ***************************************************************************
void CCtrlBase::convertTooltipHotSpot(const char *prop, THotSpot &parentHS, THotSpot &childHS)
{

View file

@ -235,6 +235,25 @@ namespace NLGUI
}
std::string CInterfaceElement::getProperty( const std::string &name ) const
{
if( name == "id" )
{
return getId();
}
else
if( name == "active" )
{
if( getActive() )
return "true";
else
return "false";
}
return "";
}
// ------------------------------------------------------------------------------------------------
void CInterfaceElement::setSizeRef(const std::string &sizeref)
{

View file

@ -353,6 +353,21 @@ namespace NLGUI
return true;
}
std::string CInterfaceGroup::getProperty( const std::string &name ) const
{
if( name == "on_enter" )
{
return getAHOnEnter();
}
else
if( name == "on_enter_params" )
{
return getAHOnEnterParams();
}
return CCtrlBase::getProperty( name );
}
// ------------------------------------------------------------------------------------------------
void CInterfaceGroup::parseMaxSizeRef(const char *ptr)

View file

@ -75,9 +75,10 @@ namespace GUIEditor
dock = new QDockWidget( "Widget Properties", this );
dock->setAllowedAreas( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea );
QtTreePropertyBrowser *propBrowser = new QtTreePropertyBrowser;
browserCtrl.setupWidgetInfo( widgetInfo );
browserCtrl.setBrowser( propBrowser );
browserCtrl.setup();
dock->setWidget( propBrowser );
addDockWidget( Qt::RightDockWidgetArea, dock );
@ -86,6 +87,8 @@ namespace GUIEditor
connect( viewPort, SIGNAL( guiLoadComplete() ), hierarchyView, SLOT( onGUILoaded() ) );
connect( viewPort, SIGNAL( guiLoadComplete() ), procList, SLOT( onGUILoaded() ) );
connect( viewPort, SIGNAL( guiLoadComplete() ), linkList, SLOT( onGUILoaded() ) );
connect( hierarchyView, SIGNAL( selectionChanged( std::string& ) ),
&browserCtrl, SLOT( onSelectionChanged( std::string& ) ) );
}
GUIEditorWindow::~GUIEditorWindow()

View file

@ -18,6 +18,9 @@
#include "property_browser_ctrl.h"
#include "../../3rdparty/qtpropertybrowser/QtVariantPropertyManager"
#include "../../3rdparty/qtpropertybrowser/QtTreePropertyBrowser"
#include "nel/gui/interface_group.h"
#include "nel/gui/widget_manager.h"
#include <typeinfo>
namespace GUIEditor
{
@ -39,27 +42,74 @@ namespace GUIEditor
browser = b;
}
void CPropBrowserCtrl::setup()
void CPropBrowserCtrl::setupWidgetInfo( const std::map< std::string, SWidgetInfo > &info )
{
widgetInfo.clear();
std::map< std::string, SWidgetInfo >::const_iterator itr;
for( itr = info.begin(); itr != info.end(); ++itr )
{
const SWidgetInfo &w = itr->second;
widgetInfo[ w.GUIName ] = w;
}
}
void CPropBrowserCtrl::onSelectionChanged( std::string &id )
{
if( browser == NULL )
return;
browser->clear();
QtVariantProperty *p;
CInterfaceElement *e = CWidgetManager::getInstance()->getElementFromId( id );
if( e == NULL )
return;
p = propertyMgr->addProperty( QVariant::String, "Id" );
p->setValue( "ExampleId" );
browser->addProperty( p );
std::string n;
n = typeid( *e ).name();
std::string::size_type i = n.find_last_of( ':' );
if( i != std::string::npos )
n = n.substr( i + 1, n.size() - 1 );
p = propertyMgr->addProperty( QVariant::Bool, "Active" );
p->setValue( true );
browser->addProperty( p );
setupProperties( n, e );
}
p = propertyMgr->addProperty( QVariant::String, "on_enter" );
p->setValue( "on_enter_handler" );
browser->addProperty( p );
void CPropBrowserCtrl::setupProperties( const std::string &type, const CInterfaceElement *element )
{
std::map< std::string, SWidgetInfo >::iterator itr = widgetInfo.find( type );
if( itr == widgetInfo.end() )
return;
SWidgetInfo &w = itr->second;
std::vector< SPropEntry >::const_iterator pItr;
for( pItr = w.props.begin(); pItr != w.props.end(); ++pItr )
{
const SPropEntry &prop = *pItr;
setupProperty( prop, element );
}
}
void CPropBrowserCtrl::setupProperty( const SPropEntry &prop, const CInterfaceElement *element )
{
QtVariantProperty *p = NULL;
if( prop.propType == "string" )
{
p = propertyMgr->addProperty( QVariant::String, prop.propName.c_str() );
p->setValue( element->getProperty( prop.propName ).c_str() );
}
else
if( prop.propType == "bool" )
{
p = propertyMgr->addProperty( QVariant::Bool, prop.propName.c_str() );
bool value = false;
if( element->getProperty( prop.propName ) == "true" )
value = true;
p->setValue( value );
}
if( p == NULL )
return;
p = propertyMgr->addProperty( QVariant::String, "on_enter_params" );
p->setValue( "someparams" );
browser->addProperty( p );
}
}

View file

@ -19,10 +19,18 @@
#define PROP_BROWSER_CTRL
#include <QObject>
#include <string>
#include <map>
#include "widget_info.h"
class QtTreePropertyBrowser;
class QtVariantPropertyManager;
namespace NLGUI
{
class CInterfaceElement;
}
namespace GUIEditor
{
@ -36,11 +44,18 @@ namespace GUIEditor
CPropBrowserCtrl();
~CPropBrowserCtrl();
void setBrowser( QtTreePropertyBrowser *b );
void setup();
void setupWidgetInfo( const std::map< std::string, SWidgetInfo > &info );
public Q_SLOTS:
void onSelectionChanged( std::string &id );
private:
void setupProperties( const std::string &type, const NLGUI::CInterfaceElement *element );
void setupProperty( const SPropEntry &prop, const NLGUI::CInterfaceElement *element );
QtTreePropertyBrowser *browser;
QtVariantPropertyManager *propertyMgr;
std::map< std::string, SWidgetInfo > widgetInfo;
};
}

View file

@ -137,6 +137,9 @@ namespace GUIEditor
if( item->parent() == NULL )
return;
CWidgetManager::getInstance()->setCurrentEditorSelection( makeFullName( item, item->text( 0 ).toStdString() ) );
std::string selection = makeFullName( item, item->text( 0 ).toStdString() );
CWidgetManager::getInstance()->setCurrentEditorSelection( selection );
Q_EMIT selectionChanged( selection );
}
}

View file

@ -52,6 +52,9 @@ namespace GUIEditor
private:
std::string currentSelection;
std::string masterGroup;
Q_SIGNALS:
void selectionChanged( std::string &id );
};
}

View file

@ -18,8 +18,8 @@
#ifndef WIDGET_INFO_H
#define WIDGET_INFO_H
#include <string>
#include <vector>
#include <string>
namespace GUIEditor
{