From 2e6b1a834f7bd78f82aeb6ccb5ba1e41048717f1 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Thu, 4 Jul 2013 03:02:37 +0200 Subject: [PATCH] We don't want duplicate property names and labels either. --HG-- branch : gsoc2013-dfighter --- .../material_editor/material_properties.cpp | 80 +++++++++++++++++++ .../material_editor/material_properties.h | 4 + .../material_property_editor.h | 14 ++++ 3 files changed, 98 insertions(+) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_properties.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_properties.cpp index e9262b0a3..6085cab51 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_properties.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_properties.cpp @@ -18,6 +18,8 @@ #include "material_property_editor.h" #include "nel3d_interface.h" +#include + 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; + } + } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_properties.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_properties.h index 3471420c1..1021f1e94 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_properties.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_properties.h @@ -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; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_property_editor.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_property_editor.h index c54eb4012..af9053191 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_property_editor.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_property_editor.h @@ -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