1 #include <cpPlugins/Interface/ParametersQtDialog.h>
6 #include <cpPlugins/Interface/ParametersListWidget.h>
9 #include <QDialogButtonBox>
10 #include <QDoubleSpinBox>
11 #include <QHBoxLayout>
16 // -------------------------------------------------------------------------
17 bool cpPlugins::Interface::
19 Parameters& parameters, const std::string& title, QWidget* parent
22 // Create dialog with a simple layout
23 QDialog* dlg = new QDialog( parent );
24 dlg->setWindowFlags( Qt::FramelessWindowHint );
25 dlg->setWindowFlags( Qt::WindowTitleHint );
26 QGridLayout* gridLayout = new QGridLayout( dlg );
27 QVBoxLayout* verticalLayout = new QVBoxLayout( );
30 QLabel* dlg_title = new QLabel( dlg );
31 dlg_title->setText( title.c_str( ) );
32 verticalLayout->addWidget( dlg_title );
35 std::vector< std::string > names = parameters.GetParameters( );
36 std::vector< std::string >::const_iterator nIt = names.begin( );
37 for( ; nIt != names.end( ); ++nIt )
39 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 ) );
96 pt == Parameters::StringList ||
97 pt == Parameters::IntList ||
98 pt == Parameters::UintList ||
99 pt == Parameters::RealList
102 cpPlugins::Interface::ParametersListWidget* l_double =
103 new cpPlugins::Interface::ParametersListWidget( *nIt, dlg );
108 // Ok, a representation was created
109 if( w_input != NULL )
111 w_input->setObjectName( QString( nIt->c_str( ) ) );
113 QHBoxLayout* horizontalLayout = new QHBoxLayout( );
114 QLabel* label = new QLabel( dlg );
115 label->setText( QString( nIt->c_str( ) ) );
116 horizontalLayout->addWidget( label );
117 horizontalLayout->addWidget( w_input );
118 verticalLayout->addLayout( horizontalLayout );
125 QDialogButtonBox* bb = new QDialogButtonBox(
126 QDialogButtonBox::Ok | QDialogButtonBox::Cancel
128 QObject::connect( bb, SIGNAL( accepted( ) ), dlg, SLOT( accept( ) ) );
129 QObject::connect( bb, SIGNAL( rejected( ) ), dlg, SLOT( reject( ) ) );
130 verticalLayout->addWidget( bb );
131 gridLayout->addLayout( verticalLayout, 0, 0, 1, 1 );
134 QMetaObject::connectSlotsByName( dlg );
135 if( !( dlg->exec( ) ) )
139 nIt = names.begin( );
140 for( ; nIt != names.end( ); ++nIt )
142 Parameters::Type pt = parameters.GetParameterType( *nIt );
143 if( pt == Parameters::String )
145 QLineEdit* v_string = dlg->findChild< QLineEdit* >( nIt->c_str( ) );
146 if( v_string != NULL )
147 parameters.SetValueAsString( *nIt, v_string->text( ).toStdString( ) );
149 else if( pt == Parameters::Bool )
151 QCheckBox* v_bool = dlg->findChild< QCheckBox* >( nIt->c_str( ) );
153 parameters.SetValueAsBool( *nIt, v_bool->isChecked( ) );
155 else if( pt == Parameters::Uint )
157 QSpinBox* v_uint = dlg->findChild< QSpinBox* >( nIt->c_str( ) );
159 parameters.SetValueAsUint( *nIt, v_uint->value( ) );
161 else if( pt == Parameters::Int )
163 QSpinBox* v_int = dlg->findChild< QSpinBox* >( nIt->c_str( ) );
165 parameters.SetValueAsInt( *nIt, v_int->value( ) );
167 else if( pt == Parameters::Real )
169 QDoubleSpinBox* v_double =
170 dlg->findChild< QDoubleSpinBox* >( nIt->c_str( ) );
171 if( v_double != NULL )
172 parameters.SetValueAsReal( *nIt, v_double->value( ) );
175 pt == Parameters::StringList ||
176 pt == Parameters::IntList ||
177 pt == Parameters::UintList ||
178 pt == Parameters::RealList
181 cpPlugins::Interface::ParametersListWidget* l_double =
182 dlg->findChild< cpPlugins::Interface::ParametersListWidget* >(
185 if( l_double != NULL )
187 if( pt == Parameters::StringList )
189 std::vector< std::string > values = l_double->GetStringValues( );
190 for( int r = 0; r < values.size( ); ++r )
191 parameters.AddValueToStringList( *nIt, values[ r ] );
193 else if( pt == Parameters::IntList )
195 std::vector< int > values = l_double->GetIntValues( );
196 for( int r = 0; r < values.size( ); ++r )
197 parameters.AddValueToIntList( *nIt, values[ r ] );
199 else if( pt == Parameters::UintList )
201 std::vector< unsigned int > values = l_double->GetUintValues( );
202 for( int r = 0; r < values.size( ); ++r )
203 parameters.AddValueToUintList( *nIt, values[ r ] );
205 else if( pt == Parameters::RealList )
207 std::vector< double > values = l_double->GetDoubleValues( );
208 for( int r = 0; r < values.size( ); ++r )
209 parameters.AddValueToRealList( *nIt, values[ r ] );