mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-11-05 23:09:02 +00:00
CHANGED: #1471 Widget definition inheritance is now supported in the GUI editor. www.youtube.com/watch?v=VG_TnZiGjBk
This commit is contained in:
parent
30eef5ddef
commit
042e9e0000
5 changed files with 98 additions and 1 deletions
|
@ -43,11 +43,19 @@ namespace GUIEditor
|
||||||
{
|
{
|
||||||
std::string name;
|
std::string name;
|
||||||
std::string GUIName;
|
std::string GUIName;
|
||||||
|
std::string ancestor;
|
||||||
std::string description;
|
std::string description;
|
||||||
bool isAbstract;
|
bool isAbstract;
|
||||||
std::string icon;
|
std::string icon;
|
||||||
|
bool resolved;
|
||||||
|
|
||||||
std::vector< SPropEntry > props;
|
std::vector< SPropEntry > props;
|
||||||
|
|
||||||
|
SWidgetInfo()
|
||||||
|
{
|
||||||
|
resolved = false;
|
||||||
|
isAbstract = true;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,8 @@ namespace GUIEditor
|
||||||
while( itr.hasNext() )
|
while( itr.hasNext() )
|
||||||
parseGUIWidget( "widgets/" + itr.next() );
|
parseGUIWidget( "widgets/" + itr.next() );
|
||||||
|
|
||||||
|
resolveInheritance();
|
||||||
|
|
||||||
widgetInfo = NULL;
|
widgetInfo = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,6 +121,9 @@ namespace GUIEditor
|
||||||
if( key == "guiname" )
|
if( key == "guiname" )
|
||||||
info.GUIName = value.toStdString();
|
info.GUIName = value.toStdString();
|
||||||
else
|
else
|
||||||
|
if( key == "ancestor" )
|
||||||
|
info.ancestor = value.toStdString();
|
||||||
|
else
|
||||||
if( key == "description" )
|
if( key == "description" )
|
||||||
info.description = value.toStdString();
|
info.description = value.toStdString();
|
||||||
else
|
else
|
||||||
|
@ -203,6 +208,65 @@ namespace GUIEditor
|
||||||
reader.readNext();
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,8 @@ namespace GUIEditor
|
||||||
void parseGUIWidgetXML( QFile &file );
|
void parseGUIWidgetXML( QFile &file );
|
||||||
QString parseGUIWidgetHeader( QXmlStreamReader &reader );
|
QString parseGUIWidgetHeader( QXmlStreamReader &reader );
|
||||||
void parseGUIWidgetProperties( QXmlStreamReader &reader, const QString &widgetName );
|
void parseGUIWidgetProperties( QXmlStreamReader &reader, const QString &widgetName );
|
||||||
|
void resolveInheritance();
|
||||||
|
void resolveInheritanceFor( const std::string name );
|
||||||
|
|
||||||
std::map< std::string, SWidgetInfo > *widgetInfo;
|
std::map< std::string, SWidgetInfo > *widgetInfo;
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
<header>
|
<header>
|
||||||
<name>CtrlBase</name>
|
<name>CtrlBase</name>
|
||||||
<guiname>cb</guiname>
|
<guiname>cb</guiname>
|
||||||
|
<ancestor>InterfaceElement</ancestor>
|
||||||
<description></description>
|
<description></description>
|
||||||
<abstract>true</abstract>
|
<abstract>true</abstract>
|
||||||
<icon></icon>
|
<icon></icon>
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
<widget>
|
||||||
|
<header>
|
||||||
|
<name>InterfaceGroup</name>
|
||||||
|
<guiname>ig</guiname>
|
||||||
|
<ancestor>CtrlBase</ancestor>
|
||||||
|
<description></description>
|
||||||
|
<abstract>false</abstract>
|
||||||
|
<icon></icon>
|
||||||
|
</header>
|
||||||
|
<properties>
|
||||||
|
<property>
|
||||||
|
<name>on_enter</name>
|
||||||
|
<type>string</type>
|
||||||
|
<default>handler</default>
|
||||||
|
</property>
|
||||||
|
<property>
|
||||||
|
<name>on_enter_params</name>
|
||||||
|
<type>string</type>
|
||||||
|
<default>params</default>
|
||||||
|
</property>
|
||||||
|
</properties>
|
||||||
|
</widget>
|
Loading…
Reference in a new issue