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