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