#include #ifdef cpPlugins_Interface_QT4 #include #include #include #include #include #include #include #include #include #include #include // ------------------------------------------------------------------------- bool cpPlugins::Interface:: ParametersQtDialog( Parameters& parameters, const std::string& title, QWidget* parent ) { // 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( ); // Put a title QLabel* dlg_title = new QLabel( dlg ); dlg_title->setText( title.c_str( ) ); verticalLayout->addWidget( dlg_title ); // Put values std::vector< std::string > names = parameters.GetParameters( ); std::vector< std::string >::const_iterator nIt = names.begin( ); for( ; nIt != names.end( ); ++nIt ) { 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 ) { QLineEdit* v_string = new QLineEdit( dlg ); v_string->setText( "Enter some text!!!" ); w_input = v_string; } else if( pt == Parameters::Bool ) { QCheckBox* v_bool = new QCheckBox( dlg ); v_bool->setText( "[ON/OFF]" ); v_bool->setChecked( parameters.GetValueAsBool( *nIt ) ); w_input = v_bool; } else if( pt == Parameters::Uint ) { QSpinBox* v_uint = new QSpinBox( dlg ); v_uint->setMinimum( 0 ); v_uint->setMaximum( std::numeric_limits< int >::max( ) ); v_uint->setValue( parameters.GetValueAsUint( *nIt ) ); w_input = v_uint; } else if( pt == Parameters::Int ) { 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 ); 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 ) ); w_input = v_double; } else if( pt == Parameters::StringList || pt == Parameters::IntList || pt == Parameters::UintList || pt == Parameters::RealList ) { cpPlugins::Interface::ParametersListWidget* l_double = new cpPlugins::Interface::ParametersListWidget( *nIt, dlg ); w_input = l_double; } // fi // 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 ); } // fi } // rof // Add buttons QDialogButtonBox* bb = 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 ); // Get values back nIt = names.begin( ); for( ; nIt != names.end( ); ++nIt ) { Parameters::Type pt = parameters.GetParameterType( *nIt ); if( pt == Parameters::String ) { QLineEdit* v_string = dlg->findChild< QLineEdit* >( nIt->c_str( ) ); if( v_string != NULL ) parameters.SetValueAsString( *nIt, v_string->text( ).toStdString( ) ); } else if( pt == Parameters::Bool ) { QCheckBox* v_bool = dlg->findChild< QCheckBox* >( nIt->c_str( ) ); if( v_bool != NULL ) parameters.SetValueAsBool( *nIt, v_bool->isChecked( ) ); } else if( pt == Parameters::Uint ) { QSpinBox* v_uint = dlg->findChild< QSpinBox* >( nIt->c_str( ) ); if( v_uint != NULL ) parameters.SetValueAsUint( *nIt, v_uint->value( ) ); } else if( pt == Parameters::Int ) { QSpinBox* v_int = dlg->findChild< QSpinBox* >( nIt->c_str( ) ); if( v_int != NULL ) parameters.SetValueAsInt( *nIt, v_int->value( ) ); } else if( pt == Parameters::Real ) { QDoubleSpinBox* v_double = dlg->findChild< QDoubleSpinBox* >( nIt->c_str( ) ); if( v_double != NULL ) parameters.SetValueAsReal( *nIt, v_double->value( ) ); } else if( pt == Parameters::StringList || pt == Parameters::IntList || pt == Parameters::UintList || pt == Parameters::RealList ) { cpPlugins::Interface::ParametersListWidget* l_double = dlg->findChild< cpPlugins::Interface::ParametersListWidget* >( nIt->c_str( ) ); if( l_double != NULL ) { if( pt == Parameters::StringList ) { 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 ) { 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::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::vector< double > values = l_double->GetDoubleValues( ); for( int r = 0; r < values.size( ); ++r ) parameters.AddValueToRealList( *nIt, values[ r ] ); } // fi } // fi } // fi } // rof return( true ); } #endif // cpPlugins_Interface_QT4 // eof - $RCSfile$