When adding a new widget, the correct widget is now instantiated. Also added some checks.

This commit is contained in:
dfighter1985 2013-05-09 23:57:48 +02:00
parent 954bb6a533
commit 871fed3e12
37 changed files with 151 additions and 39 deletions

View file

@ -1,3 +1,19 @@
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// 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 <http://www.gnu.org/licenses/>.
#ifndef WIDGET_ADD_WATCHER #ifndef WIDGET_ADD_WATCHER
#define WIDGET_ADD_WATCHER #define WIDGET_ADD_WATCHER

View file

@ -3271,37 +3271,34 @@ namespace NLGUI
CInterfaceElement* CWidgetManager::addWidgetToGroup( std::string &group, std::string &widgetClass, std::string &widgetName ) CInterfaceElement* CWidgetManager::addWidgetToGroup( std::string &group, std::string &widgetClass, std::string &widgetName )
{ {
// Check if this group exists // Check if this group exists
CInterfaceElement *e = getElementFromId( group ); CInterfaceElement *e = getElementFromId( group );
if( e == NULL ) if( e == NULL )
return NULL; return NULL;
CInterfaceGroup *g = dynamic_cast< CInterfaceGroup* >( e ); CInterfaceGroup *g = dynamic_cast< CInterfaceGroup* >( e );
if( g == NULL ) if( g == NULL )
return NULL; return NULL;
// Check if an element already exists with that name // Check if an element already exists with that name
if( g->getElement( widgetName ) != NULL ) if( g->getElement( widgetName ) != NULL )
return NULL; return NULL;
// Create and add the new widget // Create and add the new widget
CViewBase *v = getParser()->createClass( "button" ); CViewBase *v = getParser()->createClass( widgetClass );
if( v == NULL ) if( v == NULL )
return NULL; return NULL;
v->setId( std::string( g->getId() + ":" + widgetName ) ); v->setId( std::string( g->getId() + ":" + widgetName ) );
v->setParentPosRef( Hotspot_TL ); if( v->isGroup() )
v->setPosRef( Hotspot_TL ); g->addGroup( dynamic_cast< CInterfaceGroup* >( v ) );
else
if( v->isGroup() ) if( v->isCtrl() )
g->addGroup( dynamic_cast< CInterfaceGroup* >( v ) ); g->addCtrl( dynamic_cast< CCtrlBase* >( v ) );
else else
if( v->isCtrl() ) g->addView( v );
g->addCtrl( dynamic_cast< CCtrlBase* >( v ) );
else // Invalidate so it shows up!
g->addView( v );
// Invalidate so it shows up!
v->invalidateCoords(); v->invalidateCoords();
notifyAdditionWatchers( v->getId() ); notifyAdditionWatchers( v->getId() );

View file

@ -19,6 +19,7 @@
#include "nel/gui/interface_group.h" #include "nel/gui/interface_group.h"
#include "nel/gui/widget_manager.h" #include "nel/gui/widget_manager.h"
#include "widget_info_tree.h"
namespace GUIEditor namespace GUIEditor
{ {
@ -57,13 +58,42 @@ namespace GUIEditor
void CEditorMessageProcessor::onAdd( const QString &parentGroup, const QString &widgetType, const QString &name ) void CEditorMessageProcessor::onAdd( const QString &parentGroup, const QString &widgetType, const QString &name )
{ {
CWidgetInfoTreeNode *node = tree->findNodeByName( std::string( widgetType.toUtf8() ) );
// No such widget
if( node == NULL )
{
QMessageBox::critical(
NULL,
tr( "Error" ),
tr( "Error adding the new widget! No such widget type!" ),
QMessageBox::Ok
);
return;
}
// No class name defined
std::string className = node->getInfo().className;
if( className.empty() )
{
QMessageBox::critical(
NULL,
tr( "Error" ),
tr( "Error adding the new widget! Missing classname!" ),
QMessageBox::Ok
);
return;
}
CInterfaceElement *e = CInterfaceElement *e =
CWidgetManager::getInstance()->addWidgetToGroup( CWidgetManager::getInstance()->addWidgetToGroup(
std::string( parentGroup.toUtf8() ), std::string( parentGroup.toUtf8() ),
std::string( widgetType.toUtf8() ), className,
std::string( name.toUtf8() ) std::string( name.toUtf8() )
); );
// Failed to add widget
if( e == NULL ) if( e == NULL )
{ {
QMessageBox::critical( QMessageBox::critical(
@ -72,7 +102,29 @@ namespace GUIEditor
tr( "Error adding the new widget!" ), tr( "Error adding the new widget!" ),
QMessageBox::Ok QMessageBox::Ok
); );
return;
} }
// Setting the defaults will override the Id too
std::string id = e->getId();
// Set up the defaults
std::vector< SPropEntry >::const_iterator itr = node->getInfo().props.begin();
while( itr != node->getInfo().props.end() )
{
e->setProperty( itr->propName, itr->propDefault );
++itr;
}
// Restore the Id
e->setId( id );
// Make the widget aligned to the top left corner
e->setParentPosRef( Hotspot_TL );
e->setPosRef( Hotspot_TL );
// Apply the new settings
e->invalidateCoords();
} }
} }

View file

@ -18,17 +18,29 @@
namespace GUIEditor namespace GUIEditor
{ {
class CWidgetInfoTree;
/// Processes the GUI Editor's editor messages like delete, new, etc... /// Processes the GUI Editor's editor messages like delete, new, etc...
class CEditorMessageProcessor : public QObject class CEditorMessageProcessor : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
CEditorMessageProcessor( QObject *parent = NULL ) : QObject( parent ){} CEditorMessageProcessor( QObject *parent = NULL ) :
QObject( parent )
{
tree = NULL;
}
~CEditorMessageProcessor(){} ~CEditorMessageProcessor(){}
void setTree( CWidgetInfoTree *tree ){ this->tree = tree; }
public Q_SLOTS: public Q_SLOTS:
void onDelete(); void onDelete();
void onAdd( const QString &parentGroup, const QString &widgetType, const QString &name ); void onAdd( const QString &parentGroup, const QString &widgetType, const QString &name );
private:
CWidgetInfoTree *tree;
}; };
} }

