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;
38 parameters->GetNames( names );
39 std::vector< std::string >::const_iterator nIt = names.begin( );
40 for( ; nIt != names.end( ); ++nIt )
42 Parameters::Type pt = parameters->GetType( *nIt );
59 QWidget* w_input = NULL;
60 if( pt == Parameters::String )
62 QLineEdit* v_string = new QLineEdit( dlg );
63 v_string->setText( "Enter some text!!!" );
66 else if( pt == Parameters::Bool )
68 QCheckBox* v_bool = new QCheckBox( dlg );
69 v_bool->setText( "[ON/OFF]" );
70 v_bool->setChecked( parameters->GetBool( *nIt ) );
73 else if( pt == Parameters::Uint )
75 QSpinBox* v_uint = new QSpinBox( dlg );
76 v_uint->setMinimum( 0 );
77 v_uint->setMaximum( std::numeric_limits< int >::max( ) );
78 v_uint->setValue( parameters->GetUint( *nIt ) );
81 else if( pt == Parameters::Int )
83 QSpinBox* v_int = new QSpinBox( dlg );
84 v_int->setMinimum( -std::numeric_limits< int >::max( ) );
85 v_int->setMaximum( std::numeric_limits< int >::max( ) );
86 v_int->setValue( parameters->GetInt( *nIt ) );
89 else if( pt == Parameters::Real )
91 QDoubleSpinBox* v_double = new QDoubleSpinBox( dlg );
92 v_double->setDecimals( 3 );
93 v_double->setMinimum( -std::numeric_limits< double >::max( ) );
94 v_double->setMaximum( std::numeric_limits< double >::max( ) );
95 v_double->setValue( parameters->GetReal( *nIt ) );
99 pt == Parameters::StringList ||
100 pt == Parameters::IntList ||
101 pt == Parameters::UintList ||
102 pt == Parameters::RealList
105 cpPlugins::Interface::ParametersListWidget* l_double =
106 new cpPlugins::Interface::ParametersListWidget( *nIt, dlg );
111 // Ok, a representation was created
112 if( w_input != NULL )
114 w_input->setObjectName( QString( nIt->c_str( ) ) );
116 QHBoxLayout* horizontalLayout = new QHBoxLayout( );
117 QLabel* label = new QLabel( dlg );
118 label->setText( QString( nIt->c_str( ) ) );
119 horizontalLayout->addWidget( label );
120 horizontalLayout->addWidget( w_input );
121 verticalLayout->addLayout( horizontalLayout );
128 QDialogButtonBox* bb = new QDialogButtonBox(
129 QDialogButtonBox::Ok | QDialogButtonBox::Cancel
131 QObject::connect( bb, SIGNAL( accepted( ) ), dlg, SLOT( accept( ) ) );
132 QObject::connect( bb, SIGNAL( rejected( ) ), dlg, SLOT( reject( ) ) );
133 verticalLayout->addWidget( bb );
134 gridLayout->addLayout( verticalLayout, 0, 0, 1, 1 );
137 QMetaObject::connectSlotsByName( dlg );
138 if( !( dlg->exec( ) ) )
142 nIt = names.begin( );
143 for( ; nIt != names.end( ); ++nIt )
145 Parameters::Type pt = parameters->GetType( *nIt );
146 if( pt == Parameters::String )
148 QLineEdit* v_string = dlg->findChild< QLineEdit* >( nIt->c_str( ) );
149 if( v_string != NULL )
150 parameters->SetString( *nIt, v_string->text( ).toStdString( ) );
152 else if( pt == Parameters::Bool )
154 QCheckBox* v_bool = dlg->findChild< QCheckBox* >( nIt->c_str( ) );
156 parameters->SetBool( *nIt, v_bool->isChecked( ) );
158 else if( pt == Parameters::Uint )
160 QSpinBox* v_uint = dlg->findChild< QSpinBox* >( nIt->c_str( ) );
162 parameters->SetUint( *nIt, v_uint->value( ) );
164 else if( pt == Parameters::Int )
166 QSpinBox* v_int = dlg->findChild< QSpinBox* >( nIt->c_str( ) );
168 parameters->SetInt( *nIt, v_int->value( ) );
170 else if( pt == Parameters::Real )
172 QDoubleSpinBox* v_double =
173 dlg->findChild< QDoubleSpinBox* >( nIt->c_str( ) );
174 if( v_double != NULL )
175 parameters->SetReal( *nIt, v_double->value( ) );
178 pt == Parameters::StringList ||
179 pt == Parameters::IntList ||
180 pt == Parameters::UintList ||
181 pt == Parameters::RealList
184 cpPlugins::Interface::ParametersListWidget* l_double =
185 dlg->findChild< cpPlugins::Interface::ParametersListWidget* >(
188 if( l_double != NULL )
190 if( pt == Parameters::StringList )
192 std::vector< std::string > values = l_double->GetStringValues( );
193 for( int r = 0; r < values.size( ); ++r )
194 parameters->AddToStringList( *nIt, values[ r ] );
196 else if( pt == Parameters::IntList )
198 std::vector< int > values = l_double->GetIntValues( );
199 for( int r = 0; r < values.size( ); ++r )
200 parameters->AddToIntList( *nIt, values[ r ] );
202 else if( pt == Parameters::UintList )
204 std::vector< unsigned int > values = l_double->GetUintValues( );
205 for( int r = 0; r < values.size( ); ++r )
206 parameters->AddToUintList( *nIt, values[ r ] );
208 else if( pt == Parameters::RealList )
210 std::vector< double > values = l_double->GetDoubleValues( );
211 for( int r = 0; r < values.size( ); ++r )
212 parameters->AddToRealList( *nIt, values[ r ] );
224 #endif // cpPlugins_Interface_QT4