Skip to content
Snippets Groups Projects
Commit c3022675 authored by Mathias Paulin's avatar Mathias Paulin :speech_balloon:
Browse files

Fix sync between code edition and code loading

parent c5e2b13e
No related branches found
No related tags found
No related merge requests found
...@@ -196,43 +196,42 @@ void RendererPanel::addCodeEditor( const std::string& name, ...@@ -196,43 +196,42 @@ void RendererPanel::addCodeEditor( const std::string& name,
{ {
dialog = new QDialog( this ); dialog = new QDialog( this );
auto buttonBox =
new QDialogButtonBox( QDialogButtonBox::Save | QDialogButtonBox::Close );
auto textEditor = new GlslEditor( dialog ); auto textEditor = new GlslEditor( dialog );
textEditor->setPlainText( QString::fromStdString( initialText() ) ); textEditor->setPlainText( QString::fromStdString( initialText() ) );
auto buttonBox =
new QDialogButtonBox( QDialogButtonBox::Save | QDialogButtonBox::Close, dialog );
connect( buttonBox, &QDialogButtonBox::accepted, [callback, textEditor]() { connect( buttonBox, &QDialogButtonBox::accepted, [callback, textEditor]() {
std::cout << "Accepted event received" << std::endl;
callback( textEditor->toPlainText().toStdString() ); callback( textEditor->toPlainText().toStdString() );
} ); } );
connect( connect(
buttonBox, &QDialogButtonBox::rejected, [callback, &dialog, initialText]() mutable { buttonBox, &QDialogButtonBox::rejected, [callback, &dialog, initialText]() mutable {
delete dialog; dialog->hide();
dialog = nullptr;
} ); } );
QVBoxLayout* mainLayout = new QVBoxLayout; QVBoxLayout* mainLayout = new QVBoxLayout;
mainLayout->addWidget( textEditor ); mainLayout->addWidget( textEditor );
mainLayout->addWidget( buttonBox ); mainLayout->addWidget( buttonBox );
dialog->setLayout( mainLayout ); dialog->setLayout( mainLayout );
} }
else
{
auto childs = dialog->children();
auto textEditor = dynamic_cast<GlslEditor*>( childs.first() );
if ( textEditor )
{ textEditor->setPlainText( QString::fromStdString( initialText() ) ); }
else
{
std::cout << "ERROR !!! Text editor is not the first child of the dialog"
<< std::endl;
}
}
dialog->show(); dialog->show();
dialog->raise(); dialog->raise();
dialog->activateWindow(); dialog->activateWindow();
}; };
connect( button, &QPushButton::clicked, editDialog ); connect( button, &QPushButton::clicked, editDialog );
/*
GlslEditor *editor{nullptr};
auto launchEditor= [this, callback, initialText, editor]() mutable {
if ( !editor ){
editor = new GlslEditor();
}
editor->show();
};
connect( button, &QPushButton::clicked, launchEditor );
*/
m_currentLayout->addWidget( button ); m_currentLayout->addWidget( button );
} }
......
...@@ -53,23 +53,23 @@ buildControllerGui( NodeBasedRenderer* renderer, const std::function<void()>& ap ...@@ -53,23 +53,23 @@ buildControllerGui( NodeBasedRenderer* renderer, const std::function<void()>& ap
controlPanel->beginLayout( QBoxLayout::LeftToRight ); controlPanel->beginLayout( QBoxLayout::LeftToRight );
controlPanel->beginLayout( QBoxLayout::TopToBottom ); controlPanel->beginLayout( QBoxLayout::TopToBottom );
auto visualizationFunction = controller.getAttribToColorFunc(); // auto visualizationFunction = controller.getAttribToColorFunc();
auto getAttribCode = [&controller]() { return controller.getAttribToColorFunc().first; }; auto getAttribCode = [&controller]() { return controller.getAttribToColorFunc().first; };
auto getColorCode = [&controller]() { return controller.getAttribToColorFunc().second; }; auto getColorCode = [&controller]() { return controller.getAttribToColorFunc().second; };
controlPanel->addCodeEditor( controlPanel->addCodeEditor(
"Edit attribute function", "Edit attribute function",
[&controller, visualizationFunction, appUpdateCallback]( const std::string& s ) { [&controller, getColorCode, appUpdateCallback]( const std::string& s ) {
controller.setAttribToColorFunc( s, visualizationFunction.second ); controller.setAttribToColorFunc( s, getColorCode() );
appUpdateCallback(); appUpdateCallback();
}, },
getAttribCode ); getAttribCode );
controlPanel->addCodeEditor( controlPanel->addCodeEditor(
"Edit Color function", "Edit Color function",
[&controller, visualizationFunction, appUpdateCallback]( const std::string& s ) { [&controller, getAttribCode, appUpdateCallback]( const std::string& s ) {
controller.setAttribToColorFunc( visualizationFunction.first, s ); controller.setAttribToColorFunc( getAttribCode(), s );
appUpdateCallback(); appUpdateCallback();
}, },
getColorCode ); getColorCode );
...@@ -77,23 +77,23 @@ buildControllerGui( NodeBasedRenderer* renderer, const std::function<void()>& ap ...@@ -77,23 +77,23 @@ buildControllerGui( NodeBasedRenderer* renderer, const std::function<void()>& ap
controlPanel->beginLayout( QBoxLayout::TopToBottom ); controlPanel->beginLayout( QBoxLayout::TopToBottom );
auto loadAttribFuncClbk = auto loadAttribFuncClbk =
[&controller, visualizationFunction, appUpdateCallback]( const std::string& file ) { [&controller, getColorCode, appUpdateCallback]( const std::string& file ) {
if ( file.empty() ) { return; } if ( file.empty() ) { return; }
std::cout << "Loading attrib function from file " << file << std::endl; std::cout << "Loading attrib function from file " << file << std::endl;
std::ifstream inFile( file ); std::ifstream inFile( file );
std::stringstream strStream; std::stringstream strStream;
strStream << inFile.rdbuf(); // read the file strStream << inFile.rdbuf(); // read the file
controller.setAttribToColorFunc( strStream.str(), visualizationFunction.second ); controller.setAttribToColorFunc( strStream.str(), getColorCode() );
appUpdateCallback(); appUpdateCallback();
}; };
auto loadColorFuncClbk = auto loadColorFuncClbk =
[&controller, visualizationFunction, appUpdateCallback]( const std::string& file ) { [&controller, getAttribCode, appUpdateCallback]( const std::string& file ) {
if ( file.empty() ) { return; } if ( file.empty() ) { return; }
std::cout << "Loading color function from file " << file << std::endl; std::cout << "Loading color function from file " << file << std::endl;
std::ifstream inFile( file ); std::ifstream inFile( file );
std::stringstream strStream; std::stringstream strStream;
strStream << inFile.rdbuf(); // read the file strStream << inFile.rdbuf(); // read the file
controller.setAttribToColorFunc( visualizationFunction.first, strStream.str() ); controller.setAttribToColorFunc( getAttribCode(), strStream.str() );
appUpdateCallback(); appUpdateCallback();
}; };
controlPanel->addFileInput( controlPanel->addFileInput(
...@@ -102,14 +102,13 @@ buildControllerGui( NodeBasedRenderer* renderer, const std::function<void()>& ap ...@@ -102,14 +102,13 @@ buildControllerGui( NodeBasedRenderer* renderer, const std::function<void()>& ap
controlPanel->endLayout( false ); controlPanel->endLayout( false );
controlPanel->beginLayout( QBoxLayout::TopToBottom ); controlPanel->beginLayout( QBoxLayout::TopToBottom );
auto saveAttribFuncClbk = [visualizationFunction, auto saveAttribFuncClbk = [getAttribCode, appUpdateCallback]( const std::string& file ) {
appUpdateCallback]( const std::string& file ) {
std::ofstream outFile( file ); std::ofstream outFile( file );
outFile << visualizationFunction.first; outFile << getAttribCode();
}; };
auto saveColorFuncClbk = [visualizationFunction, appUpdateCallback]( const std::string& file ) { auto saveColorFuncClbk = [getColorCode, appUpdateCallback]( const std::string& file ) {
std::ofstream outFile( file ); std::ofstream outFile( file );
outFile << visualizationFunction.second; outFile << getColorCode();
}; };
controlPanel->addFileOuput( controlPanel->addFileOuput(
"Save attribute func", saveAttribFuncClbk, "./", "Shaders (*.glsl)" ); "Save attribute func", saveAttribFuncClbk, "./", "Shaders (*.glsl)" );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment