mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-12-17 22:48:44 +00:00
MODIFIED: #1471 Adding new property now works.
This commit is contained in:
parent
c7131429c9
commit
2f18aec5d4
7 changed files with 336 additions and 0 deletions
|
@ -56,6 +56,7 @@ SET(OVQT_PLUGIN_GUI_EDITOR_HDR
|
||||||
project_window.h
|
project_window.h
|
||||||
nel3d_widget.h
|
nel3d_widget.h
|
||||||
nelgui_widget.h
|
nelgui_widget.h
|
||||||
|
new_property_widget.h
|
||||||
)
|
)
|
||||||
|
|
||||||
SET(OVQT_PLUGIN_GUI_EDITOR_UIS
|
SET(OVQT_PLUGIN_GUI_EDITOR_UIS
|
||||||
|
@ -68,6 +69,7 @@ SET(OVQT_PLUGIN_GUI_EDITOR_UIS
|
||||||
proc_editor.ui
|
proc_editor.ui
|
||||||
action_editor.ui
|
action_editor.ui
|
||||||
project_window.ui
|
project_window.ui
|
||||||
|
new_property_widget.ui
|
||||||
)
|
)
|
||||||
|
|
||||||
SET(QT_USE_QTGUI TRUE)
|
SET(QT_USE_QTGUI TRUE)
|
||||||
|
|
|
@ -0,0 +1,123 @@
|
||||||
|
// Object Viewer Qt 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 "new_property_widget.h"
|
||||||
|
#include "widget_info_tree_node.h"
|
||||||
|
#include <qmessagebox.h>
|
||||||
|
|
||||||
|
|
||||||
|
namespace GUIEditor
|
||||||
|
{
|
||||||
|
NewPropertyWidget::NewPropertyWidget( QWidget *parent ) :
|
||||||
|
QWidget( parent )
|
||||||
|
{
|
||||||
|
widgetInfoTreeNode = NULL;
|
||||||
|
setupUi( this );
|
||||||
|
connect( addButton, SIGNAL( clicked( bool ) ), this, SLOT( onAddClicked() ) );
|
||||||
|
connect( cancelButton, SIGNAL( clicked( bool ) ), this, SLOT( hide() ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
NewPropertyWidget::~NewPropertyWidget()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void NewPropertyWidget::onAddClicked()
|
||||||
|
{
|
||||||
|
if( nameEdit->text().isEmpty() )
|
||||||
|
{
|
||||||
|
QMessageBox::warning( this,
|
||||||
|
tr( "Adding a new property" ),
|
||||||
|
tr( "You need to specify a name for the new property!" ),
|
||||||
|
QMessageBox::Ok
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( !checkName() )
|
||||||
|
{
|
||||||
|
QMessageBox::warning( this,
|
||||||
|
tr( "Adding a new property" ),
|
||||||
|
tr( "A property with that name already exists in the widget!" ),
|
||||||
|
QMessageBox::Ok
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( !checkDefaultValue() )
|
||||||
|
{
|
||||||
|
QMessageBox::warning( this,
|
||||||
|
tr( "Adding a new property" ),
|
||||||
|
tr( "You need to specify a valid default value." ),
|
||||||
|
QMessageBox::Ok
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SPropEntry prop;
|
||||||
|
prop.propName = nameEdit->text().toStdString();
|
||||||
|
prop.propType = typeCB->currentText().toStdString();
|
||||||
|
prop.propDefault = defvalEdit->text().toStdString();
|
||||||
|
widgetInfoTreeNode->addPropertyToAll( prop );
|
||||||
|
|
||||||
|
widgetInfoTreeNode = NULL;
|
||||||
|
hide();
|
||||||
|
|
||||||
|
Q_EMIT propertyAdded();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool NewPropertyWidget::checkName() const
|
||||||
|
{
|
||||||
|
if( widgetInfoTreeNode == NULL )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if( widgetInfoTreeNode->hasProperty( nameEdit->text().toStdString() ) )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool NewPropertyWidget::checkDefaultValue() const
|
||||||
|
{
|
||||||
|
if( widgetInfoTreeNode == NULL )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if( ( typeCB->currentText() != "string" ) && ( defvalEdit->text().isEmpty() ) )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if( typeCB->currentText() == "bool" )
|
||||||
|
{
|
||||||
|
if( defvalEdit->text().toUpper() == "TRUE" )
|
||||||
|
return true;
|
||||||
|
if( defvalEdit->text().toUpper() == "FALSE" )
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if( typeCB->currentText() == "int" )
|
||||||
|
{
|
||||||
|
bool ok = false;
|
||||||
|
defvalEdit->text().toInt( &ok );
|
||||||
|
if( ok )
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
// Object Viewer Qt 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 NEW_PROPERTY_WIDGET_H
|
||||||
|
#define NEW_PROPERTY_WIDGET_H
|
||||||
|
|
||||||
|
#include "ui_new_property_widget.h"
|
||||||
|
|
||||||
|
namespace GUIEditor
|
||||||
|
{
|
||||||
|
class CWidgetInfoTreeNode;
|
||||||
|
|
||||||
|
/// Widget for adding a new property
|
||||||
|
class NewPropertyWidget : public QWidget, public Ui::NewPropertyWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
NewPropertyWidget( QWidget *parent = NULL );
|
||||||
|
~NewPropertyWidget();
|
||||||
|
|
||||||
|
/// Sets the widget info, so that we can check for duplicates
|
||||||
|
void setWidgetInfo( CWidgetInfoTreeNode *node ){ widgetInfoTreeNode = node; }
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void onAddClicked();
|
||||||
|
|
||||||
|
/// Checks the validity of the property name field
|
||||||
|
bool checkName() const;
|
||||||
|
|
||||||
|
/// Checks the validity of the default value field
|
||||||
|
bool checkDefaultValue() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
CWidgetInfoTreeNode *widgetInfoTreeNode;
|
||||||
|
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
void propertyAdded();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
|
@ -0,0 +1,85 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>NewPropertyWidget</class>
|
||||||
|
<widget class="QWidget" name="NewPropertyWidget">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>299</width>
|
||||||
|
<height>121</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>New property</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QGridLayout" name="gridLayout_2">
|
||||||
|
<item row="0" column="0" colspan="2">
|
||||||
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="text">
|
||||||
|
<string>Name</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="1">
|
||||||
|
<widget class="QLineEdit" name="nameEdit"/>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QLabel" name="label_2">
|
||||||
|
<property name="text">
|
||||||
|
<string>Type</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QComboBox" name="typeCB">
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>string</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>int</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>bool</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="0">
|
||||||
|
<widget class="QLabel" name="label_3">
|
||||||
|
<property name="text">
|
||||||
|
<string>Default value</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="1">
|
||||||
|
<widget class="QLineEdit" name="defvalEdit"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QPushButton" name="addButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Add</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QPushButton" name="cancelButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Cancel</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
|
@ -138,12 +138,36 @@ namespace GUIEditor
|
||||||
children.clear();
|
children.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Checks if this node has this property
|
||||||
|
bool hasProperty( const std::string &name )
|
||||||
|
{
|
||||||
|
std::vector< SPropEntry >::const_iterator itr = info.findProp( name );
|
||||||
|
if( itr != info.props.end() )
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/// Add new property to the node
|
/// Add new property to the node
|
||||||
void addProperty( const SPropEntry &prop )
|
void addProperty( const SPropEntry &prop )
|
||||||
{
|
{
|
||||||
info.props.push_back( prop );
|
info.props.push_back( prop );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Add new property to the node and all children
|
||||||
|
void addPropertyToAll( const SPropEntry &prop )
|
||||||
|
{
|
||||||
|
addProperty( prop );
|
||||||
|
|
||||||
|
std::vector< CWidgetInfoTreeNode* >::iterator itr = children.begin();
|
||||||
|
while( itr != children.end() )
|
||||||
|
{
|
||||||
|
( *itr )->addPropertyToAll( prop );
|
||||||
|
++itr;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/// Removes this property from the node
|
/// Removes this property from the node
|
||||||
void removeProperty( const SPropEntry &prop )
|
void removeProperty( const SPropEntry &prop )
|
||||||
{
|
{
|
||||||
|
|
|
@ -16,19 +16,27 @@
|
||||||
|
|
||||||
#include "widget_properties.h"
|
#include "widget_properties.h"
|
||||||
#include "widget_info_tree.h"
|
#include "widget_info_tree.h"
|
||||||
|
#include "new_property_widget.h"
|
||||||
#include <qmessagebox.h>
|
#include <qmessagebox.h>
|
||||||
|
|
||||||
namespace GUIEditor{
|
namespace GUIEditor{
|
||||||
CWidgetProperties::CWidgetProperties( QWidget *parent ) :
|
CWidgetProperties::CWidgetProperties( QWidget *parent ) :
|
||||||
QWidget( parent )
|
QWidget( parent )
|
||||||
{
|
{
|
||||||
|
newPropertyWidget = new NewPropertyWidget();
|
||||||
|
|
||||||
setupUi( this );
|
setupUi( this );
|
||||||
connect( rmWButton, SIGNAL( clicked( bool ) ), this, SLOT( onRemoveWButtonClicked() ) );
|
connect( rmWButton, SIGNAL( clicked( bool ) ), this, SLOT( onRemoveWButtonClicked() ) );
|
||||||
connect( rmPButton, SIGNAL( clicked( bool ) ), this, SLOT( onRemovePButtonClicked() ) );
|
connect( rmPButton, SIGNAL( clicked( bool ) ), this, SLOT( onRemovePButtonClicked() ) );
|
||||||
|
connect( addPButton, SIGNAL( clicked( bool ) ), this, SLOT( onAddPButtonClicked() ) );
|
||||||
|
connect( newPropertyWidget, SIGNAL( propertyAdded() ), this, SLOT( onPropertyAdded() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
CWidgetProperties::~CWidgetProperties()
|
CWidgetProperties::~CWidgetProperties()
|
||||||
{
|
{
|
||||||
|
delete newPropertyWidget;
|
||||||
|
newPropertyWidget = NULL;
|
||||||
|
tree = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWidgetProperties::setupWidgetInfo( CWidgetInfoTree *tree )
|
void CWidgetProperties::setupWidgetInfo( CWidgetInfoTree *tree )
|
||||||
|
@ -102,6 +110,31 @@ namespace GUIEditor{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void CWidgetProperties::onAddWButtonClicked()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void CWidgetProperties::onAddPButtonClicked()
|
||||||
|
{
|
||||||
|
if( widgetList->count() == 0 )
|
||||||
|
return;
|
||||||
|
|
||||||
|
if( ( widgetList->currentRow() >= widgetList->count() ) || ( widgetList->currentRow() < 0 ) )
|
||||||
|
return;
|
||||||
|
|
||||||
|
CWidgetInfoTreeNode *node = tree->findNodeByName( widgetList->currentItem()->text().toStdString() );
|
||||||
|
if( node == NULL )
|
||||||
|
return;
|
||||||
|
|
||||||
|
newPropertyWidget->setWidgetInfo( node );
|
||||||
|
newPropertyWidget->show();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CWidgetProperties::onPropertyAdded()
|
||||||
|
{
|
||||||
|
onListSelectionChanged( widgetList->currentRow() );
|
||||||
|
}
|
||||||
|
|
||||||
void CWidgetProperties::buildWidgetList()
|
void CWidgetProperties::buildWidgetList()
|
||||||
{
|
{
|
||||||
widgetList->clear();
|
widgetList->clear();
|
||||||
|
|
|
@ -27,7 +27,10 @@
|
||||||
namespace GUIEditor
|
namespace GUIEditor
|
||||||
{
|
{
|
||||||
class CWidgetInfoTree;
|
class CWidgetInfoTree;
|
||||||
|
class NewPropertyWidget;
|
||||||
|
|
||||||
|
/// Widget that shows all available GUI widgets and their properties,
|
||||||
|
/// Also allows the user to add / remove widgets and properties
|
||||||
class CWidgetProperties : public QWidget, public Ui::WidgetProperties
|
class CWidgetProperties : public QWidget, public Ui::WidgetProperties
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -46,6 +49,14 @@ namespace GUIEditor
|
||||||
/// Removes widget property from the list
|
/// Removes widget property from the list
|
||||||
void onRemovePButtonClicked();
|
void onRemovePButtonClicked();
|
||||||
|
|
||||||
|
/// Adds a widget to the list
|
||||||
|
void onAddWButtonClicked();
|
||||||
|
|
||||||
|
/// Adds a widget property to the list
|
||||||
|
void onAddPButtonClicked();
|
||||||
|
|
||||||
|
void onPropertyAdded();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// Builds the widget list
|
/// Builds the widget list
|
||||||
void buildWidgetList();
|
void buildWidgetList();
|
||||||
|
@ -54,6 +65,7 @@ namespace GUIEditor
|
||||||
void setPropsOf( const char *name );
|
void setPropsOf( const char *name );
|
||||||
|
|
||||||
CWidgetInfoTree *tree;
|
CWidgetInfoTree *tree;
|
||||||
|
NewPropertyWidget *newPropertyWidget;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue