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