1 #include <cpPlugins/Interface/ParametersQtDialog.h>
3 #ifdef cpPlugins_Interface_QT4
8 #include <cpPlugins/Interface/ParametersListWidget.h>
11 #include <QDialogButtonBox>
12 #include <QDoubleSpinBox>
13 #include <QHBoxLayout>
18 // -------------------------------------------------------------------------
19 bool cpPlugins::Interface::
21 Parameters& parameters, const std::string& title, QWidget* parent
24 // Create dialog with a simple layout
25 QDialog* dlg = new QDialog( parent );
26 dlg->setWindowFlags( Qt::FramelessWindowHint );
27 dlg->setWindowFlags( Qt::WindowTitleHint );
28 QGridLayout* gridLayout = new QGridLayout( dlg );
29 QVBoxLayout* verticalLayout = new QVBoxLayout( );
32 QLabel* dlg_title = new QLabel( dlg );
33 dlg_title->setText( title.c_str( ) );
34 verticalLayout->addWidget( dlg_title );
37 std::vector< std::string > names = parameters.GetParameters( );
38 std::vector< std::string >::const_iterator nIt = names.begin( );
39 for( ; nIt != names.end( ); ++nIt )
41 Parameters::Type pt = parameters.GetParameterType( *nIt );
58 QWidget* w_input = NULL;
59 if( pt == Parameters::String )
61 QLineEdit* v_string = new QLineEdit( dlg );
62 v_string->setText( "Enter some text!!!" );
65 else if( pt == Parameters::Bool )
67 QCheckBox* v_bool = new QCheckBox( dlg );
68 v_bool->setText( "[ON/OFF]" );
69 v_bool->setChecked( parameters.GetValueAsBool( *nIt ) );
72 else if( pt == Parameters::Uint )
74 QSpinBox* v_uint = new QSpinBox( dlg );
75 v_uint->setMinimum( 0 );
76 v_uint->setMaximum( std::numeric_limits< int >::max( ) );
77 v_uint->setValue( parameters.GetValueAsUint( *nIt ) );
80 else if( pt == Parameters::Int )
82 QSpinBox* v_int = new QSpinBox( dlg );
83 v_int->setMinimum( -std::numeric_limits< int >::max( ) );
84 v_int->setMaximum( std::numeric_limits< int >::max( ) );
85 v_int->setValue( parameters.GetValueAsInt( *nIt ) );
88 else if( pt == Parameters::Real )
90 QDoubleSpinBox* v_double = new QDoubleSpinBox( dlg );
91 v_double->setDecimals( 3 );
92 v_double->setMinimum( -std::numeric_limits< double >::max( ) );
93 v_double->setMaximum( std::numeric_limits< double >::max( ) );
94 v_double->setValue( parameters.GetValueAsReal( *nIt ) );
98 pt == Parameters::StringList ||
99 pt == Parameters::IntList ||
100 pt == Parameters::UintList ||
101 pt == Parameters::RealList
104 cpPlugins::Interface::ParametersListWidget* l_double =
105 new cpPlugins::Interface::ParametersListWidget( *nIt, dlg );
110 // Ok, a representation was created
111 if( w_input != NULL )
113 w_input->setObjectName( QString( nIt->c_str( ) ) );
115 QHBoxLayout* horizontalLayout = new QHBoxLayout( );
116 QLabel* label = new QLabel( dlg );
117 label->setText( QString( nIt->c_str( ) ) );
118 horizontalLayout->addWidget( label );
119 horizontalLayout->addWidget( w_input );
120 verticalLayout->addLayout( horizontalLayout );
127 QDialogButtonBox* bb = new QDialogButtonBox(
128 QDialogButtonBox::Ok | QDialogButtonBox::Cancel
130 QObject::connect( bb, SIGNAL( accepted( ) ), dlg, SLOT( accept( ) ) );
131 QObject::connect( bb, SIGNAL( rejected( ) ), dlg, SLOT( reject( ) ) );
132 verticalLayout->addWidget( bb );
133 gridLayout->addLayout( verticalLayout, 0, 0, 1, 1 );
136 QMetaObject::connectSlotsByName( dlg );
137 if( !( dlg->exec( ) ) )
141 nIt = names.begin( );
142 for( ; nIt != names.end( ); ++nIt )
144 Parameters::Type pt = parameters.GetParameterType( *nIt );
145 if( pt == Parameters::String )
147 QLineEdit* v_string = dlg->findChild< QLineEdit* >( nIt->c_str( ) );
148 if( v_string != NULL )
149 parameters.SetValueAsString( *nIt, v_string->text( ).toStdString( ) );
151 else if( pt == Parameters::Bool )
153 QCheckBox* v_bool = dlg->findChild< QCheckBox* >( nIt->c_str( ) );
155 parameters.SetValueAsBool( *nIt, v_bool->isChecked( ) );
157 else if( pt == Parameters::Uint )
159 QSpinBox* v_uint = dlg->findChild< QSpinBox* >( nIt->c_str( ) );
161 parameters.SetValueAsUint( *nIt, v_uint->value( ) );
163 else if( pt == Parameters::Int )
165 QSpinBox* v_int = dlg->findChild< QSpinBox* >( nIt->c_str( ) );
167 parameters.SetValueAsInt( *nIt, v_int->value( ) );
169 else if( pt == Parameters::Real )
171 QDoubleSpinBox* v_double =
172 dlg->findChild< QDoubleSpinBox* >( nIt->c_str( ) );
173 if( v_double != NULL )
174 parameters.SetValueAsReal( *nIt, v_double->value( ) );
177 pt == Parameters::StringList ||
178 pt == Parameters::IntList ||
179 pt == Parameters::UintList ||
180 pt == Parameters::RealList
183 cpPlugins::Interface::ParametersListWidget* l_double =
184 dlg->findChild< cpPlugins::Interface::ParametersListWidget* >(
187 if( l_double != NULL )
189 if( pt == Parameters::StringList )
191 std::vector< std::string > values = l_double->GetStringValues( );
192 for( int r = 0; r < values.size( ); ++r )
193 parameters.AddValueToStringList( *nIt, values[ r ] );
195 else if( pt == Parameters::IntList )
197 std::vector< int > values = l_double->GetIntValues( );
198 for( int r = 0; r < values.size( ); ++r )
199 parameters.AddValueToIntList( *nIt, values[ r ] );
201 else if( pt == Parameters::UintList )
203 std::vector< unsigned int > values = l_double->GetUintValues( );
204 for( int r = 0; r < values.size( ); ++r )
205 parameters.AddValueToUintList( *nIt, values[ r ] );
207 else if( pt == Parameters::RealList )
209 std::vector< double > values = l_double->GetDoubleValues( );
210 for( int r = 0; r < values.size( ); ++r )
211 parameters.AddValueToRealList( *nIt, values[ r ] );
223 #endif // cpPlugins_Interface_QT4