View file

@ -79,6 +79,7 @@ namespace GUIEditor
parser.parseGUIWidgets(); parser.parseGUIWidgets();
widgetProps->setupWidgetInfo( widgetInfoTree ); widgetProps->setupWidgetInfo( widgetInfoTree );
addWidgetWidget->setupWidgetInfo( widgetInfoTree ); addWidgetWidget->setupWidgetInfo( widgetInfoTree );
messageProcessor->setTree( widgetInfoTree );
QDockWidget *dock = new QDockWidget( "Widget Hierarchy", this ); QDockWidget *dock = new QDockWidget( "Widget Hierarchy", this );
dock->setAllowedAreas( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea ); dock->setAllowedAreas( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea );

View file

@ -53,6 +53,7 @@ namespace GUIEditor
{ {
std::string name; std::string name;
std::string GUIName; std::string GUIName;
std::string className;
std::string ancestor; std::string ancestor;
std::string description; std::string description;
bool isAbstract; bool isAbstract;

View file

@ -63,6 +63,7 @@ namespace GUIEditor
f << "\t<header>" << std::endl; f << "\t<header>" << std::endl;
f << "\t\t<name>" << info.name << "</name>" << std::endl; f << "\t\t<name>" << info.name << "</name>" << std::endl;
f << "\t\t<guiname>" << info.GUIName << "</guiname>" << std::endl; f << "\t\t<guiname>" << info.GUIName << "</guiname>" << std::endl;
f << "\t\t<classname>" << info.className << "</classname>" << std::endl;
f << "\t\t<ancestor>" << info.ancestor << "</ancestor>" << std::endl; f << "\t\t<ancestor>" << info.ancestor << "</ancestor>" << std::endl;
f << "\t\t<description>" << info.description << "</description>" << std::endl; f << "\t\t<description>" << info.description << "</description>" << std::endl;

View file

@ -131,6 +131,9 @@ namespace GUIEditor
if( key == "guiname" ) if( key == "guiname" )
info.GUIName = value.toUtf8().constData(); info.GUIName = value.toUtf8().constData();
else else
if( key == "classname" )
info.className = value.toUtf8().constData();
else
if( key == "ancestor" ) if( key == "ancestor" )
info.ancestor = value.toUtf8().constData(); info.ancestor = value.toUtf8().constData();
else else

View file

@ -2,6 +2,7 @@
<header> <header>
<name>CtrlButton</name> <name>CtrlButton</name>
<guiname>CCtrlButton</guiname> <guiname>CCtrlButton</guiname>
<classname>button</classname>
<ancestor>CtrlBaseButton</ancestor> <ancestor>CtrlBaseButton</ancestor>
<description></description> <description></description>
<abstract>false</abstract> <abstract>false</abstract>

View file

@ -2,6 +2,7 @@
<header> <header>
<name>CtrlColPick</name> <name>CtrlColPick</name>
<guiname>CCtrlColPick</guiname> <guiname>CCtrlColPick</guiname>
<classname>colpick</classname>
<ancestor>CtrlBase</ancestor> <ancestor>CtrlBase</ancestor>
<description></description> <description></description>
<abstract>false</abstract> <abstract>false</abstract>

View file

@ -2,6 +2,7 @@
<header> <header>
<name>CtrlScroll</name> <name>CtrlScroll</name>
<guiname>CCtrlScroll</guiname> <guiname>CCtrlScroll</guiname>
<classname>scroll</classname>
<ancestor>CtrlBase</ancestor> <ancestor>CtrlBase</ancestor>
<description></description> <description></description>
<abstract>false</abstract> <abstract>false</abstract>

View file

@ -2,6 +2,7 @@
<header> <header>
<name>CtrlTextButton</name> <name>CtrlTextButton</name>
<guiname>CCtrlTextButton</guiname> <guiname>CCtrlTextButton</guiname>
<classname>text_button</classname>
<ancestor>CtrlBaseButton</ancestor> <ancestor>CtrlBaseButton</ancestor>
<description></description> <description></description>
<abstract>false</abstract> <abstract>false</abstract>

View file

@ -2,6 +2,7 @@
<header> <header>
<name>DBGroupSelectNumber</name> <name>DBGroupSelectNumber</name>
<guiname>CDBGroupSelectNumber</guiname> <guiname>CDBGroupSelectNumber</guiname>
<classname>select_number</classname>
<ancestor>InterfaceGroup</ancestor> <ancestor>InterfaceGroup</ancestor>
<description></description> <description></description>
<abstract>false</abstract> <abstract>false</abstract>

View file

@ -2,6 +2,7 @@
<header> <header>
<name>DBViewBar</name> <name>DBViewBar</name>
<guiname>CDBViewBar</guiname> <guiname>CDBViewBar</guiname>
<classname>bar</classname>
<ancestor>ViewBitmap</ancestor> <ancestor>ViewBitmap</ancestor>
<description></description> <description></description>
<abstract>false</abstract> <abstract>false</abstract>

View file

@ -2,6 +2,7 @@
<header> <header>
<name>DBViewBar3</name> <name>DBViewBar3</name>
<guiname>CDBViewBar3</guiname> <guiname>CDBViewBar3</guiname>
<classname>bar3</classname>
<ancestor>ViewBitmap</ancestor> <ancestor>ViewBitmap</ancestor>
<description></description> <description></description>
<abstract>false</abstract> <abstract>false</abstract>

View file

@ -2,6 +2,7 @@
<header> <header>
<name>DBViewDigit</name> <name>DBViewDigit</name>
<guiname>CDBViewDigit</guiname> <guiname>CDBViewDigit</guiname>
<classname>digit</classname>
<ancestor>CtrlBase</ancestor> <ancestor>CtrlBase</ancestor>
<description></description> <description></description>
<abstract>false</abstract> <abstract>false</abstract>
@ -11,7 +12,7 @@
<property> <property>
<name>value</name> <name>value</name>
<type>string</type> <type>string</type>
<default></default> <default>0</default>
</property> </property>
<property> <property>
<name>numdigit</name> <name>numdigit</name>

View file

@ -2,6 +2,7 @@
<header> <header>
<name>DBViewNumber</name> <name>DBViewNumber</name>
<guiname>CDBViewNumber</guiname> <guiname>CDBViewNumber</guiname>
<classname>text_number</classname>
<ancestor>ViewText</ancestor> <ancestor>ViewText</ancestor>
<description></description> <description></description>
<abstract>false</abstract> <abstract>false</abstract>
@ -11,7 +12,7 @@
<property> <property>
<name>value</name> <name>value</name>
<type>string</type> <type>string</type>
<default></default> <default>0</default>
</property> </property>
<property> <property>
<name>positive</name> <name>positive</name>

View file

@ -2,6 +2,7 @@
<header> <header>
<name>DBViewQuantity</name> <name>DBViewQuantity</name>
<guiname>CDBViewQuantity</guiname> <guiname>CDBViewQuantity</guiname>
<classname>text_quantity</classname>
<ancestor>ViewText</ancestor> <ancestor>ViewText</ancestor>
<description></description> <description></description>
<abstract>false</abstract> <abstract>false</abstract>
@ -11,17 +12,17 @@
<property> <property>
<name>value</name> <name>value</name>
<type>string</type> <type>string</type>
<default></default> <default>0</default>
</property> </property>
<property> <property>
<name>valuemax</name> <name>valuemax</name>
<type>string</type> <type>string</type>
<default></default> <default>100</default>
</property> </property>
<property> <property>
<name>emptytext</name> <name>emptytext</name>
<type>string</type> <type>string</type>
<default></default> <default>empty text</default>
</property> </property>

View file

@ -2,6 +2,7 @@
<header> <header>
<name>GroupContainer</name> <name>GroupContainer</name>
<guiname>CGroupContainer</guiname> <guiname>CGroupContainer</guiname>
<classname>container</classname>
<ancestor>InterfaceGroup</ancestor> <ancestor>InterfaceGroup</ancestor>
<description></description> <description></description>
<abstract>false</abstract> <abstract>false</abstract>

View file

@ -2,6 +2,7 @@
<header> <header>
<name>GroupEditBox</name> <name>GroupEditBox</name>
<guiname>CGroupEditBox</guiname> <guiname>CGroupEditBox</guiname>
<classname>edit_box</classname>
<ancestor>InterfaceGroup</ancestor> <ancestor>InterfaceGroup</ancestor>
<description></description> <description></description>
<abstract>false</abstract> <abstract>false</abstract>

View file

@ -2,6 +2,7 @@
<header> <header>
<name>GroupHTML</name> <name>GroupHTML</name>
<guiname>CGroupHTML</guiname> <guiname>CGroupHTML</guiname>
<classname>html</classname>
<ancestor>GroupScrollText</ancestor> <ancestor>GroupScrollText</ancestor>
<description></description> <description></description>
<abstract>false</abstract> <abstract>false</abstract>

View file

@ -2,6 +2,7 @@
<header> <header>
<name>GroupHeader</name> <name>GroupHeader</name>
<guiname>CGroupHeader</guiname> <guiname>CGroupHeader</guiname>
<classname>header</classname>
<ancestor>GroupList</ancestor> <ancestor>GroupList</ancestor>
<description></description> <description></description>
<abstract>false</abstract> <abstract>false</abstract>

View file

@ -2,6 +2,7 @@
<header> <header>
<name>GroupList</name> <name>GroupList</name>
<guiname>CGroupList</guiname> <guiname>CGroupList</guiname>
<classname>list</classname>
<ancestor>InterfaceGroup</ancestor> <ancestor>InterfaceGroup</ancestor>
<description></description> <description></description>
<abstract>false</abstract> <abstract>false</abstract>

View file

@ -2,6 +2,7 @@
<header> <header>
<name>GroupMenu</name> <name>GroupMenu</name>
<guiname>CGroupMenu</guiname> <guiname>CGroupMenu</guiname>
<classname>menu</classname>
<ancestor>GroupModal</ancestor> <ancestor>GroupModal</ancestor>
<description></description> <description></description>
<abstract>false</abstract> <abstract>false</abstract>

View file

@ -2,6 +2,7 @@
<header> <header>
<name>GroupModal</name> <name>GroupModal</name>
<guiname>CGroupModal</guiname> <guiname>CGroupModal</guiname>
<classname>modal</classname>
<ancestor>GroupFrame</ancestor> <ancestor>GroupFrame</ancestor>
<description></description> <description></description>
<abstract>false</abstract> <abstract>false</abstract>

View file

@ -2,6 +2,7 @@
<header> <header>
<name>GroupScrollText</name> <name>GroupScrollText</name>
<guiname>CGroupScrollText</guiname> <guiname>CGroupScrollText</guiname>
<classname>scroll_text</classname>
<ancestor>InterfaceGroup</ancestor> <ancestor>InterfaceGroup</ancestor>
<description></description> <description></description>
<abstract>false</abstract> <abstract>false</abstract>

View file

@ -2,6 +2,7 @@
<header> <header>
<name>GroupTab</name> <name>GroupTab</name>
<guiname>CGroupTab</guiname> <guiname>CGroupTab</guiname>
<classname>tab</classname>
<ancestor>InterfaceGroup</ancestor> <ancestor>InterfaceGroup</ancestor>
<description></description> <description></description>
<abstract>false</abstract> <abstract>false</abstract>

View file

@ -2,6 +2,7 @@
<header> <header>
<name>GroupTable</name> <name>GroupTable</name>
<guiname>CGroupTable</guiname> <guiname>CGroupTable</guiname>
<classname>table</classname>
<ancestor>InterfaceGroup</ancestor> <ancestor>InterfaceGroup</ancestor>
<description></description> <description></description>
<abstract>false</abstract> <abstract>false</abstract>

View file

@ -2,6 +2,7 @@
<header> <header>
<name>GroupTree</name> <name>GroupTree</name>
<guiname>CGroupTree</guiname> <guiname>CGroupTree</guiname>
<classname>tree</classname>
<ancestor>InterfaceGroup</ancestor> <ancestor>InterfaceGroup</ancestor>
<description></description> <description></description>
<abstract>false</abstract> <abstract>false</abstract>

View file

@ -2,6 +2,7 @@
<header> <header>
<name>InterfaceGroup</name> <name>InterfaceGroup</name>
<guiname>CInterfaceGroup</guiname> <guiname>CInterfaceGroup</guiname>
<classname>interface_group</classname>
<ancestor>CtrlBase</ancestor> <ancestor>CtrlBase</ancestor>
<description></description> <description></description>
<abstract>false</abstract> <abstract>false</abstract>

View file

@ -2,6 +2,7 @@
<header> <header>
<name>InterfaceGroupWheel</name> <name>InterfaceGroupWheel</name>
<guiname>CInterfaceGroupWheel</guiname> <guiname>CInterfaceGroupWheel</guiname>
<classname>group_wheel</classname>
<ancestor>InterfaceGroup</ancestor> <ancestor>InterfaceGroup</ancestor>
<description></description> <description></description>
<abstract>false</abstract> <abstract>false</abstract>

View file

@ -2,6 +2,7 @@
<header> <header>
<name>ViewBitmap</name> <name>ViewBitmap</name>
<guiname>CViewBitmap</guiname> <guiname>CViewBitmap</guiname>
<classname>bitmap</classname>
<ancestor>CtrlBase</ancestor> <ancestor>CtrlBase</ancestor>
<description></description> <description></description>
<abstract>false</abstract> <abstract>false</abstract>

View file

@ -2,6 +2,7 @@
<header> <header>
<name>ViewBitmapCombo</name> <name>ViewBitmapCombo</name>
<guiname>CViewBitmapCombo</guiname> <guiname>CViewBitmapCombo</guiname>
<classname>bitmap_combo</classname>
<ancestor>CtrlBase</ancestor> <ancestor>CtrlBase</ancestor>
<description></description> <description></description>
<abstract>false</abstract> <abstract>false</abstract>

View file

@ -2,6 +2,7 @@
<header> <header>
<name>ViewText</name> <name>ViewText</name>
<guiname>CViewText</guiname> <guiname>CViewText</guiname>
<classname>text</classname>
<ancestor>InterfaceElement</ancestor> <ancestor>InterfaceElement</ancestor>
<description></description> <description></description>
<abstract>false</abstract> <abstract>false</abstract>
@ -101,7 +102,7 @@
<property> <property>
<name>hardtext</name> <name>hardtext</name>
<type>string</type> <type>string</type>
<default></default> <default>some text</default>
</property> </property>
<property> <property>
<name>hardtext_format</name> <name>hardtext_format</name>

View file

@ -2,6 +2,7 @@
<header> <header>
<name>ViewTextFormated</name> <name>ViewTextFormated</name>
<guiname>CViewTextFormated</guiname> <guiname>CViewTextFormated</guiname>
<classname>text_formated</classname>
<ancestor>ViewText</ancestor> <ancestor>ViewText</ancestor>
<description></description> <description></description>
<abstract>false</abstract> <abstract>false</abstract>

View file

@ -2,6 +2,7 @@
<header> <header>
<name>ViewTextID</name> <name>ViewTextID</name>
<guiname>CViewTextID</guiname> <guiname>CViewTextID</guiname>
<classname>text_id</classname>
<ancestor>ViewText</ancestor> <ancestor>ViewText</ancestor>
<description></description> <description></description>
<abstract>false</abstract> <abstract>false</abstract>

View file

@ -2,6 +2,7 @@
<header> <header>
<name>ViewTextIDFormated</name> <name>ViewTextIDFormated</name>
<guiname>CViewTextIDFormated</guiname> <guiname>CViewTextIDFormated</guiname>
<classname>text_id_formated</classname>
<ancestor>ViewTextID</ancestor> <ancestor>ViewTextID</ancestor>
<description></description> <description></description>
<abstract>false</abstract> <abstract>false</abstract>