1 #include <cpPlugins/Interface/ParametersQtDialog.h>
3 #ifdef cpPlugins_Interface_QT4
7 #include <cpPlugins/Interface/ParametersListWidget.h>
9 #include <vtkRenderWindowInteractor.h>
12 #include <QDialogButtonBox>
13 #include <QDoubleSpinBox>
14 #include <QHBoxLayout>
18 // -------------------------------------------------------------------------
19 cpPlugins::Interface::ParametersQtDialog::
20 ParametersQtDialog( QWidget* parent, Qt::WindowFlags f )
21 : QDialog( parent, f ),
25 this->m_Title = new QLabel( this );
26 this->m_Title->setText( "Parameters dialog title" );
28 this->m_MainLayout = new QGridLayout( this );
29 this->m_ToolsLayout = new QVBoxLayout( );
30 this->m_ToolsLayout->addWidget( this->m_Title );
31 this->m_MainLayout->addLayout( this->m_ToolsLayout, 0, 0, 1, 1 );
34 // -------------------------------------------------------------------------
35 cpPlugins::Interface::ParametersQtDialog::
36 ~ParametersQtDialog( )
39 delete this->m_ToolsLayout;
40 delete this->m_MainLayout;
43 // -------------------------------------------------------------------------
44 bool cpPlugins::Interface::ParametersQtDialog::
47 return( this->m_IsModal );
50 // -------------------------------------------------------------------------
51 cpPlugins::Interface::
52 Parameters* cpPlugins::Interface::ParametersQtDialog::
53 getParameters( ) const
55 return( this->m_Parameters );
58 // -------------------------------------------------------------------------
59 void cpPlugins::Interface::ParametersQtDialog::
60 addInteractor( vtkRenderWindowInteractor* interactor )
62 this->m_Interactors.insert( interactor );
65 // -------------------------------------------------------------------------
66 bool cpPlugins::Interface::ParametersQtDialog::
67 setParameters( Parameters* parameters )
69 this->m_IsModal = true;
70 this->m_Parameters = parameters;
71 if( this->m_Parameters == NULL )
75 std::vector< std::string > names;
76 this->m_Parameters->GetNames( names );
77 std::vector< std::string >::const_iterator nIt = names.begin( );
78 for( ; nIt != names.end( ); ++nIt )
80 Parameters::Type pt = this->m_Parameters->GetType( *nIt );
82 QWidget* w_input = NULL;
83 if( pt == Parameters::String )
85 QLineEdit* v_string = new QLineEdit( this );
86 v_string->setText( "Enter some text!!!" );
89 else if( pt == Parameters::Bool )
91 QCheckBox* v_bool = new QCheckBox( this );
92 v_bool->setText( "[ON/OFF]" );
93 v_bool->setChecked( this->m_Parameters->GetBool( *nIt ) );
96 else if( pt == Parameters::Uint )
98 QSpinBox* v_uint = new QSpinBox( this );
99 v_uint->setMinimum( 0 );
100 v_uint->setMaximum( std::numeric_limits< int >::max( ) );
101 v_uint->setValue( this->m_Parameters->GetUint( *nIt ) );
104 else if( pt == Parameters::Int )
106 QSpinBox* v_int = new QSpinBox( this );
107 v_int->setMinimum( -std::numeric_limits< int >::max( ) );
108 v_int->setMaximum( std::numeric_limits< int >::max( ) );
109 v_int->setValue( this->m_Parameters->GetInt( *nIt ) );
112 else if( pt == Parameters::Real )
114 QDoubleSpinBox* v_double = new QDoubleSpinBox( this );
115 v_double->setDecimals( 3 );
116 v_double->setMinimum( -std::numeric_limits< double >::max( ) );
117 v_double->setMaximum( std::numeric_limits< double >::max( ) );
118 v_double->setValue( this->m_Parameters->GetReal( *nIt ) );
122 pt == Parameters::StringList ||
123 pt == Parameters::IntList ||
124 pt == Parameters::UintList ||
125 pt == Parameters::RealList
128 cpPlugins::Interface::ParametersListWidget* l_double =
129 new cpPlugins::Interface::ParametersListWidget( *nIt, this );
132 else if( pt == Parameters::Point || pt == Parameters::Index )
134 auto iIt = this->m_Interactors.begin( );
135 for( ; iIt != this->m_Interactors.end( ); ++iIt )
138 dynamic_cast< TStyle* >( ( *iIt )->GetInteractorStyle( ) );
139 std::cout << "ACA VOY --> " << style << std::endl;
142 this->m_IsModal = false;
145 if( this->m_Interactor != NULL )
153 // Ok, a representation was created
154 if( w_input != NULL )
156 w_input->setObjectName( QString( nIt->c_str( ) ) );
158 QHBoxLayout* new_layout = new QHBoxLayout( );
159 QLabel* label = new QLabel( this );
160 label->setText( QString( nIt->c_str( ) ) );
161 new_layout->addWidget( label );
162 new_layout->addWidget( w_input );
163 this->m_ToolsLayout->addLayout( new_layout );
168 return( this->m_IsModal );
171 // -------------------------------------------------------------------------
172 void cpPlugins::Interface::ParametersQtDialog::
173 setTitle( const std::string& title )
175 this->m_Title->setText( title.c_str( ) );
178 // -------------------------------------------------------------------------
179 int cpPlugins::Interface::ParametersQtDialog::
182 if( !this->m_IsModal )
186 QDialogButtonBox* bb = new QDialogButtonBox(
187 QDialogButtonBox::Ok | QDialogButtonBox::Cancel
189 QObject::connect( bb, SIGNAL( accepted( ) ), this, SLOT( accept( ) ) );
190 QObject::connect( bb, SIGNAL( rejected( ) ), this, SLOT( reject( ) ) );
191 this->m_ToolsLayout->addWidget( bb );
193 int ret = this->QDialog::exec( );
195 this->syncParameters( );
199 // -------------------------------------------------------------------------
200 void cpPlugins::Interface::ParametersQtDialog::
203 if( this->m_IsModal )
206 this->QDialog::show( );
209 // -------------------------------------------------------------------------
210 void cpPlugins::Interface::ParametersQtDialog::
213 if( this->m_Parameters == NULL )
217 std::vector< std::string > names;
218 this->m_Parameters->GetNames( names );
219 std::vector< std::string >::const_iterator nIt = names.begin( );
220 for( ; nIt != names.end( ); ++nIt )
222 Parameters::Type pt = this->m_Parameters->GetType( *nIt );
224 if( pt == Parameters::String )
226 QLineEdit* v = this->findChild< QLineEdit* >( nIt->c_str( ) );
228 this->m_Parameters->SetString( *nIt, v->text( ).toStdString( ) );
230 else if( pt == Parameters::Bool )
232 QCheckBox* v = this->findChild< QCheckBox* >( nIt->c_str( ) );
234 this->m_Parameters->SetBool( *nIt, v->isChecked( ) );
236 else if( pt == Parameters::Uint )
238 QSpinBox* v = this->findChild< QSpinBox* >( nIt->c_str( ) );
240 this->m_Parameters->SetUint( *nIt, v->value( ) );
242 else if( pt == Parameters::Int )
244 QSpinBox* v = this->findChild< QSpinBox* >( nIt->c_str( ) );
246 this->m_Parameters->SetInt( *nIt, v->value( ) );
248 else if( pt == Parameters::Real )
250 QDoubleSpinBox* v = this->findChild< QDoubleSpinBox* >( nIt->c_str( ) );
252 this->m_Parameters->SetReal( *nIt, v->value( ) );
255 pt == Parameters::StringList ||
256 pt == Parameters::IntList ||
257 pt == Parameters::UintList ||
258 pt == Parameters::RealList
261 cpPlugins::Interface::ParametersListWidget* lst =
262 this->findChild< cpPlugins::Interface::ParametersListWidget* >(
267 if( pt == Parameters::StringList )
269 this->m_Parameters->ClearStringList( *nIt );
270 std::vector< std::string > values = lst->GetStringValues( );
271 for( int r = 0; r < values.size( ); ++r )
272 this->m_Parameters->AddToStringList( *nIt, values[ r ] );
274 else if( pt == Parameters::IntList )
276 this->m_Parameters->ClearIntList( *nIt );
277 std::vector< int > values = lst->GetIntValues( );
278 for( int r = 0; r < values.size( ); ++r )
279 this->m_Parameters->AddToIntList( *nIt, values[ r ] );
281 else if( pt == Parameters::UintList )
283 this->m_Parameters->ClearUintList( *nIt );
284 std::vector< unsigned int > values = lst->GetUintValues( );
285 for( int r = 0; r < values.size( ); ++r )
286 this->m_Parameters->AddToUintList( *nIt, values[ r ] );
288 else if( pt == Parameters::RealList )
290 this->m_Parameters->ClearRealList( *nIt );
291 std::vector< double > values = lst->GetDoubleValues( );
292 for( int r = 0; r < values.size( ); ++r )
293 this->m_Parameters->AddToRealList( *nIt, values[ r ] );
299 else if( pt == Parameters::Point || pt == Parameters::Index )
332 pt == Parameters::StringList ||
333 pt == Parameters::IntList ||
334 pt == Parameters::UintList ||
335 pt == Parameters::RealList
338 cpPlugins::Interface::ParametersListWidget* lst =
339 this->findChild< cpPlugins::Interface::ParametersListWidget* >(
344 if( pt == Parameters::StringList )
346 std::vector< std::string > values = lst->GetStringValues( );
347 for( int r = 0; r < values.size( ); ++r )
348 this->m_Parameters->AddToStringList( *nIt, values[ r ] );
350 else if( pt == Parameters::IntList )
352 std::vector< int > values = lst->GetIntValues( );
353 for( int r = 0; r < values.size( ); ++r )
354 this->m_Parameters->AddToIntList( *nIt, values[ r ] );
356 else if( pt == Parameters::UintList )
358 std::vector< unsigned int > values = lst->GetUintValues( );
359 for( int r = 0; r < values.size( ); ++r )
360 this->m_Parameters->AddToUintList( *nIt, values[ r ] );
362 else if( pt == Parameters::RealList )
364 std::vector< double > values = lst->GetDoubleValues( );
365 for( int r = 0; r < values.size( ); ++r )
366 this->m_Parameters->AddToRealList( *nIt, values[ r ] );
379 #endif // cpPlugins_Interface_QT4