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