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