Added action property editor, editor factory, manager. Actions can now be edited using the editor widget in the property tree.

--HG--
branch : gsoc2014-dfighter
This commit is contained in:
dfighter1985 2014-07-08 18:26:20 +02:00
parent 396a3c2db2
commit 7cbc82fe8f
9 changed files with 529 additions and 23 deletions

View file

@ -32,6 +32,7 @@ SET(OVQT_PLUGIN_GUI_EDITOR_HDR
editor_message_processor.h
action_list.h
texture_chooser.h
action_property_manager.h
)
SET(OVQT_PLUGIN_GUI_EDITOR_UIS

View file

@ -0,0 +1,333 @@
// Ryzom Core Studio GUI Editor plugin <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/>.
#include "action_property_manager.h"
#include "action_list.h"
#include <QMap>
#include <QList>
#include <QLineEdit>
#include <QToolButton>
#include <QHBoxLayout>
////////////////////////////////////////////////////////////////// Manager ///////////////////////////////////////////////////////////////////////////
struct ActionPropertyManagerPrivate
{
QMap< const QtProperty*, QString > values;
};
ActionPropertyManager::ActionPropertyManager( QObject *parent ) :
QtAbstractPropertyManager( parent )
{
d_ptr = new ActionPropertyManagerPrivate();
}
ActionPropertyManager::~ActionPropertyManager()
{
delete d_ptr;
d_ptr = NULL;
}
QString ActionPropertyManager::value( const QtProperty *p ) const
{
return valueText( p );
}
void ActionPropertyManager::setValue( QtProperty *p, const QString &value )
{
if( !d_ptr->values.contains( p ) )
return;
if( d_ptr->values[ p ] == value )
return;
d_ptr->values[ p ] = value;
Q_EMIT propertyChanged( p );
Q_EMIT valueChanged( p, value );
}
bool ActionPropertyManager::hasValue( const QtProperty *p ) const
{
return d_ptr->values.contains( p );
}
QString ActionPropertyManager::valueText( const QtProperty *p ) const
{
if( !d_ptr->values.contains( p ) )
return "";
return d_ptr->values[ p ];
}
void ActionPropertyManager::initializeProperty( QtProperty *p )
{
if( d_ptr->values.contains( p ) )
return;
d_ptr->values[ p ] = "";
}
void ActionPropertyManager::uninitializeProperty( QtProperty *p )
{
d_ptr->values.remove( p );
}
//////////////////////////////////////////////////////////////////// Factory ///////////////////////////////////////////////////////////////////////
struct ActionEditorFactoryPrivate
{
QMap< QtProperty*, QList< ActionPropertyEditor* > > createdEditors;
QMap< ActionPropertyEditor*, QtProperty* > editorToProperty;
~ActionEditorFactoryPrivate()
{
createdEditors.clear();
QMap< ActionPropertyEditor*, QtProperty* >::iterator itr = editorToProperty.begin();
while( itr != editorToProperty.end() )
{
delete itr.key();
++itr;
}
editorToProperty.clear();
}
void addEditor( QtProperty *p, ActionPropertyEditor *editor )
{
QMap< QtProperty*, QList< ActionPropertyEditor* > >::iterator itr = createdEditors.find( p );
if( itr != createdEditors.end() )
{
itr->push_back( editor );
}
else
{
QList< ActionPropertyEditor* > l;
l.push_back( editor );
createdEditors.insert( p, l );
}
editorToProperty.insert( editor, p );
}
void removeEditor( QObject *o )
{
// Remove from editorToProperty first
QMap< ActionPropertyEditor*, QtProperty* >::iterator itr1 = editorToProperty.begin();
while( itr1 != editorToProperty.end() )
{
if( itr1.key() == o )
break;
++itr1;
}
if( itr1 != editorToProperty.end() )
editorToProperty.erase( itr1 );
// Then from createdEditors
QMap< QtProperty*, QList< ActionPropertyEditor* > >::iterator itr2 = createdEditors.begin();
while( itr2 != createdEditors.end() )
{
QList< ActionPropertyEditor* > &l = *itr2;
QList< ActionPropertyEditor* >::iterator itr = l.begin();
while( itr != l.end() )
{
if( *itr == o )
{
QList< ActionPropertyEditor* >::iterator d = itr;
++itr;
l.erase( d );
continue;
}
++itr;
}
++itr2;
}
}
};
ActionEditorFactory::ActionEditorFactory( QObject *parent ) :
QtAbstractEditorFactory( parent )
{
d_ptr = new ActionEditorFactoryPrivate();
}
ActionEditorFactory::~ActionEditorFactory()
{
delete d_ptr;
d_ptr = NULL;
}
void ActionEditorFactory::connectPropertyManager( ActionPropertyManager *manager )
{
connect( manager, SIGNAL( valueChanged( QtProperty*, const QString& ) ), this, SLOT( onPropertyChanged( QtProperty*, const QString& ) ) );
}
void ActionEditorFactory::disconnectPropertyManager( ActionPropertyManager *manager )
{
disconnect( manager, SIGNAL( valueChanged( QtProperty*, const QString& ) ), this, SLOT( onPropertyChanged( QtProperty*, const QString& ) ) );
}
QWidget* ActionEditorFactory::createEditor( ActionPropertyManager *manager, QtProperty *p, QWidget *parent )
{
ActionPropertyEditor *editor = new ActionPropertyEditor( parent );
editor->setValue( manager->value( p ) );
connect( editor, SIGNAL( valueChanged( const QString& ) ), this, SLOT( onSetValue( const QString& ) ) );
connect( editor, SIGNAL( destroyed( QObject* ) ), this, SLOT( onEditorDestroyed( QObject* ) ) );
d_ptr->addEditor( p, editor );
return editor;
}
void ActionEditorFactory::onPropertyChanged( QtProperty *p, const QString &value )
{
QMap< QtProperty*, QList< ActionPropertyEditor* > >::iterator itr = d_ptr->createdEditors.find( p );
if( itr == d_ptr->createdEditors.end() )
return;
QList< ActionPropertyEditor* > &l = *itr;
QList< ActionPropertyEditor* >::iterator i = l.begin();
while( i != l.end() )
{
ActionPropertyEditor *editor = *i;
editor->blockSignals( true );
editor->setValue( value );
editor->blockSignals( false );
++i;
}
}
void ActionEditorFactory::onSetValue( const QString &value )
{
QObject *s = sender();
ActionPropertyEditor *editor = qobject_cast< ActionPropertyEditor* >( s );
if( editor == NULL )
return;
QMap< ActionPropertyEditor*, QtProperty* >::iterator itr = d_ptr->editorToProperty.find( editor );
if( itr == d_ptr->editorToProperty.end() )
return;
QtProperty *p = *itr;
ActionPropertyManager *manager = qobject_cast< ActionPropertyManager* >( p->propertyManager() );
if( manager == NULL )
return;
blockSignals( true );
manager->setValue( p, value );
blockSignals( false );
}
void ActionEditorFactory::onEditorDestroyed( QObject *editor )
{
d_ptr->removeEditor( editor );
}
//////////////////////////////////////////////////////////////////////// Editor //////////////////////////////////////////////////////////////////
ActionPropertyEditor::ActionPropertyEditor( QWidget *parent ) :
QWidget( parent )
{
setupUi();
setupConnections();
}
ActionPropertyEditor::~ActionPropertyEditor()
{
}
void ActionPropertyEditor::setValue( const QString &value )
{
if( lineEdit->text() == value )
return;
disableConnections();
lineEdit->setText( value );
setupConnections();
}
void ActionPropertyEditor::showEvent( QShowEvent *e )
{
QWidget::showEvent( e );
}
void ActionPropertyEditor::onToolButtonClicked()
{
ActionList d;
d.load();
int result = d.exec();
if( QDialog::Accepted != result )
return;
lineEdit->setText( d.getSelectedAction() );
}
void ActionPropertyEditor::onTextChanged( const QString &text )
{
Q_EMIT valueChanged( text );
}
void ActionPropertyEditor::setupConnections()
{
connect( toolButton, SIGNAL( clicked( bool ) ), this, SLOT( onToolButtonClicked() ) );
connect( lineEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( onTextChanged( const QString& ) ) );
}
void ActionPropertyEditor::disableConnections()
{
disconnect( toolButton, SIGNAL( clicked( bool ) ), this, SLOT( onToolButtonClicked() ) );
disconnect( lineEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( onTextChanged( const QString& ) ) );
}
void ActionPropertyEditor::setupUi()
{
lineEdit = new QLineEdit();
toolButton = new QToolButton();
toolButton->setText( "..." );
QHBoxLayout *lt = new QHBoxLayout( this );
lt->setContentsMargins( 0, 0, 0, 0 );
lt->setSpacing( 0 );
lt->addWidget( lineEdit );
lt->addWidget( toolButton );
setFocusProxy( lineEdit );
setSizePolicy( QSizePolicy::Ignored, QSizePolicy::Fixed );
}

View file

@ -0,0 +1,125 @@
// Ryzom Core Studio GUI Editor plugin <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 ACTION_PROPERTY_MANAGER
#define ACTION_PROPERTY_MANAGER
#define QT_QTPROPERTYBROWSER_IMPORT
#include "3rdparty/qtpropertybrowser/qtpropertybrowser.h"
#include <QString>
/////////////////////////////////////////////////////// Manager ///////////////////////////////////////////////////////////////////////////
struct ActionPropertyManagerPrivate;
class ActionPropertyManager : public QtAbstractPropertyManager
{
Q_OBJECT
public:
ActionPropertyManager( QObject *parent = NULL );
~ActionPropertyManager();
QString value( const QtProperty *p ) const;
public Q_SLOTS:
void setValue( QtProperty *p, const QString &value );
Q_SIGNALS:
void valueChanged( QtProperty *p, const QString &value );
protected:
bool hasValue( const QtProperty *p ) const;
QString valueText( const QtProperty *p ) const;
void initializeProperty( QtProperty *p );
void uninitializeProperty( QtProperty *p );
private:
ActionPropertyManagerPrivate *d_ptr;
Q_DISABLE_COPY( ActionPropertyManager );
};
////////////////////////////////////////////////////////////////// Factory /////////////////////////////////////////////////////////////////////////
struct ActionEditorFactoryPrivate;
class ActionEditorFactory : public QtAbstractEditorFactory< ActionPropertyManager >
{
Q_OBJECT
public:
ActionEditorFactory( QObject *parent = NULL );
~ActionEditorFactory();
protected:
void connectPropertyManager( ActionPropertyManager *manager );
void disconnectPropertyManager( ActionPropertyManager *manager );
QWidget* createEditor( ActionPropertyManager *manager, QtProperty *p, QWidget *parent );
private Q_SLOTS:
void onPropertyChanged( QtProperty *p, const QString &value );
void onSetValue( const QString &value );
void onEditorDestroyed( QObject *editor );
private:
ActionEditorFactoryPrivate *d_ptr;
Q_DISABLE_COPY( ActionEditorFactory );
};
///////////////////////////////////////////////////////////////// Editor ///////////////////////////////////////////////////////////////////////////
class QLineEdit;
class QToolButton;
class ActionPropertyEditor : public QWidget
{
Q_OBJECT
public:
ActionPropertyEditor( QWidget *parent = NULL );
~ActionPropertyEditor();
public Q_SLOTS:
void setValue( const QString &value );
protected:
void showEvent( QShowEvent *e );
private Q_SLOTS:
void onToolButtonClicked();
void onTextChanged( const QString &text );
Q_SIGNALS:
void valueChanged( const QString &value );
private:
void setupUi();
void setupConnections();
void disableConnections();
QLineEdit *lineEdit;
QToolButton *toolButton;
};
#endif

View file

@ -26,6 +26,8 @@
#include "widget_info_tree.h"
#include <QList>
#include "action_property_manager.h"
namespace
{
class NelBMAlign
@ -368,9 +370,11 @@ namespace GUIEditor
browser = NULL;
propertyMgr = new QtVariantPropertyManager;
enumMgr = new QtEnumPropertyManager;
actionMgr = new ActionPropertyManager;
variantFactory = new QtVariantEditorFactory;
enumFactory = new QtEnumEditorFactory;
actionFactory = new ActionEditorFactory;
ttPairs[ "tooltip_posref" ] = "tooltip_parent_posref";
ttPairs[ "tooltip_parent_posref" ] = "tooltip_posref";
@ -381,11 +385,15 @@ namespace GUIEditor
CPropBrowserCtrl::~CPropBrowserCtrl()
{
delete actionMgr;
actionMgr = NULL;
delete enumMgr;
enumMgr = NULL;
delete propertyMgr;
propertyMgr = NULL;
delete actionFactory;
actionFactory = NULL;
delete variantFactory;
variantFactory = NULL;
delete enumFactory;
@ -447,7 +455,7 @@ namespace GUIEditor
// probably the clear() method clears them too...
browser->setFactoryForManager( propertyMgr, variantFactory );
browser->setFactoryForManager( enumMgr, enumFactory );
browser->setFactoryForManager( actionMgr, actionFactory );
enablePropertyWatchers();
}
@ -617,12 +625,27 @@ namespace GUIEditor
}
}
void CPropBrowserCtrl::onActionPropertyChanged( QtProperty *p, const QString &v )
{
QString propName = p->propertyName();
CInterfaceElement *e = CWidgetManager::getInstance()->getElementFromId( currentElement );
if( e == NULL )
return;
e->setProperty( propName.toUtf8().constData(), v.toUtf8().constData() );
}
void CPropBrowserCtrl::enablePropertyWatchers()
{
connect( propertyMgr, SIGNAL( valueChanged( QtProperty*, const QVariant& ) ),
this, SLOT( onPropertyChanged( QtProperty*, const QVariant& ) ) );
connect( enumMgr, SIGNAL( valueChanged( QtProperty*, int ) ),
this, SLOT( onEnumPropertyChanged( QtProperty*, int ) ) );
connect( actionMgr, SIGNAL( valueChanged( QtProperty*, const QString& ) ),
this, SLOT( onActionPropertyChanged( QtProperty*, const QString& ) ) );
}
void CPropBrowserCtrl::disablePropertyWatchers()
@ -631,6 +654,9 @@ namespace GUIEditor
this, SLOT( onPropertyChanged( QtProperty*, const QVariant& ) ) );
disconnect( enumMgr, SIGNAL( valueChanged( QtProperty*, int ) ),
this, SLOT( onEnumPropertyChanged( QtProperty*, int ) ) );
disconnect( actionMgr, SIGNAL( valueChanged( QtProperty*, const QString& ) ),
this, SLOT( onActionPropertyChanged( QtProperty*, const QString& ) ) );
}
void CPropBrowserCtrl::setupProperties( const std::string &type, const CInterfaceElement *element )
@ -657,6 +683,21 @@ namespace GUIEditor
QtVariantProperty *p = NULL;
QVariant v;
if( prop.propType == "action" )
{
std::string j = element->getProperty( prop.propName );
if( j.empty() )
return;
QtProperty *pp = actionMgr->addProperty( prop.propName.c_str() );
if( pp == NULL )
return;
actionMgr->setValue( pp, j.c_str() );
browser->addProperty( pp );
}
else
if( prop.propType == "bitmap_align" )
{
std::string j = element->getProperty( prop.propName );

View file

@ -31,6 +31,9 @@ class QtEnumEditorFactory;
class QtProperty;
class QVariant;
class ActionPropertyManager;
class ActionEditorFactory;
namespace NLGUI
{
class CInterfaceElement;
@ -59,6 +62,7 @@ namespace GUIEditor
private Q_SLOTS:
void onPropertyChanged( QtProperty *prop, const QVariant &v );
void onEnumPropertyChanged( QtProperty *prop, int value );
void onActionPropertyChanged( QtProperty *p, const QString &v );
private:
void enablePropertyWatchers();
@ -70,9 +74,11 @@ namespace GUIEditor
QtTreePropertyBrowser *browser;
QtVariantPropertyManager *propertyMgr;
QtEnumPropertyManager *enumMgr;
ActionPropertyManager *actionMgr;
QtVariantEditorFactory *variantFactory;
QtEnumEditorFactory *enumFactory;
ActionEditorFactory *actionFactory;
std::string currentElement;
std::map< std::string, SWidgetInfo > widgetInfo;

View file

@ -60,7 +60,7 @@
</property>
<property>
<name>onover</name>
<type>string</type>
<type>action</type>
<default></default>
</property>
<property>
@ -70,7 +70,7 @@
</property>
<property>
<name>onclick_l</name>
<type>string</type>
<type>action</type>
<default></default>
</property>
<property>
@ -80,7 +80,7 @@
</property>
<property>
<name>ondblclick_l</name>
<type>string</type>
<type>action</type>
<default></default>
</property>
<property>
@ -90,7 +90,7 @@
</property>
<property>
<name>onclick_r</name>
<type>string</type>
<type>action</type>
<default></default>
</property>
<property>
@ -100,7 +100,7 @@
</property>
<property>
<name>onlongclick_l</name>
<type>string</type>
<type>action</type>
<default></default>
</property>
<property>
@ -110,7 +110,7 @@
</property>
<property>
<name>onclock_tick</name>
<type>string</type>
<type>action</type>
<default></default>
</property>
<property>

View file

@ -110,7 +110,7 @@
</property>
<property>
<name>on_open</name>
<type>string</type>
<type>action</type>
<default></default>
</property>
<property>
@ -120,7 +120,7 @@
</property>
<property>
<name>on_close</name>
<type>string</type>
<type>action</type>
<default></default>
</property>
<property>
@ -130,7 +130,7 @@
</property>
<property>
<name>on_close_button</name>
<type>string</type>
<type>action</type>
<default></default>
</property>
<property>
@ -140,7 +140,7 @@
</property>
<property>
<name>on_move</name>
<type>string</type>
<type>action</type>
<default></default>
</property>
<property>
@ -150,7 +150,7 @@
</property>
<property>
<name>on_deactive_check</name>
<type>string</type>
<type>action</type>
<default></default>
</property>
<property>
@ -160,7 +160,7 @@
</property>
<property>
<name>on_resize</name>
<type>string</type>
<type>action</type>
<default></default>
</property>
<property>
@ -170,7 +170,7 @@
</property>
<property>
<name>on_alpha_settings_changed</name>
<type>string</type>
<type>action</type>
<default></default>
</property>
<property>
@ -180,7 +180,7 @@
</property>
<property>
<name>on_begin_move</name>
<type>string</type>
<type>action</type>
<default></default>
</property>
<property>

View file

@ -40,7 +40,7 @@
</property>
<property>
<name>on_active</name>
<type>string</type>
<type>action</type>
<default></default>
</property>
<property>
@ -50,7 +50,7 @@
</property>
<property>
<name>on_deactive</name>
<type>string</type>
<type>action</type>
<default></default>
</property>
<property>
@ -80,7 +80,7 @@
</property>
<property>
<name>group_onclick_r</name>
<type>string</type>
<type>action</type>
<default></default>
</property>
<property>
@ -90,7 +90,7 @@
</property>
<property>
<name>group_onclick_l</name>
<type>string</type>
<type>action</type>
<default></default>
</property>
<property>
@ -100,7 +100,7 @@
</property>
<property>
<name>on_enter</name>
<type>string</type>
<type>action</type>
<default>handler</default>
</property>
<property>

View file

@ -10,7 +10,7 @@
<properties>
<property>
<name>on_wheel_up</name>
<type>string</type>
<type>action</type>
<default></default>
</property>
<property>
@ -20,7 +20,7 @@
</property>
<property>
<name>on_wheel_down</name>
<type>string</type>
<type>action</type>
<default></default>
</property>
<property>