From c9605dde578d56c2ea098fa8b6cb43807b64bd30 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Tue, 2 Jul 2013 19:05:53 +0200 Subject: [PATCH] Little bit of refactoring. --HG-- branch : gsoc2013-dfighter --- .../material_editor/material_properties.cpp | 64 ++----------------- .../material_editor/nel3d_interface.cpp | 28 ++++++++ .../plugins/material_editor/nel3d_interface.h | 9 ++- 3 files changed, 41 insertions(+), 60 deletions(-) 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 320b169a5..c0cb2e281 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 @@ -60,38 +60,7 @@ namespace MaterialEditor item->setData( 0, Qt::DisplayRole, QString( mp.id.c_str() ) ); item->setData( 1, Qt::DisplayRole, QString( mp.label.c_str() ) ); - QString type; - switch( mp.type ) - { - case SMatProp::Color: - type = "Color"; - break; - case SMatProp::Double: - type = "Double"; - break; - case SMatProp::Float: - type = "Float"; - break; - case SMatProp::Int: - type = "Int"; - break; - case SMatProp::Matrix4: - type = "Matrix4"; - break; - case SMatProp::Texture: - type = "Texture"; - break; - case SMatProp::Uint: - type = "UInt"; - break; - case SMatProp::Vector4: - type = "Vector4"; - break; - default: - type = ""; - break; - } - + QString type = SMatProp::typeIdToString( mp.type ).c_str(); item->setData( 2, Qt::DisplayRole, type ); treeWidget->addTopLevelItem( item ); @@ -118,39 +87,16 @@ namespace MaterialEditor std::vector< SMatProp > v; SMatProp p; QTreeWidgetItem *item = NULL; + std::string s; for( int i = 0; i < treeWidget->topLevelItemCount(); i++ ) { item = treeWidget->topLevelItem( i ); p.id = item->text( 0 ).toUtf8().data(); p.label = item->text( 1 ).toUtf8().data(); - - std::string t = item->text( 2 ).toUtf8().data(); - if( t == "Color" ) - p.type = SMatProp::Color; - else - if( t == "Double" ) - p.type = SMatProp::Double; - else - if( t == "Float" ) - p.type = SMatProp::Float; - else - if( t == "Int" ) - p.type = SMatProp::Int; - else - if( t == "Matrix4" ) - p.type = SMatProp::Matrix4; - else - if( t == "Texture" ) - p.type = SMatProp::Texture; - else - if( t == "UInt" ) - p.type = SMatProp::Uint; - else - if( t == "Vector4" ) - p.type = SMatProp::Vector4; - else - p.type = SMatProp::Int; + + s = item->text( 2 ).toUtf8().data(); + p.type = SMatProp::typeStringToId( s ); v.push_back( p ); } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.cpp index b8397bc1d..21b134a90 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.cpp @@ -23,6 +23,34 @@ namespace MaterialEditor { + const char *SMatProp::idToString[] = + { + "Color", + "Vector4", + "Float", + "Double", + "Int", + "Uint", + "Matrix4", + "Texture" + }; + + std::string SMatProp::typeIdToString( unsigned char id ) + { + if( id >= EType_count ) + return std::string(); + else + return std::string( idToString[ id ] ); + } + + unsigned char SMatProp::typeStringToId( const std::string &s ) + { + for( unsigned char i = 0; i < EType_count; i++ ) + if( s == idToString[ i ] ) + return i; + return 0; + } + void CRenderPassProxy::getProperties( std::vector< SMatProp > &v ) { uint32 count = pass->count(); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.h index a035eea6d..d0d3d6f06 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.h @@ -41,13 +41,20 @@ namespace MaterialEditor Int, Uint, Matrix4, - Texture + Texture, + EType_count }; + static std::string typeIdToString( unsigned char type ); + static unsigned char typeStringToId( const std::string &s ); + std::string id; std::string label; unsigned char type; std::string value; + + private: + static const char *idToString[]; }; class CRenderPassProxy