parent
3c854dc1e2
commit
4a9fb9e013
@ -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>
|
Loading…
Reference in New Issue