From bd41a670679862d1f66256abbda88947ae4ed68a Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Thu, 26 Jul 2012 20:12:24 +0200 Subject: [PATCH] ADDED: #1471 Implemented basic framework for querying widget properties. Not yet fully implemented. --HG-- branch : gsoc2012-gui-editor --- code/nel/include/nel/gui/ctrl_base.h | 4 +- code/nel/include/nel/gui/interface_element.h | 2 + code/nel/include/nel/gui/interface_group.h | 2 + code/nel/src/gui/ctrl_base.cpp | 15 +++ code/nel/src/gui/interface_element.cpp | 19 ++++ code/nel/src/gui/interface_group.cpp | 15 +++ .../plugins/gui_editor/gui_editor_window.cpp | 5 +- .../gui_editor/property_browser_ctrl.cpp | 106 +++++++++++++----- .../gui_editor/property_browser_ctrl.h | 45 +++++--- .../plugins/gui_editor/widget_hierarchy.cpp | 5 +- .../src/plugins/gui_editor/widget_hierarchy.h | 3 + .../src/plugins/gui_editor/widget_info.h | 4 +- 12 files changed, 177 insertions(+), 48 deletions(-) diff --git a/code/nel/include/nel/gui/ctrl_base.h b/code/nel/include/nel/gui/ctrl_base.h index ad171ec45..d163447d6 100644 --- a/code/nel/include/nel/gui/ctrl_base.h +++ b/code/nel/include/nel/gui/ctrl_base.h @@ -57,7 +57,9 @@ namespace NLGUI virtual ~CCtrlBase(); // special parse - virtual bool parse (xmlNodePtr cur, CInterfaceGroup *parentGroup); + 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) diff --git a/code/nel/include/nel/gui/interface_element.h b/code/nel/include/nel/gui/interface_element.h index 7c510bbfe..9bedd1186 100644 --- a/code/nel/include/nel/gui/interface_element.h +++ b/code/nel/include/nel/gui/interface_element.h @@ -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()); } diff --git a/code/nel/include/nel/gui/interface_group.h b/code/nel/include/nel/gui/interface_group.h index 38d0c1e32..2a44160a5 100644 --- a/code/nel/include/nel/gui/interface_group.h +++ b/code/nel/include/nel/gui/interface_group.h @@ -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); diff --git a/code/nel/src/gui/ctrl_base.cpp b/code/nel/src/gui/ctrl_base.cpp index adc0ce5b1..cef775e8d 100644 --- a/code/nel/src/gui/ctrl_base.cpp +++ b/code/nel/src/gui/ctrl_base.cpp @@ -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) { diff --git a/code/nel/src/gui/interface_element.cpp b/code/nel/src/gui/interface_element.cpp index 2c3673ac6..50177bf23 100644 --- a/code/nel/src/gui/interface_element.cpp +++ b/code/nel/src/gui/interface_element.cpp @@ -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) { diff --git a/code/nel/src/gui/interface_group.cpp b/code/nel/src/gui/interface_group.cpp index 72d1de1d7..2baa6633c 100644 --- a/code/nel/src/gui/interface_group.cpp +++ b/code/nel/src/gui/interface_group.cpp @@ -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) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.cpp index a4a5b69c2..ff41878ed 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.cpp @@ -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() diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/property_browser_ctrl.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/property_browser_ctrl.cpp index 3a8dafd99..d9e27ecbc 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/property_browser_ctrl.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/property_browser_ctrl.cpp @@ -1,23 +1,26 @@ -// Object Viewer Qt GUI Editor plugin -// Copyright (C) 2010 Winch Gate Property Limited -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License +// Object Viewer Qt GUI Editor plugin +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . #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 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; + + 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 ); + + setupProperties( n, e ); + } + + 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; - p = propertyMgr->addProperty( QVariant::String, "Id" ); - p->setValue( "ExampleId" ); - browser->addProperty( p ); + 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 = propertyMgr->addProperty( QVariant::Bool, "Active" ); - p->setValue( true ); - browser->addProperty( p ); + p->setValue( value ); + } + if( p == NULL ) + return; - p = propertyMgr->addProperty( QVariant::String, "on_enter" ); - p->setValue( "on_enter_handler" ); - browser->addProperty( p ); - - p = propertyMgr->addProperty( QVariant::String, "on_enter_params" ); - p->setValue( "someparams" ); browser->addProperty( p ); } } \ No newline at end of file diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/property_browser_ctrl.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/property_browser_ctrl.h index f8549205a..90b719138 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/property_browser_ctrl.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/property_browser_ctrl.h @@ -1,17 +1,17 @@ -// Object Viewer Qt GUI Editor plugin -// Copyright (C) 2010 Winch Gate Property Limited -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License +// Object Viewer Qt GUI Editor plugin +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . @@ -19,10 +19,18 @@ #define PROP_BROWSER_CTRL #include +#include +#include +#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; }; } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.cpp index 883e5cfdc..c8e70574a 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.cpp @@ -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 ); } } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.h index f634bba91..05957db39 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.h @@ -52,6 +52,9 @@ namespace GUIEditor private: std::string currentSelection; std::string masterGroup; + + Q_SIGNALS: + void selectionChanged( std::string &id ); }; } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_info.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_info.h index 684cbc8ca..b2e6affc9 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_info.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_info.h @@ -18,8 +18,8 @@ #ifndef WIDGET_INFO_H #define WIDGET_INFO_H -#include #include +#include namespace GUIEditor { @@ -28,7 +28,7 @@ namespace GUIEditor std::string propName; std::string propType; std::string propDefault; - + static SPropEntry create( const char *propname, const char *proptype, const char *propdefault ) { SPropEntry entry;