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