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