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