1 #include <cpPlugins/Interface/ParametersQtDialog.h>
8 #include <QDialogButtonBox>
9 #include <QDoubleSpinBox>
10 #include <QHBoxLayout>
13 #include <QTableWidget>
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 ) );
95 else if( pt == Parameters::RealList )
98 header << nIt->c_str( );
100 QTableWidget* l_double = new QTableWidget( dlg );
101 l_double->setColumnCount( 1 );
102 l_double->setRowCount( 1 );
103 l_double->setHorizontalHeaderLabels( header );
104 l_double->setShowGrid( true );
105 l_double->setSelectionBehavior( QAbstractItemView::SelectRows );
106 l_double->setSelectionMode( QAbstractItemView::SingleSelection );
109 l_double, SIGNAL( cellDoubleClicked( int, int ) ),
110 l_double, SLOT( insertRow( int ) )
117 // Ok, a representation was created
118 if( w_input != NULL )
120 w_input->setObjectName( QString( nIt->c_str( ) ) );
122 QHBoxLayout* horizontalLayout = new QHBoxLayout( );
123 QLabel* label = new QLabel( dlg );
124 label->setText( QString( nIt->c_str( ) ) );
125 horizontalLayout->addWidget( label );
126 horizontalLayout->addWidget( w_input );
127 verticalLayout->addLayout( horizontalLayout );
134 QDialogButtonBox* bb = new QDialogButtonBox(
135 QDialogButtonBox::Ok | QDialogButtonBox::Cancel
137 QObject::connect( bb, SIGNAL( accepted( ) ), dlg, SLOT( accept( ) ) );
138 QObject::connect( bb, SIGNAL( rejected( ) ), dlg, SLOT( reject( ) ) );
139 verticalLayout->addWidget( bb );
140 gridLayout->addLayout( verticalLayout, 0, 0, 1, 1 );
143 QMetaObject::connectSlotsByName( dlg );
144 if( !( dlg->exec( ) ) )
148 nIt = names.begin( );
149 for( ; nIt != names.end( ); ++nIt )
151 Parameters::Type pt = parameters.GetParameterType( *nIt );
152 if( pt == Parameters::String )
154 QLineEdit* v_string = dlg->findChild< QLineEdit* >( nIt->c_str( ) );
155 if( v_string != NULL )
156 parameters.SetValueAsString( *nIt, v_string->text( ).toStdString( ) );
158 else if( pt == Parameters::Bool )
160 QCheckBox* v_bool = dlg->findChild< QCheckBox* >( nIt->c_str( ) );
162 parameters.SetValueAsBool( *nIt, v_bool->isChecked( ) );
164 else if( pt == Parameters::Uint )
166 QSpinBox* v_uint = dlg->findChild< QSpinBox* >( nIt->c_str( ) );
168 parameters.SetValueAsUint( *nIt, v_uint->value( ) );
170 else if( pt == Parameters::Int )
172 QSpinBox* v_int = dlg->findChild< QSpinBox* >( nIt->c_str( ) );
174 parameters.SetValueAsInt( *nIt, v_int->value( ) );
176 else if( pt == Parameters::Real )
178 QDoubleSpinBox* v_double =
179 dlg->findChild< QDoubleSpinBox* >( nIt->c_str( ) );
180 if( v_double != NULL )
181 parameters.SetValueAsReal( *nIt, v_double->value( ) );
183 else if( pt == Parameters::RealList )
185 QTableWidget* l_double =
186 dlg->findChild< QTableWidget* >( nIt->c_str( ) );
187 if( l_double != NULL )
189 for( int r = 0; r < l_double->rowCount( ); ++r )
193 l_double->item( r, 0 )->text( ).toStdString( ).c_str( )
195 parameters.AddValueToRealList( *nIt, v );