From cc86cdd3ef511a3bf9e82c291ade4efed389a149 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Sun, 7 Jul 2013 03:23:39 +0200 Subject: [PATCH] ShaderEditorWidget will now load/save it's content. --HG-- branch : gsoc2013-dfighter --- .../material_editor_window.cpp | 1 - .../material_editor/material_widget.cpp | 13 ++-- .../plugins/material_editor/material_widget.h | 3 +- .../plugins/material_editor/shader_editor.cpp | 59 ++++++++----------- .../plugins/material_editor/shader_editor.h | 12 ++-- .../plugins/material_editor/shader_widget.cpp | 53 ++++------------- .../plugins/material_editor/shader_widget.h | 2 +- 7 files changed, 49 insertions(+), 94 deletions(-) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_editor_window.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_editor_window.cpp index cf805e0fd..6b5d5ab27 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_editor_window.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_editor_window.cpp @@ -142,7 +142,6 @@ namespace MaterialEditor void MaterialEditorWindow::onShadersClicked() { - shaderWidget->load(); shaderWidget->show(); } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_widget.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_widget.cpp index 1ebcab5fb..13e88141e 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_widget.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_widget.cpp @@ -133,6 +133,12 @@ namespace MaterialEditor shaderCB->removeItem( i ); } + void MaterialWidget::setNel3DIface( CNel3DInterface *iface ) + { + nl3dIface = iface; + shaderEditorWidget->setNel3DInterface( iface ); + } + void MaterialWidget::getCurrentPass( QString &pass ) { pass = passCB->currentText(); @@ -161,11 +167,8 @@ namespace MaterialEditor void MaterialWidget::onShaderEditClicked() { - shaderEditorWidget->show(); - } - - void MaterialWidget::onShaderEditOKClicked() - { + shaderEditorWidget->load( shaderCB->currentText() ); + int result = shaderEditorWidget->exec(); } void MaterialWidget::onPassCBChanged( const QString &text ) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_widget.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_widget.h index a4d75220b..6909c0ac3 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_widget.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_widget.h @@ -45,7 +45,7 @@ namespace MaterialEditor void onShaderAdded( const QString &name ); void onShaderRemoved( const QString &name ); - void setNel3DIface( CNel3DInterface *iface ){ nl3dIface = iface; } + void setNel3DIface( CNel3DInterface *iface ); void getCurrentPass( QString &pass ); @@ -62,7 +62,6 @@ namespace MaterialEditor private Q_SLOTS: void onPassEditClicked(); void onShaderEditClicked(); - void onShaderEditOKClicked(); void onPassCBChanged( const QString &text ); }; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/shader_editor.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/shader_editor.cpp index dd9eb602b..cdfb9ec59 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/shader_editor.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/shader_editor.cpp @@ -16,6 +16,7 @@ #include "shader_editor.h" +#include "nel3d_interface.h" namespace MaterialEditor { @@ -23,6 +24,7 @@ namespace MaterialEditor QDialog( parent ) { setupUi( this ); + nl3dIface = NULL; setupConnections(); } @@ -30,46 +32,11 @@ namespace MaterialEditor { } - void ShaderEditorWidget::getName( QString &name ) - { - name = nameEdit->text(); - } - void ShaderEditorWidget::getDescription( QString &desc ) { desc = descriptionEdit->toPlainText(); } - void ShaderEditorWidget::getVertexShader( QString &vs ) - { - vs = vsEdit->toPlainText(); - } - - void ShaderEditorWidget::getFragmentShader( QString &fs ) - { - fs = fsEdit->toPlainText(); - } - - void ShaderEditorWidget::setName( const QString &name ) - { - nameEdit->setText( name ); - } - - void ShaderEditorWidget::setDescription( const QString &desc ) - { - descriptionEdit->setPlainText( desc ); - } - - void ShaderEditorWidget::setVertexShader( const QString &vs ) - { - vsEdit->setPlainText( vs ); - } - - void ShaderEditorWidget::setFragmentShader( const QString &fs ) - { - fsEdit->setPlainText( fs ); - } - void ShaderEditorWidget::setupConnections() { connect( okButton, SIGNAL( clicked( bool ) ), this, SLOT( onOKClicked() ) ) ; @@ -78,6 +45,16 @@ namespace MaterialEditor void ShaderEditorWidget::onOKClicked() { + SShaderInfo info; + info.name = nameEdit->text().toUtf8().data(); + info.description = descriptionEdit->toPlainText().toUtf8().data(); + info.vp = vsEdit->toPlainText().toUtf8().data(); + info.fp = fsEdit->toPlainText().toUtf8().data(); + + bool ok = nl3dIface->updateShaderInfo( info ); + if( ok ) + nl3dIface->saveShader( info.name ); + accept(); } @@ -95,6 +72,18 @@ namespace MaterialEditor fsEdit->setPlainText( empty ); setResult( QDialog::Rejected ); } + + void ShaderEditorWidget::load( const QString &name ) + { + SShaderInfo info; + nl3dIface->getShaderInfo( name.toUtf8().data(), info ); + + nameEdit->setText( info.name.c_str() ); + descriptionEdit->setPlainText( info.description.c_str() ); + vsEdit->setPlainText( info.vp.c_str() ); + fsEdit->setPlainText( info.fp.c_str() ); + + } } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/shader_editor.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/shader_editor.h index 389aa47cc..3179babc3 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/shader_editor.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/shader_editor.h @@ -22,6 +22,8 @@ namespace MaterialEditor { + class CNel3DInterface; + class ShaderEditorWidget : public QDialog, public Ui::ShaderEditorWidget { Q_OBJECT @@ -29,17 +31,12 @@ namespace MaterialEditor ShaderEditorWidget( QDialog *parent = NULL ); ~ShaderEditorWidget(); - void getName( QString &name ); void getDescription( QString &desc ); - void getVertexShader( QString &vs ); - void getFragmentShader( QString &fs ); - void setName( const QString &name ); - void setDescription( const QString &desc ); - void setVertexShader( const QString &vs ); - void setFragmentShader( const QString &fs ); + void setNel3DInterface( CNel3DInterface *iface ){ nl3dIface = iface; } void reset(); + void load( const QString &name ); private Q_SLOTS: void onOKClicked(); @@ -47,6 +44,7 @@ namespace MaterialEditor private: void setupConnections(); + CNel3DInterface *nl3dIface; }; } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/shader_widget.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/shader_widget.cpp index a310b0a24..f019c38e0 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/shader_widget.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/shader_widget.cpp @@ -39,6 +39,12 @@ namespace MaterialEditor shaderEditorWidget = NULL; } + void ShaderWidget::setNel3DInterface( CNel3DInterface *iface ) + { + nl3dIface = iface; + shaderEditorWidget->setNel3DInterface( iface ); + } + void ShaderWidget::load() { std::vector< std::string > v; @@ -185,54 +191,15 @@ namespace MaterialEditor QString name = shaderList->item( i )->text(); shaderEditorWidget->reset(); + shaderEditorWidget->load( name ); - SShaderInfo info; - std::string n = name.toUtf8().data(); - bool ok = nl3dIface->getShaderInfo( n, info ); - if( !ok ) - { - QMessageBox::critical( - this, - tr( "Error retrieving shader data" ), - tr( "There was an error while trying to retrieve shader data!" ) - ); - - return; - } - - shaderEditorWidget->setName( info.name.c_str() ); - shaderEditorWidget->setDescription( info.description.c_str() ); - shaderEditorWidget->setVertexShader( info.vp.c_str() ); - shaderEditorWidget->setFragmentShader( info.fp.c_str() ); - int res = shaderEditorWidget->exec(); if( res == QDialog::Rejected ) return; - // save - QString s; - - shaderEditorWidget->getDescription( s ); - info.description = s.toUtf8().data(); - - shaderEditorWidget->getVertexShader( s ); - info.vp = s.toUtf8().data(); - - shaderEditorWidget->getFragmentShader( s ); - info.fp = s.toUtf8().data(); - - ok = nl3dIface->updateShaderInfo( info ); - if( !ok ) - { - QMessageBox::critical( - this, - tr( "Error saving shader data" ), - tr( "There was an error while trying to save shader data!" ) - ); - } - nl3dIface->saveShader( info.name ); - - description->setPlainText( info.description.c_str() ); + QString descr; + shaderEditorWidget->getDescription( descr ); + description->setPlainText( descr ); } void ShaderWidget::onRowChanged( int i ) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/shader_widget.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/shader_widget.h index 9659d5a03..d5941d253 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/shader_widget.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/shader_widget.h @@ -33,7 +33,7 @@ namespace MaterialEditor ShaderWidget( QWidget *parent = NULL ); ~ShaderWidget(); - void setNel3DInterface( CNel3DInterface *iface ){ nl3dIface = iface; } + void setNel3DInterface( CNel3DInterface *iface ); void load(); Q_SIGNALS: