From 264e0fe16ca88caac28aed9b7ef635033d593117 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Fri, 6 Jul 2012 03:15:15 +0200 Subject: [PATCH] CHANGED: #1471 Widget definition inheritance is now supported in the GUI editor. www.youtube.com/watch?v=VG_TnZiGjBk --- .../src/plugins/gui_editor/widget_info.h | 8 +++ .../gui_editor/widget_properties_parser.cpp | 66 ++++++++++++++++++- .../gui_editor/widget_properties_parser.h | 2 + .../gui_editor/widgets/ControlBase.xml | 1 + .../gui_editor/widgets/InterfaceGroup.xml | 22 +++++++ 5 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/InterfaceGroup.xml 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 3fed78733..684cbc8ca 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 @@ -43,11 +43,19 @@ namespace GUIEditor { std::string name; std::string GUIName; + std::string ancestor; std::string description; bool isAbstract; std::string icon; + bool resolved; std::vector< SPropEntry > props; + + SWidgetInfo() + { + resolved = false; + isAbstract = true; + } }; } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_properties_parser.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_properties_parser.cpp index 8f5b64191..dc2b016c7 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_properties_parser.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_properties_parser.cpp @@ -47,6 +47,8 @@ namespace GUIEditor while( itr.hasNext() ) parseGUIWidget( "widgets/" + itr.next() ); + resolveInheritance(); + widgetInfo = NULL; } @@ -119,6 +121,9 @@ namespace GUIEditor if( key == "guiname" ) info.GUIName = value.toStdString(); else + if( key == "ancestor" ) + info.ancestor = value.toStdString(); + else if( key == "description" ) info.description = value.toStdString(); else @@ -202,7 +207,66 @@ namespace GUIEditor reader.readNext(); } - } + } + + bool propCompare( const SPropEntry &left, const SPropEntry &right ) + { + return left.propName < right.propName; + } + + void CWidgetPropParser::resolveInheritance() + { + for( std::map< std::string, SWidgetInfo >::iterator itr = widgetInfo->begin(); itr != widgetInfo->end(); ++itr ) + { + resolveInheritanceFor( itr->first ); + std::sort( itr->second.props.begin(), itr->second.props.end(), propCompare ); + } + + } + + void CWidgetPropParser::resolveInheritanceFor( const std::string name ) + { + if( name.empty() ) + return; + + std::map< std::string, SWidgetInfo >::iterator itr = + widgetInfo->find( name ); + if( itr == widgetInfo->end() ) + return; + + SWidgetInfo *info = &(itr->second); + if( info->resolved ) + return; + + if( info->ancestor.empty() ) + return; + + std::vector< SPropEntry > &props = info->props; + + std::map< std::string, SWidgetInfo >::iterator itr2 = + widgetInfo->find( info->ancestor ); + if( itr2 == widgetInfo->end() ) + return; + SWidgetInfo *info2 = &(itr2->second); + + do + { + for( std::vector< SPropEntry >::iterator propItr = info2->props.begin(); propItr != info2->props.end(); ++propItr ) + props.push_back( *propItr ); + + if( !info2->resolved && !info2->ancestor.empty() ) + { + itr2 = widgetInfo->find( info2->ancestor ); + if( itr2 != widgetInfo->end() ) + info2 = &(itr2->second); + else + info2 = NULL; + } + } + while( ( info2 != NULL ) && !info2->resolved && !info2->ancestor.empty() ); + + info->resolved = true; + } } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_properties_parser.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_properties_parser.h index b3dc403ca..4dcbffacf 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_properties_parser.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_properties_parser.h @@ -41,6 +41,8 @@ namespace GUIEditor void parseGUIWidgetXML( QFile &file ); QString parseGUIWidgetHeader( QXmlStreamReader &reader ); void parseGUIWidgetProperties( QXmlStreamReader &reader, const QString &widgetName ); + void resolveInheritance(); + void resolveInheritanceFor( const std::string name ); std::map< std::string, SWidgetInfo > *widgetInfo; }; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/ControlBase.xml b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/ControlBase.xml index 3f092e135..809ccacfd 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/ControlBase.xml +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/ControlBase.xml @@ -2,6 +2,7 @@
CtrlBase cb + InterfaceElement true diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/InterfaceGroup.xml b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/InterfaceGroup.xml new file mode 100644 index 000000000..d11ceb180 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widgets/InterfaceGroup.xml @@ -0,0 +1,22 @@ + +
+ InterfaceGroup + ig + CtrlBase + + false + +
+ + + on_enter + string + handler + + + on_enter_params + string + params + + +