]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/ParametersQtDialog.cxx
9650765676feeaf2e2b8dd9f234d9921dfe565c3
[cpPlugins.git] / lib / cpPlugins / ParametersQtDialog.cxx
1 #include <cpPlugins/ParametersQtDialog.h>
2
3 #ifdef cpPlugins_QT4
4
5 #include <limits>
6
7 #include <cpPlugins/ProcessObject.h>
8
9 #include <QCheckBox>
10 #include <QComboBox>
11 #include <QDoubleSpinBox>
12 #include <QFileDialog>
13 #include <QHBoxLayout>
14 #include <QInputDialog>
15 #include <QLineEdit>
16 #include <QPushButton>
17 #include <QWidget>
18
19 // -------------------------------------------------------------------------
20 cpPlugins::ParametersQtDialog::
21 ParametersQtDialog( QWidget* parent, Qt::WindowFlags f, bool manual )
22   : QDialog( parent, f ),
23     m_ProcessObject( NULL ),
24     m_WidgetsUpdated( false ),
25     m_Manual( manual )
26 {
27   if( !this->m_Manual )
28   {
29     this->m_Title = new QLabel( this );
30     this->m_Title->setText( "Parameters dialog title" );
31     this->m_MainLayout = new QGridLayout( this );
32     this->m_ToolsLayout = new QVBoxLayout( );
33     this->m_ToolsLayout->addWidget( this->m_Title );
34     this->m_MainLayout->addLayout( this->m_ToolsLayout, 0, 0, 1, 1 );
35
36   } // fi
37 }
38
39 // -------------------------------------------------------------------------
40 cpPlugins::ParametersQtDialog::
41 ~ParametersQtDialog( )
42 {
43   if( !this->m_Manual )
44   {
45     delete this->m_Title;
46     delete this->m_ToolsLayout;
47     delete this->m_MainLayout;
48
49   } // fi
50 }
51
52 // -------------------------------------------------------------------------
53 cpPlugins::
54 ProcessObject* cpPlugins::ParametersQtDialog::
55 getProcessObject( ) const
56 {
57   return( this->m_ProcessObject );
58 }
59
60 // -------------------------------------------------------------------------
61 bool cpPlugins::ParametersQtDialog::
62 setProcessObject( ProcessObject* obj )
63 {
64   if( this->m_ProcessObject != NULL || obj == NULL )
65     return( false );
66   this->m_ProcessObject = obj;
67   this->m_WidgetsUpdated = false;
68   return( true );
69 }
70
71 // -------------------------------------------------------------------------
72 int cpPlugins::ParametersQtDialog::
73 exec( )
74 {
75   this->_updateWidgets( );
76   this->updateView( );
77
78   int ret = this->QDialog::exec( );
79   if( ret == 1 )
80     this->updateParameters( );
81   else
82     this->updateView( );
83   return( ret );
84 }
85
86 // -------------------------------------------------------------------------
87 void cpPlugins::ParametersQtDialog::
88 updateParameters( )
89 {
90   if( this->m_ProcessObject == NULL )
91     return;
92   if( this->m_Manual )
93     return;
94
95   // Check if an explicit re-execution button is needed
96   if( this->m_ProcessObject->GetCouldHaveExplicitReExecution( ) )
97   {
98     QCheckBox* v_bool =
99       this->findChild< QCheckBox* >( "___ExplicitReExecution___" );
100     if( v_bool != NULL )
101       this->m_ProcessObject->SetExplicitReExecution( v_bool->isChecked( ) );
102
103   } // fi
104
105   // Put values
106   auto parameters = this->m_ProcessObject->GetParameters( );
107   auto& raw_params = parameters->GetRawParameters( );
108   for( auto pIt = raw_params.begin( ); pIt != raw_params.end( ); ++pIt )
109   {
110     QString pName = pIt->first.c_str( );
111     switch( pIt->second.first )
112     {
113     case Parameters::String:
114     case Parameters::OpenFileName:
115     case Parameters::SaveFileName:
116     case Parameters::PathName:
117     case Parameters::IntList:
118     case Parameters::UintList:
119     case Parameters::RealList:
120     case Parameters::OpenFileNameList:
121     {
122       QLineEdit* v_string = this->findChild< QLineEdit* >( pName );
123       if( v_string != NULL )
124         pIt->second.second = v_string->text( ).toStdString( );
125     }
126     break;
127     case Parameters::Bool:
128     {
129       QCheckBox* v_bool = this->findChild< QCheckBox* >( pName );
130       if( v_bool != NULL )
131         pIt->second.second = ( v_bool->isChecked( ) )? "1": "0";
132     }
133     break;
134     case Parameters::Int:
135     case Parameters::Uint:
136     {
137       QSpinBox* v_uint = this->findChild< QSpinBox* >( pName );
138       if( v_uint )
139       {
140         std::stringstream str;
141         str << v_uint->value( );
142         pIt->second.second = str.str( );
143
144       } // fi
145     }
146     break;
147     case Parameters::Real:
148     {
149       QDoubleSpinBox* v_double = this->findChild< QDoubleSpinBox* >( pName );
150       if( v_double )
151       {
152         std::stringstream str;
153         str << v_double->value( );
154         pIt->second.second = str.str( );
155
156       } // fi
157     }
158     break;
159     case Parameters::StringList:
160       break;
161     case Parameters::BoolList:
162       break;
163     case Parameters::SaveFileNameList:
164       break;
165     case Parameters::PathNameList:
166       break;
167     case Parameters::Choices:
168     {
169       QComboBox* v_choices = this->findChild< QComboBox* >( pName );
170       if( v_choices != NULL )
171       {
172         std::istringstream str_choices( pIt->second.second );
173         std::string real_choices;
174         std::getline( str_choices, real_choices, '@' );
175         pIt->second.second =
176           real_choices + "@" +
177           v_choices->currentText( ).toStdString( );
178
179       } // fi
180     }
181     break;
182     default:
183       break;
184     } // hctiws
185
186   } // rof
187   this->m_ProcessObject->Modified( );
188 }
189
190 // -------------------------------------------------------------------------
191 void cpPlugins::ParametersQtDialog::
192 updateView( )
193 {
194   if( this->m_ProcessObject == NULL )
195     return;
196   if( this->m_Manual )
197     return;
198
199   // Check if an explicit re-execution button is needed
200   if( this->m_ProcessObject->GetCouldHaveExplicitReExecution( ) )
201   {
202     QCheckBox* v_bool =
203       this->findChild< QCheckBox* >( "___ExplicitReExecution___" );
204     if( v_bool != NULL )
205       v_bool->setChecked( this->m_ProcessObject->GetExplicitReExecution( ) );
206
207   } // fi
208
209   // Put values
210   auto parameters = this->m_ProcessObject->GetParameters( );
211   auto& raw_params = parameters->GetRawParameters( );
212   for( auto pIt = raw_params.begin( ); pIt != raw_params.end( ); ++pIt )
213   {
214     QString pName = pIt->first.c_str( );
215     switch( pIt->second.first )
216     {
217     case Parameters::String:
218     case Parameters::OpenFileName:
219     case Parameters::SaveFileName:
220     case Parameters::PathName:
221     case Parameters::IntList:
222     case Parameters::UintList:
223     case Parameters::RealList:
224     case Parameters::OpenFileNameList:
225     {
226       QLineEdit* v_string = this->findChild< QLineEdit* >( pName );
227       if( v_string != NULL )
228         v_string->setText( pIt->second.second.c_str( ) );
229     }
230     break;
231     case Parameters::Bool:
232     {
233       QCheckBox* v_bool = this->findChild< QCheckBox* >( pName );
234       if( v_bool != NULL )
235         v_bool->setChecked( pIt->second.second == "1" );
236     }
237     break;
238     case Parameters::Int:
239     case Parameters::Uint:
240     {
241       QSpinBox* v_uint = this->findChild< QSpinBox* >( pName );
242       if( v_uint )
243       {
244         std::istringstream tok_str( pIt->second.second );
245         int v;
246         tok_str >> v;
247         v_uint->setValue( v );
248
249       } // fi
250     }
251     break;
252     case Parameters::Real:
253     {
254       QDoubleSpinBox* v_double = this->findChild< QDoubleSpinBox* >( pName );
255       if( v_double )
256       {
257         std::istringstream tok_str( pIt->second.second );
258         double v;
259         tok_str >> v;
260         v_double->setValue( v );
261
262       } // fi
263     }
264     break;
265     case Parameters::StringList:
266       break;
267     case Parameters::BoolList:
268       break;
269     case Parameters::SaveFileNameList:
270       break;
271     case Parameters::PathNameList:
272       break;
273     case Parameters::Choices:
274     {
275       QComboBox* v_choices = this->findChild< QComboBox* >( pName );
276       if( v_choices != NULL )
277       {
278         std::istringstream str_choices( pIt->second.second );
279         std::string choices, real_choice;
280         std::getline( str_choices, choices, '@' );
281         std::getline( str_choices, real_choice, '@' );
282         std::istringstream str( choices );
283         std::string token;
284         int id = -1, cont = 0;
285         while( std::getline( str, token, '#' ) )
286         {
287           if( token == real_choice )
288             id = cont;
289           cont++;
290
291         } // elihw
292
293         if( id > -1 )
294           v_choices->setCurrentIndex( id );
295
296       } // fi
297     }
298     break;
299     default:
300       break;
301     } // hctiws
302
303   } // rof
304 }
305
306 // -------------------------------------------------------------------------
307 void cpPlugins::ParametersQtDialog::
308 _addButtons( )
309 {
310   if( this->m_Manual )
311     return;
312
313   // Add buttons
314   this->m_Buttons = new QDialogButtonBox(
315     QDialogButtonBox::Ok | QDialogButtonBox::Cancel
316     );
317   this->connect(
318     this->m_Buttons, SIGNAL( accepted( ) ), this, SLOT( accept( ) )
319     );
320   this->connect(
321     this->m_Buttons, SIGNAL( rejected( ) ), this, SLOT( reject( ) )
322     );
323   this->m_ToolsLayout->addWidget( this->m_Buttons );
324
325   this->updateView( );
326   this->m_WidgetsUpdated = true;
327 }
328
329 // -------------------------------------------------------------------------
330 void cpPlugins::ParametersQtDialog::
331 _updateWidgets( )
332 {
333   if( this->m_WidgetsUpdated || this->m_ProcessObject == NULL )
334     return;
335   if( this->m_Manual )
336     return;
337
338   // Set dialog title
339   std::stringstream title;
340   title
341     << "Parameters for an object of class \""
342     << this->m_ProcessObject->GetClassName( )
343     << "\"";
344   this->m_Title->setText( title.str( ).c_str( ) );
345
346   // Check if an explicit re-execution button is needed
347   if( this->m_ProcessObject->GetCouldHaveExplicitReExecution( ) )
348   {
349     QCheckBox* v_bool = new QCheckBox( this );
350     v_bool->setObjectName( "___ExplicitReExecution___" );
351     v_bool->setText( "Explicit re-execution" );
352     v_bool->setChecked( this->m_ProcessObject->GetExplicitReExecution( ) );
353
354     QHBoxLayout* new_layout = new QHBoxLayout( );
355     new_layout->addWidget( v_bool );
356     this->m_ToolsLayout->addLayout( new_layout );
357
358   } // fi
359
360   // Put values
361   auto parameters = this->m_ProcessObject->GetParameters( );
362   auto& raw_params = parameters->GetRawParameters( );
363   for( auto pIt = raw_params.begin( ); pIt != raw_params.end( ); ++pIt )
364   {
365     QWidget* w_input = NULL;
366     switch( pIt->second.first )
367     {
368     case Parameters::String:
369     {
370       QLineEdit* v_string = new QLineEdit( this );
371       v_string->setObjectName( pIt->first.c_str( ) );
372       v_string->setText( pIt->second.second.c_str( ) );
373       w_input = v_string;
374     }
375     break;
376     case Parameters::Bool:
377     {
378       QCheckBox* v_bool = new QCheckBox( this );
379       v_bool->setObjectName( pIt->first.c_str( ) );
380       v_bool->setText( "[ON/OFF]" );
381       v_bool->setChecked( pIt->second.second == "1" );
382       w_input = v_bool;
383     }
384     break;
385     case Parameters::Int:
386     case Parameters::Uint:
387     {
388       std::istringstream tok_str( pIt->second.second );
389       int v;
390       tok_str >> v;
391       QSpinBox* v_uint = new QSpinBox( this );
392       v_uint->setObjectName( pIt->first.c_str( ) );
393       if( pIt->second.first == Parameters::Uint )
394         v_uint->setMinimum( 0 );
395       else
396         v_uint->setMinimum( -std::numeric_limits< int >::max( ) );
397       v_uint->setMaximum( std::numeric_limits< int >::max( ) );
398       v_uint->setValue( v );
399       w_input = v_uint;
400     }
401     break;
402     case Parameters::Real:
403     {
404       std::istringstream tok_str( pIt->second.second );
405       double v;
406       tok_str >> v;
407       QDoubleSpinBox* v_double = new QDoubleSpinBox( this );
408       v_double->setObjectName( pIt->first.c_str( ) );
409       v_double->setDecimals( 3 );
410       v_double->setMinimum( -std::numeric_limits< double >::max( ) );
411       v_double->setMaximum(  std::numeric_limits< double >::max( ) );
412       v_double->setValue( v );
413       w_input = v_double;
414     }
415     break;
416     case Parameters::OpenFileName:
417     {
418       QFrame* frame = new QFrame( this );
419       QHBoxLayout* layout = new QHBoxLayout( frame );
420       QLineEdit* v_string = new QLineEdit( frame );
421       v_string->setObjectName( pIt->first.c_str( ) );
422       v_string->setText( pIt->second.second.c_str( ) );
423       QPushButton* v_button = new QPushButton( frame );
424       v_button->setObjectName( ( pIt->first + "_=?btn" ).c_str( ) );
425       v_button->setText( "..." );
426       v_button->connect(
427         v_button, SIGNAL( clicked( ) ),
428         this, SLOT( _dlg_OpenSingleFile( ) )
429         );
430       layout->addWidget( v_string );
431       layout->addWidget( v_button );
432       w_input = frame;
433     }
434     case Parameters::SaveFileName:
435     {
436       QFrame* frame = new QFrame( this );
437       QHBoxLayout* layout = new QHBoxLayout( frame );
438       QLineEdit* v_string = new QLineEdit( frame );
439       v_string->setObjectName( pIt->first.c_str( ) );
440       v_string->setText( pIt->second.second.c_str( ) );
441       QPushButton* v_button = new QPushButton( frame );
442       v_button->setObjectName( ( pIt->first + "_=?btn" ).c_str( ) );
443       v_button->setText( "..." );
444       v_button->connect(
445         v_button, SIGNAL( clicked( ) ),
446         this, SLOT( _dlg_SaveSingleFile( ) )
447         );
448       layout->addWidget( v_string );
449       layout->addWidget( v_button );
450       w_input = frame;
451     }
452     break;
453     case Parameters::PathName:
454     {
455       QFrame* frame = new QFrame( this );
456       QHBoxLayout* layout = new QHBoxLayout( frame );
457       QLineEdit* v_string = new QLineEdit( frame );
458       v_string->setObjectName( pIt->first.c_str( ) );
459       v_string->setText( pIt->second.second.c_str( ) );
460       QPushButton* v_button = new QPushButton( frame );
461       v_button->setObjectName( ( pIt->first + "_=?btn" ).c_str( ) );
462       v_button->setText( "..." );
463       v_button->connect(
464         v_button, SIGNAL( clicked( ) ),
465         this, SLOT( _dlg_OpenSinglePath( ) )
466         );
467       layout->addWidget( v_string );
468       layout->addWidget( v_button );
469       w_input = frame;
470     }
471     break;
472     case Parameters::StringList:
473       break;
474     case Parameters::BoolList:
475       break;
476     case Parameters::IntList:
477     {
478       QFrame* frame = new QFrame( this );
479       QHBoxLayout* layout = new QHBoxLayout( frame );
480       QLineEdit* v_string = new QLineEdit( frame );
481       v_string->setObjectName( pIt->first.c_str( ) );
482       v_string->setText( pIt->second.second.c_str( ) );
483       QPushButton* v_button = new QPushButton( frame );
484       v_button->setObjectName( ( pIt->first + "_=?btn" ).c_str( ) );
485       v_button->setText( "+" );
486       v_button->connect(
487         v_button, SIGNAL( clicked( ) ),
488         this, SLOT( _dlg_AddInt( ) )
489         );
490       layout->addWidget( v_string );
491       layout->addWidget( v_button );
492       w_input = frame;
493     }
494     break;
495     case Parameters::UintList:
496     {
497       QFrame* frame = new QFrame( this );
498       QHBoxLayout* layout = new QHBoxLayout( frame );
499       QLineEdit* v_string = new QLineEdit( frame );
500       v_string->setObjectName( pIt->first.c_str( ) );
501       v_string->setText( pIt->second.second.c_str( ) );
502       QPushButton* v_button = new QPushButton( frame );
503       v_button->setObjectName( ( pIt->first + "_=?btn" ).c_str( ) );
504       v_button->setText( "+" );
505       v_button->connect(
506         v_button, SIGNAL( clicked( ) ),
507         this, SLOT( _dlg_AddUint( ) )
508         );
509       layout->addWidget( v_string );
510       layout->addWidget( v_button );
511       w_input = frame;
512     }
513     break;
514     case Parameters::RealList:
515     {
516       QFrame* frame = new QFrame( this );
517       QHBoxLayout* layout = new QHBoxLayout( frame );
518       QLineEdit* v_string = new QLineEdit( frame );
519       v_string->setObjectName( pIt->first.c_str( ) );
520       v_string->setText( pIt->second.second.c_str( ) );
521       QPushButton* v_button = new QPushButton( frame );
522       v_button->setObjectName( ( pIt->first + "_=?btn" ).c_str( ) );
523       v_button->setText( "+" );
524       v_button->connect(
525         v_button, SIGNAL( clicked( ) ),
526         this, SLOT( _dlg_AddReal( ) )
527         );
528       layout->addWidget( v_string );
529       layout->addWidget( v_button );
530       w_input = frame;
531     }
532     break;
533     case Parameters::OpenFileNameList:
534     {
535       QFrame* frame = new QFrame( this );
536       QHBoxLayout* layout = new QHBoxLayout( frame );
537       QLineEdit* v_string = new QLineEdit( frame );
538       v_string->setObjectName( pIt->first.c_str( ) );
539       v_string->setMaxLength( std::numeric_limits< int >::max( ) );
540       v_string->setText( pIt->second.second.c_str( ) );
541       QPushButton* v_button = new QPushButton( frame );
542       v_button->setObjectName( ( pIt->first + "_=?btn" ).c_str( ) );
543       v_button->setText( "..." );
544       v_button->connect(
545         v_button, SIGNAL( clicked( ) ),
546         this, SLOT( _dlg_OpenMultipleFiles( ) )
547         );
548       layout->addWidget( v_string );
549       layout->addWidget( v_button );
550       w_input = frame;
551     }
552     break;
553     case Parameters::SaveFileNameList:
554       break;
555     case Parameters::PathNameList:
556       break;
557     case Parameters::Choices:
558     {
559       QComboBox* v_choices = new QComboBox( this );
560       v_choices->setObjectName( pIt->first.c_str( ) );
561
562       std::istringstream str0( pIt->second.second );
563       std::string choices;
564       std::getline( str0, choices, '@' );
565       std::istringstream str1( choices );
566       std::string token;
567       int id = 0;
568       while( std::getline( str1, token, '#' ) )
569         v_choices->insertItem( id++, token.c_str( ) );
570       w_input = v_choices;
571     }
572     break;
573     default:
574       w_input = NULL;
575       break;
576     } // hctiws
577
578     // Ok, a representation was created
579     if( w_input != NULL )
580     {
581       QHBoxLayout* new_layout = new QHBoxLayout( );
582       QLabel* label = new QLabel( this );
583       label->setText( QString( pIt->first.c_str( ) ) );
584       new_layout->addWidget( label );
585       new_layout->addWidget( w_input );
586       this->m_ToolsLayout->addLayout( new_layout );
587
588     } // fi
589
590   } // rof
591
592   // Update values
593   this->_addButtons( );
594 }
595
596 // -------------------------------------------------------------------------
597 void cpPlugins::ParametersQtDialog::
598 _dlg_OpenSingleFile( )
599 {
600   auto parameters = this->m_ProcessObject->GetParameters( );
601   QPushButton* btn = dynamic_cast< QPushButton* >( this->sender( ) );
602   if( btn != NULL )
603   {
604     std::string bName = btn->objectName( ).toStdString( );
605     std::string line_name = bName.substr( 0, bName.find( "_=?btn" ) );
606     QLineEdit* line = this->findChild< QLineEdit* >( line_name.c_str( ) );
607     if( line != NULL )
608     {
609       std::string param_name = line->objectName( ).toStdString( );
610       if( param_name != "" )
611       {
612         std::string param_value = parameters->GetOpenFileName( param_name );
613         if( param_value == "" )
614           param_value = ".";
615         QStringList dialog_filters;
616         std::string extensions = parameters->GetAcceptedFileExtensions( param_name );
617         if( extensions != "" )
618           dialog_filters << extensions.c_str( );
619         dialog_filters << "Any file (*)";
620
621         // Show dialog and check if it was accepted
622         QFileDialog dialog( this );
623         dialog.setFileMode( QFileDialog::ExistingFile );
624         dialog.setDirectory( QFileDialog::tr( param_value.c_str( ) ) );
625         dialog.setNameFilters( dialog_filters );
626         dialog.setAcceptMode( QFileDialog::AcceptOpen );
627         if( dialog.exec( ) )
628           line->setText( *( dialog.selectedFiles( ).begin( ) ) );
629
630       } // fi
631
632     } // fi
633
634   } // fi
635 }
636
637 // -------------------------------------------------------------------------
638 void cpPlugins::ParametersQtDialog::
639 _dlg_SaveSingleFile( )
640 {
641   auto parameters = this->m_ProcessObject->GetParameters( );
642   QPushButton* btn = dynamic_cast< QPushButton* >( this->sender( ) );
643   if( btn != NULL )
644   {
645     std::string bName = btn->objectName( ).toStdString( );
646     std::string line_name = bName.substr( 0, bName.find( "_=?btn" ) );
647     QLineEdit* line = this->findChild< QLineEdit* >( line_name.c_str( ) );
648     if( line != NULL )
649     {
650       std::string param_name = line->objectName( ).toStdString( );
651       if( param_name != "" )
652       {
653         std::string param_value = parameters->GetSaveFileName( param_name );
654         if( param_value == "" )
655           param_value = ".";
656         QStringList dialog_filters;
657         std::string extensions = parameters->GetAcceptedFileExtensions( param_name );
658         if( extensions != "" )
659           dialog_filters << extensions.c_str( );
660         dialog_filters << "Any file (*)";
661
662         // Show dialog and check if it was accepted
663         QFileDialog dialog( this );
664         dialog.setFileMode( QFileDialog::AnyFile );
665         dialog.setDirectory( QFileDialog::tr( param_value.c_str( ) ) );
666         dialog.setNameFilters( dialog_filters );
667         dialog.setAcceptMode( QFileDialog::AcceptSave );
668         if( dialog.exec( ) )
669           line->setText( *( dialog.selectedFiles( ).begin( ) ) );
670
671       } // fi
672
673     } // fi
674
675   } // fi
676 }
677
678 // -------------------------------------------------------------------------
679 void cpPlugins::ParametersQtDialog::
680 _dlg_OpenSinglePath( )
681 {
682   auto parameters = this->m_ProcessObject->GetParameters( );
683   QPushButton* btn = dynamic_cast< QPushButton* >( this->sender( ) );
684   if( btn != NULL )
685   {
686     std::string bName = btn->objectName( ).toStdString( );
687     std::string line_name = bName.substr( 0, bName.find( "_=?btn" ) );
688     QLineEdit* line = this->findChild< QLineEdit* >( line_name.c_str( ) );
689     if( line != NULL )
690     {
691       std::string param_name = line->objectName( ).toStdString( );
692       if( param_name != "" )
693       {
694         std::string param_value = parameters->GetPathName( param_name );
695         if( param_value == "" )
696           param_value = ".";
697
698         // Show dialog and check if it was accepted
699         QFileDialog dialog( this );
700         dialog.setFileMode( QFileDialog::Directory );
701         dialog.setDirectory( QFileDialog::tr( param_value.c_str( ) ) );
702         dialog.setAcceptMode( QFileDialog::AcceptOpen );
703         if( dialog.exec( ) )
704           line->setText( *( dialog.selectedFiles( ).begin( ) ) );
705
706       } // fi
707
708     } // fi
709
710   } // fi
711 }
712
713 // -------------------------------------------------------------------------
714 void cpPlugins::ParametersQtDialog::
715 _dlg_OpenMultipleFiles( )
716 {
717   auto parameters = this->m_ProcessObject->GetParameters( );
718   QPushButton* btn = dynamic_cast< QPushButton* >( this->sender( ) );
719   if( btn != NULL )
720   {
721     std::string bName = btn->objectName( ).toStdString( );
722     std::string line_name = bName.substr( 0, bName.find( "_=?btn" ) );
723
724     QLineEdit* line = this->findChild< QLineEdit* >( line_name.c_str( ) );
725     if( line != NULL )
726     {
727       std::string param_name = line->objectName( ).toStdString( );
728       if( param_name != "" )
729       {
730         QStringList dialog_filters;
731         std::string extensions = parameters->GetAcceptedFileExtensions( param_name );
732         if( extensions != "" )
733           dialog_filters << extensions.c_str( );
734         dialog_filters << "Any file (*)";
735
736         // Show dialog and check if it was accepted
737         QFileDialog dialog( this );
738         dialog.setFileMode( QFileDialog::ExistingFiles );
739         dialog.setNameFilters( dialog_filters );
740         dialog.setAcceptMode( QFileDialog::AcceptOpen );
741         if( dialog.exec( ) )
742         {
743           if( dialog.selectedFiles( ).size( ) > 0 )
744           {
745             std::stringstream str;
746             auto files = dialog.selectedFiles( );
747             auto fIt = files.begin( );
748             str << fIt->toStdString( );
749             ++fIt;
750             for( ; fIt != files.end( ); ++fIt )
751               str << "#" << fIt->toStdString( );
752             line->setText( str.str( ).c_str( ) );
753
754           } // fi
755
756         } // fi
757
758       } // fi
759
760     } // fi
761
762   } // fi
763 }
764
765 // -------------------------------------------------------------------------
766 void cpPlugins::ParametersQtDialog::
767 _dlg_AddInt( )
768 {
769   QPushButton* btn = dynamic_cast< QPushButton* >( this->sender( ) );
770   if( btn != NULL )
771   {
772     std::string bName = btn->objectName( ).toStdString( );
773     std::string line_name = bName.substr( 0, bName.find( "_=?btn" ) );
774     QLineEdit* line = this->findChild< QLineEdit* >( line_name.c_str( ) );
775     if( line != NULL )
776     {
777       std::string param_name = line->objectName( ).toStdString( );
778       if( param_name != "" )
779       {
780         bool ok;
781         int value =
782           QInputDialog::getInt(
783             this,
784             (
785               std::string( "Add new value to \"" ) +
786               param_name +
787               std::string( "\"" )
788               ).c_str( ),
789             "Value:",
790             0,
791             -std::numeric_limits< int >::max( ),
792             std::numeric_limits< int >::max( ),
793             1, &ok
794             );
795         if( ok )
796         {
797           std::string values = line->text( ).toStdString( );
798           if( values != "" )
799             values += "#";
800           std::stringstream str;
801           str << values << value;
802           line->setText( str.str( ).c_str( ) );
803
804         } // fi
805
806       } // fi
807
808     } // fi
809
810   } // fi
811 }
812
813 // -------------------------------------------------------------------------
814 void cpPlugins::ParametersQtDialog::
815 _dlg_AddUint( )
816 {
817   QPushButton* btn = dynamic_cast< QPushButton* >( this->sender( ) );
818   if( btn != NULL )
819   {
820     std::string bName = btn->objectName( ).toStdString( );
821     std::string line_name = bName.substr( 0, bName.find( "_=?btn" ) );
822     QLineEdit* line = this->findChild< QLineEdit* >( line_name.c_str( ) );
823     if( line != NULL )
824     {
825       std::string param_name = line->objectName( ).toStdString( );
826       if( param_name != "" )
827       {
828         bool ok;
829         int value =
830           QInputDialog::getInt(
831             this,
832             (
833               std::string( "Add new value to \"" ) +
834               param_name +
835               std::string( "\"" )
836               ).c_str( ),
837             "Value:",
838             0, 0, std::numeric_limits< int >::max( ), 1,
839             &ok
840             );
841         if( ok )
842         {
843           std::string values = line->text( ).toStdString( );
844           if( values != "" )
845             values += "#";
846           std::stringstream str;
847           str << values << value;
848           line->setText( str.str( ).c_str( ) );
849
850         } // fi
851
852       } // fi
853
854     } // fi
855
856   } // fi
857 }
858
859 // -------------------------------------------------------------------------
860 void cpPlugins::ParametersQtDialog::
861 _dlg_AddReal( )
862 {
863   QPushButton* btn = dynamic_cast< QPushButton* >( this->sender( ) );
864   if( btn != NULL )
865   {
866     std::string bName = btn->objectName( ).toStdString( );
867     std::string line_name = bName.substr( 0, bName.find( "_=?btn" ) );
868     QLineEdit* line = this->findChild< QLineEdit* >( line_name.c_str( ) );
869     if( line != NULL )
870     {
871       std::string param_name = line->objectName( ).toStdString( );
872       if( param_name != "" )
873       {
874         bool ok;
875         double value =
876           QInputDialog::getDouble(
877             this,
878             (
879               std::string( "Add new value to \"" ) +
880               param_name +
881               std::string( "\"" )
882               ).c_str( ),
883             "Value:",
884             0,
885             -std::numeric_limits< double >::max( ),
886             std::numeric_limits< double >::max( ),
887             1, &ok
888             );
889         if( ok )
890         {
891           std::string values = line->text( ).toStdString( );
892           if( values != "" )
893             values += "#";
894           std::stringstream str;
895           str << values << value;
896           line->setText( str.str( ).c_str( ) );
897
898         } // fi
899
900       } // fi
901
902     } // fi
903
904   } // fi
905 }
906
907 #endif // cpPlugins_QT4
908
909 // eof - $RCSfile$