#include <cpPlugins/Interface/ParametersQtDialog.h>
+#ifdef cpPlugins_Interface_QT4
+
#include <limits>
-#include <vector>
#include <cpPlugins/Interface/ParametersListWidget.h>
+#include <cpPlugins/Interface/ProcessObject.h>
+
+#include <vtkCommand.h>
+#include <vtkRenderWindowInteractor.h>
+
#include <QCheckBox>
-#include <QDialog>
-#include <QDialogButtonBox>
+#include <QComboBox>
#include <QDoubleSpinBox>
+#include <QFileDialog>
#include <QHBoxLayout>
-#include <QLabel>
+#include <QInputDialog>
#include <QLineEdit>
+#include <QPushButton>
#include <QWidget>
+/* TODO
+class SingleSeedCommand
+ : public vtkCommand
+{
+public:
+ static SingleSeedCommand* New( )
+ { return( new SingleSeedCommand ); }
+ virtual void Execute( vtkObject* caller, unsigned long eid, void* data )
+ {
+ // Get seed, avoiding segfaults!!!
+ if( eid != vtkCommand::PlacePointEvent || this->Dialog == NULL )
+ return;
+ vtkSeedWidget* widget = dynamic_cast< vtkSeedWidget* >( caller );
+ if( widget == NULL )
+ return;
+ vtkSeedRepresentation* rep = widget->GetSeedRepresentation( );
+ if( rep == NULL )
+ return;
+ if( rep->GetNumberOfSeeds( ) == 0 )
+ return;
+ double seed[ 3 ];
+ rep->GetSeedWorldPosition( 0, seed );
+
+ // Delete all seeds (remember that this command is just for one seed)
+ while( rep->GetNumberOfSeeds( ) > 0 )
+ widget->DeleteSeed( 0 );
+
+ if( this->Dialog->getParameters( )->HasIndex( this->Name ) )
+ {
+ }
+ else if( this->Dialog->getParameters( )->HasPoint( this->Name ) )
+ {
+ this->Dialog->getParameters( )->SetPoint( this->Name, 3, seed );
+ this->Dialog->updateParameters( );
+ auto filter = this->Dialog->getParameters( )->GetProcessObject( );
+ if( filter != NULL )
+ {
+ auto plugins = filter->GetPlugins( );
+ if( plugins != NULL )
+ {
+ auto app = plugins->GetApplication( );
+ if( app != NULL )
+ app->UpdateActualFilter( );
+
+ } // fi
+
+ } // fi
+
+ } // fi
+ }
+protected:
+ SingleSeedCommand( )
+ : vtkCommand( ),
+ Dialog( NULL )
+ {
+ }
+ virtual ~SingleSeedCommand( )
+ {
+ }
+
+public:
+ cpPlugins::Interface::ParametersQtDialog* Dialog;
+ std::string Name;
+};
+*/
+
// -------------------------------------------------------------------------
-bool cpPlugins::Interface::
-ParametersQtDialog(
- Parameters& parameters, const std::string& title, QWidget* parent
- )
+cpPlugins::Interface::ParametersQtDialog::
+ParametersQtDialog( QWidget* parent, Qt::WindowFlags f )
+ : QDialog( parent, f ),
+ m_Parameters( NULL ),
+ m_Interactive( false )
{
- // Create dialog with a simple layout
- QDialog* dlg = new QDialog( parent );
- dlg->setWindowFlags( Qt::FramelessWindowHint );
- dlg->setWindowFlags( Qt::WindowTitleHint );
- QGridLayout* gridLayout = new QGridLayout( dlg );
- QVBoxLayout* verticalLayout = new QVBoxLayout( );
+ this->m_Title = new QLabel( this );
+ this->m_Title->setText( "Parameters dialog title" );
+
+ this->m_MainLayout = new QGridLayout( this );
+ this->m_ToolsLayout = new QVBoxLayout( );
+ this->m_ToolsLayout->addWidget( this->m_Title );
+ this->m_MainLayout->addLayout( this->m_ToolsLayout, 0, 0, 1, 1 );
+}
- // Put a title
- QLabel* dlg_title = new QLabel( dlg );
- dlg_title->setText( title.c_str( ) );
- verticalLayout->addWidget( dlg_title );
+// -------------------------------------------------------------------------
+cpPlugins::Interface::ParametersQtDialog::
+~ParametersQtDialog( )
+{
+ delete this->m_Title;
+ delete this->m_ToolsLayout;
+ delete this->m_MainLayout;
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::Interface::
+Parameters* cpPlugins::Interface::ParametersQtDialog::
+getParameters( ) const
+{
+ return( this->m_Parameters );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::ParametersQtDialog::
+addInteractor( vtkRenderWindowInteractor* interactor )
+{
+ this->m_Interactors.insert( interactor );
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::Interface::ParametersQtDialog::
+TInteractors& cpPlugins::Interface::ParametersQtDialog::
+getInteractors( )
+{
+ return( this->m_Interactors );
+}
+
+// -------------------------------------------------------------------------
+const cpPlugins::Interface::ParametersQtDialog::
+TInteractors& cpPlugins::Interface::ParametersQtDialog::
+getInteractors( ) const
+{
+ return( this->m_Interactors );
+}
+
+// -------------------------------------------------------------------------
+bool cpPlugins::Interface::ParametersQtDialog::
+isInteractive( ) const
+{
+ return( this->m_Interactive );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::ParametersQtDialog::
+setInteractive( bool i )
+{
+ this->m_Interactive = i;
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::ParametersQtDialog::
+interactiveOn( )
+{
+ this->m_Interactive = true;
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::ParametersQtDialog::
+interactiveOff( )
+{
+ this->m_Interactive = false;
+}
+
+// -------------------------------------------------------------------------
+bool cpPlugins::Interface::ParametersQtDialog::
+setParameters( Parameters* parameters )
+{
+ if( this->m_Parameters != NULL || parameters == NULL )
+ return( false );
+ this->m_Parameters = parameters;
+
+ // Set dialog title
+ auto filter = this->m_Parameters->GetProcessObject( );
+ std::stringstream title;
+ title << "Parameters for \"" << filter->GetName( ) << "\"";
+ this->m_Title->setText( title.str( ).c_str( ) );
// Put values
- std::vector< std::string > names = parameters.GetParameters( );
- std::vector< std::string >::const_iterator nIt = names.begin( );
- for( ; nIt != names.end( ); ++nIt )
+ this->m_Widgets.clear( );
+ auto& raw_params = this->m_Parameters->GetRawParameters( );
+ for( auto pIt = raw_params.begin( ); pIt != raw_params.end( ); ++pIt )
{
- Parameters::Type pt = parameters.GetParameterType( *nIt );
-
- /* TODO
- enum Type
- {
- Bool,
- Index,
- Point,
- StringList,
- BoolList,
- IntList,
- UintList,
- IndexList,
- PointList,
- NoType
- };
- */
QWidget* w_input = NULL;
- if( pt == Parameters::String )
+ switch( pIt->second.first )
+ {
+ case Parameters::String:
{
- QLineEdit* v_string = new QLineEdit( dlg );
- v_string->setText( "Enter some text!!!" );
+ QLineEdit* v_string = new QLineEdit( this );
+ v_string->setObjectName( pIt->first.c_str( ) );
+ v_string->setText( pIt->second.second.c_str( ) );
w_input = v_string;
}
- else if( pt == Parameters::Bool )
+ break;
+ case Parameters::Bool:
{
- QCheckBox* v_bool = new QCheckBox( dlg );
+ QCheckBox* v_bool = new QCheckBox( this );
+ v_bool->setObjectName( pIt->first.c_str( ) );
v_bool->setText( "[ON/OFF]" );
- v_bool->setChecked( parameters.GetValueAsBool( *nIt ) );
+ v_bool->setChecked( pIt->second.second == "1" );
w_input = v_bool;
}
- else if( pt == Parameters::Uint )
+ break;
+ case Parameters::Int:
+ case Parameters::Uint:
{
- QSpinBox* v_uint = new QSpinBox( dlg );
- v_uint->setMinimum( 0 );
+ std::istringstream tok_str( pIt->second.second );
+ int v;
+ tok_str >> v;
+ QSpinBox* v_uint = new QSpinBox( this );
+ v_uint->setObjectName( pIt->first.c_str( ) );
+ if( pIt->second.first == Parameters::Uint )
+ v_uint->setMinimum( 0 );
+ else
+ v_uint->setMinimum( -std::numeric_limits< int >::max( ) );
v_uint->setMaximum( std::numeric_limits< int >::max( ) );
- v_uint->setValue( parameters.GetValueAsUint( *nIt ) );
+ v_uint->setValue( v );
w_input = v_uint;
}
- else if( pt == Parameters::Int )
+ break;
+ case Parameters::Real:
{
- QSpinBox* v_int = new QSpinBox( dlg );
- v_int->setMinimum( -std::numeric_limits< int >::max( ) );
- v_int->setMaximum( std::numeric_limits< int >::max( ) );
- v_int->setValue( parameters.GetValueAsInt( *nIt ) );
- w_input = v_int;
- }
- else if( pt == Parameters::Real )
- {
- QDoubleSpinBox* v_double = new QDoubleSpinBox( dlg );
+ std::istringstream tok_str( pIt->second.second );
+ double v;
+ tok_str >> v;
+ QDoubleSpinBox* v_double = new QDoubleSpinBox( this );
+ v_double->setObjectName( pIt->first.c_str( ) );
v_double->setDecimals( 3 );
v_double->setMinimum( -std::numeric_limits< double >::max( ) );
v_double->setMaximum( std::numeric_limits< double >::max( ) );
- v_double->setValue( parameters.GetValueAsReal( *nIt ) );
+ v_double->setValue( v );
w_input = v_double;
}
- else if(
- pt == Parameters::StringList ||
- pt == Parameters::IntList ||
- pt == Parameters::UintList ||
- pt == Parameters::RealList
- )
+ break;
+ case Parameters::OpenFileName:
+ {
+ QFrame* frame = new QFrame( this );
+ QHBoxLayout* layout = new QHBoxLayout( frame );
+ QLineEdit* v_string = new QLineEdit( frame );
+ v_string->setObjectName( pIt->first.c_str( ) );
+ v_string->setText( pIt->second.second.c_str( ) );
+ QPushButton* v_button = new QPushButton( frame );
+ v_button->setObjectName( ( pIt->first + "_=?btn" ).c_str( ) );
+ v_button->setText( "..." );
+ v_button->connect(
+ v_button, SIGNAL( clicked( ) ),
+ this, SLOT( _dlg_OpenSingleFile( ) )
+ );
+ layout->addWidget( v_string );
+ layout->addWidget( v_button );
+ w_input = frame;
+ }
+ case Parameters::SaveFileName:
+ {
+ QFrame* frame = new QFrame( this );
+ QHBoxLayout* layout = new QHBoxLayout( frame );
+ QLineEdit* v_string = new QLineEdit( frame );
+ v_string->setObjectName( pIt->first.c_str( ) );
+ v_string->setText( pIt->second.second.c_str( ) );
+ QPushButton* v_button = new QPushButton( frame );
+ v_button->setObjectName( ( pIt->first + "_=?btn" ).c_str( ) );
+ v_button->setText( "..." );
+ v_button->connect(
+ v_button, SIGNAL( clicked( ) ),
+ this, SLOT( _dlg_SaveSingleFile( ) )
+ );
+ layout->addWidget( v_string );
+ layout->addWidget( v_button );
+ w_input = frame;
+ }
+ break;
+ case Parameters::PathName:
+ {
+ QFrame* frame = new QFrame( this );
+ QHBoxLayout* layout = new QHBoxLayout( frame );
+ QLineEdit* v_string = new QLineEdit( frame );
+ v_string->setObjectName( pIt->first.c_str( ) );
+ v_string->setText( pIt->second.second.c_str( ) );
+ QPushButton* v_button = new QPushButton( frame );
+ v_button->setObjectName( ( pIt->first + "_=?btn" ).c_str( ) );
+ v_button->setText( "..." );
+ v_button->connect(
+ v_button, SIGNAL( clicked( ) ),
+ this, SLOT( _dlg_OpenSinglePath( ) )
+ );
+ layout->addWidget( v_string );
+ layout->addWidget( v_button );
+ w_input = frame;
+ }
+ break;
+ case Parameters::StringList:
+ break;
+ case Parameters::BoolList:
+ break;
+ case Parameters::IntList:
+ {
+ QFrame* frame = new QFrame( this );
+ QHBoxLayout* layout = new QHBoxLayout( frame );
+ QLineEdit* v_string = new QLineEdit( frame );
+ v_string->setObjectName( pIt->first.c_str( ) );
+ v_string->setText( pIt->second.second.c_str( ) );
+ QPushButton* v_button = new QPushButton( frame );
+ v_button->setObjectName( ( pIt->first + "_=?btn" ).c_str( ) );
+ v_button->setText( "+" );
+ v_button->connect(
+ v_button, SIGNAL( clicked( ) ),
+ this, SLOT( _dlg_AddInt( ) )
+ );
+ layout->addWidget( v_string );
+ layout->addWidget( v_button );
+ w_input = frame;
+ }
+ break;
+ case Parameters::UintList:
+ {
+ QFrame* frame = new QFrame( this );
+ QHBoxLayout* layout = new QHBoxLayout( frame );
+ QLineEdit* v_string = new QLineEdit( frame );
+ v_string->setObjectName( pIt->first.c_str( ) );
+ v_string->setText( pIt->second.second.c_str( ) );
+ QPushButton* v_button = new QPushButton( frame );
+ v_button->setObjectName( ( pIt->first + "_=?btn" ).c_str( ) );
+ v_button->setText( "+" );
+ v_button->connect(
+ v_button, SIGNAL( clicked( ) ),
+ this, SLOT( _dlg_AddUint( ) )
+ );
+ layout->addWidget( v_string );
+ layout->addWidget( v_button );
+ w_input = frame;
+ }
+ break;
+ case Parameters::RealList:
+ {
+ QFrame* frame = new QFrame( this );
+ QHBoxLayout* layout = new QHBoxLayout( frame );
+ QLineEdit* v_string = new QLineEdit( frame );
+ v_string->setObjectName( pIt->first.c_str( ) );
+ v_string->setText( pIt->second.second.c_str( ) );
+ QPushButton* v_button = new QPushButton( frame );
+ v_button->setObjectName( ( pIt->first + "_=?btn" ).c_str( ) );
+ v_button->setText( "+" );
+ v_button->connect(
+ v_button, SIGNAL( clicked( ) ),
+ this, SLOT( _dlg_AddReal( ) )
+ );
+ layout->addWidget( v_string );
+ layout->addWidget( v_button );
+ w_input = frame;
+ }
+ break;
+ case Parameters::OpenFileNameList:
+ {
+ QFrame* frame = new QFrame( this );
+ QHBoxLayout* layout = new QHBoxLayout( frame );
+ QLineEdit* v_string = new QLineEdit( frame );
+ v_string->setObjectName( pIt->first.c_str( ) );
+ v_string->setText( pIt->second.second.c_str( ) );
+ QPushButton* v_button = new QPushButton( frame );
+ v_button->setObjectName( ( pIt->first + "_=?btn" ).c_str( ) );
+ v_button->setText( "..." );
+ v_button->connect(
+ v_button, SIGNAL( clicked( ) ),
+ this, SLOT( _dlg_OpenMultipleFiles( ) )
+ );
+ layout->addWidget( v_string );
+ layout->addWidget( v_button );
+ w_input = frame;
+ }
+ break;
+ case Parameters::SaveFileNameList:
+ break;
+ case Parameters::PathNameList:
+ break;
+ case Parameters::Choices:
{
- cpPlugins::Interface::ParametersListWidget* l_double =
- new cpPlugins::Interface::ParametersListWidget( *nIt, dlg );
- w_input = l_double;
+ QComboBox* v_choices = new QComboBox( this );
+ v_choices->setObjectName( pIt->first.c_str( ) );
- } // fi
+ std::istringstream str0( pIt->second.second );
+ std::string choices;
+ std::getline( str0, choices, '@' );
+ std::istringstream str1( choices );
+ std::string token;
+ int id = 0;
+ while( std::getline( str1, token, '#' ) )
+ v_choices->insertItem( id++, token.c_str( ) );
+ w_input = v_choices;
+ }
+ break;
+ default:
+ w_input = NULL;
+ break;
+ } // hctiws
// Ok, a representation was created
if( w_input != NULL )
{
- w_input->setObjectName( QString( nIt->c_str( ) ) );
-
- QHBoxLayout* horizontalLayout = new QHBoxLayout( );
- QLabel* label = new QLabel( dlg );
- label->setText( QString( nIt->c_str( ) ) );
- horizontalLayout->addWidget( label );
- horizontalLayout->addWidget( w_input );
- verticalLayout->addLayout( horizontalLayout );
+ QHBoxLayout* new_layout = new QHBoxLayout( );
+ QLabel* label = new QLabel( this );
+ label->setText( QString( pIt->first.c_str( ) ) );
+ new_layout->addWidget( label );
+ new_layout->addWidget( w_input );
+ this->m_ToolsLayout->addLayout( new_layout );
} // fi
} // rof
// Add buttons
- QDialogButtonBox* bb = new QDialogButtonBox(
+ this->m_Buttons = new QDialogButtonBox(
QDialogButtonBox::Ok | QDialogButtonBox::Cancel
);
- QObject::connect( bb, SIGNAL( accepted( ) ), dlg, SLOT( accept( ) ) );
- QObject::connect( bb, SIGNAL( rejected( ) ), dlg, SLOT( reject( ) ) );
- verticalLayout->addWidget( bb );
- gridLayout->addLayout( verticalLayout, 0, 0, 1, 1 );
-
- // Execute
- QMetaObject::connectSlotsByName( dlg );
- if( !( dlg->exec( ) ) )
- return( false );
+ this->connect(
+ this->m_Buttons, SIGNAL( accepted( ) ), this, SLOT( accept( ) )
+ );
+ this->connect(
+ this->m_Buttons, SIGNAL( rejected( ) ), this, SLOT( reject( ) )
+ );
+ this->m_ToolsLayout->addWidget( this->m_Buttons );
+
+ // Update values
+ this->updateView( );
+
+ return( true );
+}
- // Get values back
- nIt = names.begin( );
- for( ; nIt != names.end( ); ++nIt )
+// -------------------------------------------------------------------------
+int cpPlugins::Interface::ParametersQtDialog::
+exec( )
+{
+ int ret = this->QDialog::exec( );
+ if( ret == 1 )
+ this->updateParameters( );
+ else
+ this->updateView( );
+ return( ret );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::ParametersQtDialog::
+show( )
+{
+ this->QDialog::show( );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::ParametersQtDialog::
+updateParameters( )
+{
+ if( this->m_Parameters == NULL )
+ return;
+
+ // Put values
+ auto& raw_params = this->m_Parameters->GetRawParameters( );
+ for( auto pIt = raw_params.begin( ); pIt != raw_params.end( ); ++pIt )
{
- Parameters::Type pt = parameters.GetParameterType( *nIt );
- if( pt == Parameters::String )
+ QString pName = pIt->first.c_str( );
+ switch( pIt->second.first )
{
- QLineEdit* v_string = dlg->findChild< QLineEdit* >( nIt->c_str( ) );
+ case Parameters::String:
+ case Parameters::OpenFileName:
+ case Parameters::SaveFileName:
+ case Parameters::PathName:
+ case Parameters::IntList:
+ case Parameters::UintList:
+ case Parameters::RealList:
+ case Parameters::OpenFileNameList:
+ {
+ QLineEdit* v_string = this->findChild< QLineEdit* >( pName );
if( v_string != NULL )
- parameters.SetValueAsString( *nIt, v_string->text( ).toStdString( ) );
+ pIt->second.second = v_string->text( ).toStdString( );
}
- else if( pt == Parameters::Bool )
+ break;
+ case Parameters::Bool:
{
- QCheckBox* v_bool = dlg->findChild< QCheckBox* >( nIt->c_str( ) );
+ QCheckBox* v_bool = this->findChild< QCheckBox* >( pName );
if( v_bool != NULL )
- parameters.SetValueAsBool( *nIt, v_bool->isChecked( ) );
+ pIt->second.second = ( v_bool->isChecked( ) )? "1": "0";
}
- else if( pt == Parameters::Uint )
+ break;
+ case Parameters::Int:
+ case Parameters::Uint:
{
- QSpinBox* v_uint = dlg->findChild< QSpinBox* >( nIt->c_str( ) );
- if( v_uint != NULL )
- parameters.SetValueAsUint( *nIt, v_uint->value( ) );
+ QSpinBox* v_uint = this->findChild< QSpinBox* >( pName );
+ if( v_uint )
+ {
+ std::stringstream str;
+ str << v_uint->value( );
+ pIt->second.second = str.str( );
+
+ } // fi
}
- else if( pt == Parameters::Int )
+ break;
+ case Parameters::Real:
{
- QSpinBox* v_int = dlg->findChild< QSpinBox* >( nIt->c_str( ) );
- if( v_int != NULL )
- parameters.SetValueAsInt( *nIt, v_int->value( ) );
+ QDoubleSpinBox* v_double = this->findChild< QDoubleSpinBox* >( pName );
+ if( v_double )
+ {
+ std::stringstream str;
+ str << v_double->value( );
+ pIt->second.second = str.str( );
+
+ } // fi
}
- else if( pt == Parameters::Real )
+ break;
+ case Parameters::StringList:
+ break;
+ case Parameters::BoolList:
+ break;
+ case Parameters::SaveFileNameList:
+ break;
+ case Parameters::PathNameList:
+ break;
+ case Parameters::Choices:
{
- QDoubleSpinBox* v_double =
- dlg->findChild< QDoubleSpinBox* >( nIt->c_str( ) );
- if( v_double != NULL )
- parameters.SetValueAsReal( *nIt, v_double->value( ) );
+ QComboBox* v_choices = this->findChild< QComboBox* >( pName );
+ if( v_choices != NULL )
+ {
+ std::istringstream str_choices( pIt->second.second );
+ std::string real_choices;
+ std::getline( str_choices, real_choices, '@' );
+ pIt->second.second =
+ real_choices + "@" +
+ v_choices->currentText( ).toStdString( );
+
+ } // fi
}
- else if(
- pt == Parameters::StringList ||
- pt == Parameters::IntList ||
- pt == Parameters::UintList ||
- pt == Parameters::RealList
- )
+ break;
+ default:
+ break;
+ } // hctiws
+
+ } // rof
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::ParametersQtDialog::
+updateView( )
+{
+ if( this->m_Parameters == NULL )
+ return;
+
+ // Put values
+ auto& raw_params = this->m_Parameters->GetRawParameters( );
+ for( auto pIt = raw_params.begin( ); pIt != raw_params.end( ); ++pIt )
+ {
+ QString pName = pIt->first.c_str( );
+ switch( pIt->second.first )
+ {
+ case Parameters::String:
+ case Parameters::OpenFileName:
+ case Parameters::SaveFileName:
+ case Parameters::PathName:
+ case Parameters::IntList:
+ case Parameters::UintList:
+ case Parameters::RealList:
+ case Parameters::OpenFileNameList:
+ {
+ QLineEdit* v_string = this->findChild< QLineEdit* >( pName );
+ if( v_string != NULL )
+ v_string->setText( pIt->second.second.c_str( ) );
+ }
+ break;
+ case Parameters::Bool:
+ {
+ QCheckBox* v_bool = this->findChild< QCheckBox* >( pName );
+ if( v_bool != NULL )
+ v_bool->setChecked( pIt->second.second == "1" );
+ }
+ break;
+ case Parameters::Int:
+ case Parameters::Uint:
+ {
+ QSpinBox* v_uint = this->findChild< QSpinBox* >( pName );
+ if( v_uint )
+ {
+ std::istringstream tok_str( pIt->second.second );
+ int v;
+ tok_str >> v;
+ v_uint->setValue( v );
+
+ } // fi
+ }
+ break;
+ case Parameters::Real:
+ {
+ QDoubleSpinBox* v_double = this->findChild< QDoubleSpinBox* >( pName );
+ if( v_double )
+ {
+ std::istringstream tok_str( pIt->second.second );
+ double v;
+ tok_str >> v;
+ v_double->setValue( v );
+
+ } // fi
+ }
+ break;
+ case Parameters::StringList:
+ break;
+ case Parameters::BoolList:
+ break;
+ case Parameters::SaveFileNameList:
+ break;
+ case Parameters::PathNameList:
+ break;
+ case Parameters::Choices:
+ {
+ QComboBox* v_choices = this->findChild< QComboBox* >( pName );
+ if( v_choices != NULL )
+ {
+ std::istringstream str_choices( pIt->second.second );
+ std::string choices, real_choice;
+ std::getline( str_choices, choices, '@' );
+ std::getline( str_choices, real_choice, '@' );
+ std::istringstream str( choices );
+ std::string token;
+ int id = -1, cont = 0;
+ while( std::getline( str, token, '#' ) )
+ {
+ if( token == real_choice )
+ id = cont;
+ cont++;
+
+ } // elihw
+
+ if( id > -1 )
+ v_choices->setCurrentIndex( id );
+
+ } // fi
+ }
+ break;
+ default:
+ break;
+ } // hctiws
+
+ } // rof
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::ParametersQtDialog::
+_dlg_OpenSingleFile( )
+{
+ QPushButton* btn = dynamic_cast< QPushButton* >( this->sender( ) );
+ if( btn != NULL )
+ {
+ std::string bName = btn->objectName( ).toStdString( );
+ std::string line_name = bName.substr( 0, bName.find( "_=?btn" ) );
+ QLineEdit* line = this->findChild< QLineEdit* >( line_name.c_str( ) );
+ if( line != NULL )
+ {
+ std::string param_name = line->objectName( ).toStdString( );
+ if( param_name != "" )
+ {
+ std::string param_value =
+ this->m_Parameters->GetOpenFileName( param_name );
+ if( param_value == "" )
+ param_value = ".";
+ QStringList filters;
+ filters << "Any file (*)";
+
+ // Show dialog and check if it was accepted
+ QFileDialog dialog( this );
+ dialog.setFileMode( QFileDialog::ExistingFile );
+ dialog.setDirectory( QFileDialog::tr( param_value.c_str( ) ) );
+ dialog.setNameFilters( filters );
+ dialog.setAcceptMode( QFileDialog::AcceptOpen );
+ if( dialog.exec( ) )
+ line->setText( *( dialog.selectedFiles( ).begin( ) ) );
+
+ } // fi
+
+ } // fi
+
+ } // fi
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::ParametersQtDialog::
+_dlg_SaveSingleFile( )
+{
+ QPushButton* btn = dynamic_cast< QPushButton* >( this->sender( ) );
+ if( btn != NULL )
+ {
+ std::string bName = btn->objectName( ).toStdString( );
+ std::string line_name = bName.substr( 0, bName.find( "_=?btn" ) );
+ QLineEdit* line = this->findChild< QLineEdit* >( line_name.c_str( ) );
+ if( line != NULL )
+ {
+ std::string param_name = line->objectName( ).toStdString( );
+ if( param_name != "" )
+ {
+ std::string param_value =
+ this->m_Parameters->GetSaveFileName( param_name );
+ if( param_value == "" )
+ param_value = ".";
+ QStringList filters;
+ filters << "Any file (*)";
+
+ // Show dialog and check if it was accepted
+ QFileDialog dialog( this );
+ dialog.setFileMode( QFileDialog::AnyFile );
+ dialog.setDirectory( QFileDialog::tr( param_value.c_str( ) ) );
+ dialog.setNameFilters( filters );
+ dialog.setAcceptMode( QFileDialog::AcceptSave );
+ if( dialog.exec( ) )
+ line->setText( *( dialog.selectedFiles( ).begin( ) ) );
+
+ } // fi
+
+ } // fi
+
+ } // fi
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::ParametersQtDialog::
+_dlg_OpenSinglePath( )
+{
+ QPushButton* btn = dynamic_cast< QPushButton* >( this->sender( ) );
+ if( btn != NULL )
+ {
+ std::string bName = btn->objectName( ).toStdString( );
+ std::string line_name = bName.substr( 0, bName.find( "_=?btn" ) );
+ QLineEdit* line = this->findChild< QLineEdit* >( line_name.c_str( ) );
+ if( line != NULL )
+ {
+ std::string param_name = line->objectName( ).toStdString( );
+ if( param_name != "" )
+ {
+ std::string param_value =
+ this->m_Parameters->GetPathName( param_name );
+ if( param_value == "" )
+ param_value = ".";
+
+ // Show dialog and check if it was accepted
+ QFileDialog dialog( this );
+ dialog.setFileMode( QFileDialog::Directory );
+ dialog.setDirectory( QFileDialog::tr( param_value.c_str( ) ) );
+ dialog.setAcceptMode( QFileDialog::AcceptOpen );
+ if( dialog.exec( ) )
+ line->setText( *( dialog.selectedFiles( ).begin( ) ) );
+
+ } // fi
+
+ } // fi
+
+ } // fi
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::ParametersQtDialog::
+_dlg_OpenMultipleFiles( )
+{
+ QPushButton* btn = dynamic_cast< QPushButton* >( this->sender( ) );
+ if( btn != NULL )
+ {
+ std::string bName = btn->objectName( ).toStdString( );
+ std::string line_name = bName.substr( 0, bName.find( "_=?btn" ) );
+
+ QLineEdit* line = this->findChild< QLineEdit* >( line_name.c_str( ) );
+ if( line != NULL )
{
- cpPlugins::Interface::ParametersListWidget* l_double =
- dlg->findChild< cpPlugins::Interface::ParametersListWidget* >(
- nIt->c_str( )
- );
- if( l_double != NULL )
+ std::string param_name = line->objectName( ).toStdString( );
+ if( param_name != "" )
{
- if( pt == Parameters::StringList )
+ QStringList filters;
+ filters << "Any file (*)";
+
+ // Show dialog and check if it was accepted
+ QFileDialog dialog( this );
+ dialog.setFileMode( QFileDialog::ExistingFiles );
+ dialog.setNameFilters( filters );
+ dialog.setAcceptMode( QFileDialog::AcceptOpen );
+ if( dialog.exec( ) )
{
- std::vector< std::string > values = l_double->GetStringValues( );
- for( int r = 0; r < values.size( ); ++r )
- parameters.AddValueToStringList( *nIt, values[ r ] );
- }
- else if( pt == Parameters::IntList )
+ if( dialog.selectedFiles( ).size( ) > 0 )
+ {
+ std::stringstream str;
+ auto files = dialog.selectedFiles( );
+ auto fIt = files.begin( );
+ str << fIt->toStdString( );
+ ++fIt;
+ for( ; fIt != files.end( ); ++fIt )
+ str << "#" << fIt->toStdString( );
+ line->setText( str.str( ).c_str( ) );
+
+ } // fi
+
+ } // fi
+
+ } // fi
+
+ } // fi
+
+ } // fi
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::ParametersQtDialog::
+_dlg_AddInt( )
+{
+ QPushButton* btn = dynamic_cast< QPushButton* >( this->sender( ) );
+ if( btn != NULL )
+ {
+ std::string bName = btn->objectName( ).toStdString( );
+ std::string line_name = bName.substr( 0, bName.find( "_=?btn" ) );
+ QLineEdit* line = this->findChild< QLineEdit* >( line_name.c_str( ) );
+ if( line != NULL )
+ {
+ std::string param_name = line->objectName( ).toStdString( );
+ if( param_name != "" )
+ {
+ bool ok;
+ int value =
+ QInputDialog::getInt(
+ this,
+ (
+ std::string( "Add new value to \"" ) +
+ param_name +
+ std::string( "\"" )
+ ).c_str( ),
+ "Value:",
+ 0, -2147483647, 2147483647, 1,
+ &ok
+ );
+ if( ok )
{
- std::vector< int > values = l_double->GetIntValues( );
- for( int r = 0; r < values.size( ); ++r )
- parameters.AddValueToIntList( *nIt, values[ r ] );
- }
- else if( pt == Parameters::UintList )
+ std::string values = line->text( ).toStdString( );
+ if( values != "" )
+ values += "#";
+ std::stringstream str;
+ str << values << value;
+ line->setText( str.str( ).c_str( ) );
+
+ } // fi
+
+ } // fi
+
+ } // fi
+
+ } // fi
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::ParametersQtDialog::
+_dlg_AddUint( )
+{
+ QPushButton* btn = dynamic_cast< QPushButton* >( this->sender( ) );
+ if( btn != NULL )
+ {
+ std::string bName = btn->objectName( ).toStdString( );
+ std::string line_name = bName.substr( 0, bName.find( "_=?btn" ) );
+ QLineEdit* line = this->findChild< QLineEdit* >( line_name.c_str( ) );
+ if( line != NULL )
+ {
+ std::string param_name = line->objectName( ).toStdString( );
+ if( param_name != "" )
+ {
+ bool ok;
+ int value =
+ QInputDialog::getInt(
+ this,
+ (
+ std::string( "Add new value to \"" ) +
+ param_name +
+ std::string( "\"" )
+ ).c_str( ),
+ "Value:",
+ 0, 0, 2147483647, 1,
+ &ok
+ );
+ if( ok )
{
- std::vector< unsigned int > values = l_double->GetUintValues( );
- for( int r = 0; r < values.size( ); ++r )
- parameters.AddValueToUintList( *nIt, values[ r ] );
- }
- else if( pt == Parameters::RealList )
+ std::string values = line->text( ).toStdString( );
+ if( values != "" )
+ values += "#";
+ std::stringstream str;
+ str << values << value;
+ line->setText( str.str( ).c_str( ) );
+
+ } // fi
+
+ } // fi
+
+ } // fi
+
+ } // fi
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::ParametersQtDialog::
+_dlg_AddReal( )
+{
+ QPushButton* btn = dynamic_cast< QPushButton* >( this->sender( ) );
+ if( btn != NULL )
+ {
+ std::string bName = btn->objectName( ).toStdString( );
+ std::string line_name = bName.substr( 0, bName.find( "_=?btn" ) );
+ QLineEdit* line = this->findChild< QLineEdit* >( line_name.c_str( ) );
+ if( line != NULL )
+ {
+ std::string param_name = line->objectName( ).toStdString( );
+ if( param_name != "" )
+ {
+ bool ok;
+ double value =
+ QInputDialog::getDouble(
+ this,
+ (
+ std::string( "Add new value to \"" ) +
+ param_name +
+ std::string( "\"" )
+ ).c_str( ),
+ "Value:",
+ 0, -2147483647, 2147483647, 1,
+ &ok
+ );
+ if( ok )
{
- std::vector< double > values = l_double->GetDoubleValues( );
- for( int r = 0; r < values.size( ); ++r )
- parameters.AddValueToRealList( *nIt, values[ r ] );
+ std::string values = line->text( ).toStdString( );
+ if( values != "" )
+ values += "#";
+ std::stringstream str;
+ str << values << value;
+ line->setText( str.str( ).c_str( ) );
} // fi
} // fi
- } // rof
- return( true );
+ } // fi
}
+#endif // cpPlugins_Interface_QT4
+
// eof - $RCSfile$