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

--HG--
branch : gsoc2012-gui-editor
This commit is contained in:
dfighter1985 2013-05-09 23:57:48 +02:00
parent 142bc623c9
commit 337f93a233
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
#define WIDGET_ADD_WATCHER

View file

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

View file

@ -19,6 +19,7 @@
#include "nel/gui/interface_group.h"
#include "nel/gui/widget_manager.h"
#include "widget_info_tree.h"
namespace GUIEditor
{
@ -57,13 +58,42 @@ namespace GUIEditor
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 =
CWidgetManager::getInstance()->addWidgetToGroup(
std::string( parentGroup.toUtf8() ),
std::string( widgetType.toUtf8() ),
className,
std::string( name.toUtf8() )
);
// Failed to add widget
if( e == NULL )
{
QMessageBox::critical(
@ -72,7 +102,29 @@ namespace GUIEditor
tr( "Error adding the new widget!" ),
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
{
class CWidgetInfoTree;
/// Processes the GUI Editor's editor messages like delete, new, etc...
class CEditorMessageProcessor : public QObject
{
Q_OBJECT
public:
CEditorMessageProcessor( QObject *parent = NULL ) : QObject( parent ){}
CEditorMessageProcessor( QObject *parent = NULL ) :
QObject( parent )
{
tree = NULL;
}
~CEditorMessageProcessor(){}
void setTree( CWidgetInfoTree *tree ){ this->tree = tree; }
public Q_SLOTS:
void onDelete();
void onAdd( const QString &parentGroup, const QString &widgetType, const QString &name );
private:
CWidgetInfoTree *tree;
};
}

View file

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

View file

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

View file

@ -63,6 +63,7 @@ namespace GUIEditor
f << "\t<header>" << std::endl;
f << "\t\t<name>" << info.name << "</name>" << 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<description>" << info.description << "</description>" << std::endl;

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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