We don't want duplicate property names and labels either.

--HG--
branch : gsoc2013-dfighter
hg/feature/gsoc2013-dfighter
dfighter1985 12 years ago
parent 9294cdc644
commit 2e6b1a834f

@ -18,6 +18,8 @@
#include "material_property_editor.h"
#include "nel3d_interface.h"
#include <QMessageBox>
namespace MaterialEditor
{
@ -160,12 +162,66 @@ namespace MaterialEditor
if( edit )
{
QTreeWidgetItem *item = treeWidget->currentItem();
MaterialProperty old;
old.prop = item->text( 0 );
old.label = item->text( 1 );
old.type = item->text( 2 );
if( old == prop )
return;
if( idExists( prop.prop ) )
{
QMessageBox::critical(
this,
tr( "Property Id" ),
tr( "A property with that Id already exists" )
);
return;
}
if( labelExists( prop.label ) )
{
QMessageBox::critical(
this,
tr( "Property label" ),
tr( "A property with that label already exists" )
);
return;
}
item->setData( 0, Qt::DisplayRole, prop.prop );
item->setData( 1, Qt::DisplayRole, prop.label );
item->setData( 2, Qt::DisplayRole, prop.type );
}
else
{
if( idExists( prop.prop ) )
{
QMessageBox::critical(
this,
tr( "Property Id" ),
tr( "A property with that Id already exists" )
);
return;
}
if( labelExists( prop.label ) )
{
QMessageBox::critical(
this,
tr( "Property label" ),
tr( "A property with that label already exists" )
);
return;
}
QTreeWidgetItem *item = new QTreeWidgetItem();
item->setData( 0, Qt::DisplayRole, prop.prop );
item->setData( 1, Qt::DisplayRole, prop.label );
@ -186,5 +242,29 @@ namespace MaterialEditor
connect( matPropEditWidget, SIGNAL( okClicked() ), this, SLOT( onEditorOKClicked() ) );
}
bool MatPropWidget::idExists( const QString &id )
{
int c = treeWidget->topLevelItemCount();
for( int i = 0; i < c; i++ )
{
if( id == treeWidget->topLevelItem( i )->text( 0 ) )
return true;
}
return false;
}
bool MatPropWidget::labelExists( const QString &label )
{
int c = treeWidget->topLevelItemCount();
for( int i = 0; i < c; i++ )
{
if( label == treeWidget->topLevelItem( i )->text( 1 ) )
return true;
}
return false;
}
}

@ -45,6 +45,10 @@ namespace MaterialEditor
private:
void setupConnections();
bool idExists( const QString &id );
bool labelExists( const QString &id );
bool edit;
bool changed;
MatPropEditWidget *matPropEditWidget;

@ -27,6 +27,20 @@ namespace MaterialEditor
QString prop;
QString label;
QString type;
bool operator==( const MaterialProperty &o )
{
if( o.prop != prop )
return false;
if( o.label != label )
return false;
if( o.type != type )
return false;
return true;
}
};
class MatPropEditWidget : public QWidget, public Ui::MatPropEditWidget

Loading…
Cancel
Save