1 #include <cpPlugins/Interface/ParametersQtDialog.h>
8 #include <QDialogButtonBox>
9 #include <QDoubleSpinBox>
10 #include <QHBoxLayout>
15 // -------------------------------------------------------------------------
16 bool cpPlugins::Interface::
18 Parameters& parameters, const std::string& title, QWidget* parent
21 // Create dialog with a simple layout
22 QDialog* dlg = new QDialog( parent );
23 dlg->setWindowFlags( Qt::FramelessWindowHint );
24 dlg->setWindowFlags( Qt::WindowTitleHint );
25 QGridLayout* gridLayout = new QGridLayout( dlg );
26 QVBoxLayout* verticalLayout = new QVBoxLayout( );
29 QLabel* dlg_title = new QLabel( dlg );
30 dlg_title->setText( title.c_str( ) );
31 verticalLayout->addWidget( dlg_title );
34 std::vector< std::string > names = parameters.GetParameters( );
35 std::vector< std::string >::const_iterator nIt = names.begin( );
36 for( ; nIt != names.end( ); ++nIt )
38 Parameters::Type pt = parameters.GetParameterType( *nIt );
56 QWidget* w_input = NULL;
57 if( pt == Parameters::String )
59 QLineEdit* v_string = new QLineEdit( dlg );
60 v_string->setText( "Enter some text!!!" );
63 else if( pt == Parameters::Bool )
65 QCheckBox* v_bool = new QCheckBox( dlg );
66 v_bool->setText( "[ON/OFF]" );
67 v_bool->setChecked( parameters.GetValueAsBool( *nIt ) );
70 else if( pt == Parameters::Uint )
72 QSpinBox* v_uint = new QSpinBox( dlg );
73 v_uint->setMinimum( 0 );
74 v_uint->setMaximum( std::numeric_limits< int >::max( ) );
75 v_uint->setValue( parameters.GetValueAsUint( *nIt ) );
78 else if( pt == Parameters::Int )
80 QSpinBox* v_int = new QSpinBox( dlg );
81 v_int->setMinimum( -std::numeric_limits< int >::max( ) );
82 v_int->setMaximum( std::numeric_limits< int >::max( ) );
83 v_int->setValue( parameters.GetValueAsInt( *nIt ) );
86 else if( pt == Parameters::Real )
88 QDoubleSpinBox* v_double = new QDoubleSpinBox( dlg );
89 v_double->setDecimals( 3 );
90 v_double->setMinimum( -std::numeric_limits< double >::max( ) );
91 v_double->setMaximum( std::numeric_limits< double >::max( ) );
92 v_double->setValue( parameters.GetValueAsReal( *nIt ) );
97 // Ok, a representation was created
100 w_input->setObjectName( QString( nIt->c_str( ) ) );
102 QHBoxLayout* horizontalLayout = new QHBoxLayout( );
103 QLabel* label = new QLabel( dlg );
104 label->setText( QString( nIt->c_str( ) ) );
105 horizontalLayout->addWidget( label );
106 horizontalLayout->addWidget( w_input );
107 verticalLayout->addLayout( horizontalLayout );
114 QDialogButtonBox* bb = new QDialogButtonBox(
115 QDialogButtonBox::Ok | QDialogButtonBox::Cancel
117 QObject::connect( bb, SIGNAL( accepted( ) ), dlg, SLOT( accept( ) ) );
118 QObject::connect( bb, SIGNAL( rejected( ) ), dlg, SLOT( reject( ) ) );
119 verticalLayout->addWidget( bb );
120 gridLayout->addLayout( verticalLayout, 0, 0, 1, 1 );
123 QMetaObject::connectSlotsByName( dlg );
124 if( !( dlg->exec( ) ) )
128 nIt = names.begin( );
129 for( ; nIt != names.end( ); ++nIt )
131 Parameters::Type pt = parameters.GetParameterType( *nIt );
132 if( pt == Parameters::String )
134 QLineEdit* v_string = dlg->findChild< QLineEdit* >( nIt->c_str( ) );
135 if( v_string != NULL )
136 parameters.SetValueAsString( *nIt, v_string->text( ).toStdString( ) );
138 else if( pt == Parameters::Bool )
140 QCheckBox* v_bool = dlg->findChild< QCheckBox* >( nIt->c_str( ) );
142 parameters.SetValueAsBool( *nIt, v_bool->isChecked( ) );
144 else if( pt == Parameters::Uint )
146 QSpinBox* v_uint = dlg->findChild< QSpinBox* >( nIt->c_str( ) );
148 parameters.SetValueAsUint( *nIt, v_uint->value( ) );
150 else if( pt == Parameters::Int )
152 QSpinBox* v_int = dlg->findChild< QSpinBox* >( nIt->c_str( ) );
154 parameters.SetValueAsInt( *nIt, v_int->value( ) );
156 else if( pt == Parameters::Real )
158 QDoubleSpinBox* v_double =
159 dlg->findChild< QDoubleSpinBox* >( nIt->c_str( ) );
160 if( v_double != NULL )
161 parameters.SetValueAsReal( *nIt, v_double->value( ) );