]> 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/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 << "Parameters for \"" << filter->GetName( ) << "\"";
303   this->m_Title->setText( title.str( ).c_str( ) );
304
305   // Put values
306   auto& raw_params = this->m_Parameters->GetRawParameters( );
307   for( auto pIt = raw_params.begin( ); pIt != raw_params.end( ); ++pIt )
308   {
309     QWidget* w_input = NULL;
310     switch( pIt->second.first )
311     {
312     case Parameters::String:
313     {
314       QLineEdit* v_string = new QLineEdit( this );
315       v_string->setObjectName( pIt->first.c_str( ) );
316       v_string->setText( pIt->second.second.c_str( ) );
317       w_input = v_string;
318     }
319     break;
320     case Parameters::Bool:
321     {
322       QCheckBox* v_bool = new QCheckBox( this );
323       v_bool->setObjectName( pIt->first.c_str( ) );
324       v_bool->setText( "[ON/OFF]" );
325       v_bool->setChecked( pIt->second.second == "1" );
326       w_input = v_bool;
327     }
328     break;
329     case Parameters::Int:
330     case Parameters::Uint:
331     {
332       std::istringstream tok_str( pIt->second.second );
333       int v;
334       tok_str >> v;
335       QSpinBox* v_uint = new QSpinBox( this );
336       v_uint->setObjectName( pIt->first.c_str( ) );
337       if( pIt->second.first == Parameters::Uint )
338         v_uint->setMinimum( 0 );
339       else
340         v_uint->setMinimum( -std::numeric_limits< int >::max( ) );
341       v_uint->setMaximum( std::numeric_limits< int >::max( ) );
342       v_uint->setValue( v );
343       w_input = v_uint;
344     }
345     break;
346     case Parameters::Real:
347     {
348       std::istringstream tok_str( pIt->second.second );
349       double v;
350       tok_str >> v;
351       QDoubleSpinBox* v_double = new QDoubleSpinBox( this );
352       v_double->setObjectName( pIt->first.c_str( ) );
353       v_double->setDecimals( 3 );
354       v_double->setMinimum( -std::numeric_limits< double >::max( ) );
355       v_double->setMaximum(  std::numeric_limits< double >::max( ) );
356       v_double->setValue( v );
357       w_input = v_double;
358     }
359     break;
360     case Parameters::OpenFileName:
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_OpenSingleFile( ) )
373         );
374       layout->addWidget( v_string );
375       layout->addWidget( v_button );
376       w_input = frame;
377     }
378     case Parameters::SaveFileName:
379     {
380       QFrame* frame = new QFrame( this );
381       QHBoxLayout* layout = new QHBoxLayout( frame );
382       QLineEdit* v_string = new QLineEdit( frame );
383       v_string->setObjectName( pIt->first.c_str( ) );
384       v_string->setText( pIt->second.second.c_str( ) );
385       QPushButton* v_button = new QPushButton( frame );
386       v_button->setObjectName( ( pIt->first + "_=?btn" ).c_str( ) );
387       v_button->setText( "..." );
388       v_button->connect(
389         v_button, SIGNAL( clicked( ) ),
390         this, SLOT( _dlg_SaveSingleFile( ) )
391         );
392       layout->addWidget( v_string );
393       layout->addWidget( v_button );
394       w_input = frame;
395     }
396     break;
397     case Parameters::PathName:
398     {
399       QFrame* frame = new QFrame( this );
400       QHBoxLayout* layout = new QHBoxLayout( frame );
401       QLineEdit* v_string = new QLineEdit( frame );
402       v_string->setObjectName( pIt->first.c_str( ) );
403       v_string->setText( pIt->second.second.c_str( ) );
404       QPushButton* v_button = new QPushButton( frame );
405       v_button->setObjectName( ( pIt->first + "_=?btn" ).c_str( ) );
406       v_button->setText( "..." );
407       v_button->connect(
408         v_button, SIGNAL( clicked( ) ),
409         this, SLOT( _dlg_OpenSinglePath( ) )
410         );
411       layout->addWidget( v_string );
412       layout->addWidget( v_button );
413       w_input = frame;
414     }
415     break;
416     case Parameters::StringList:
417       break;
418     case Parameters::BoolList:
419       break;
420     case Parameters::IntList:
421     {
422       QFrame* frame = new QFrame( this );
423       QHBoxLayout* layout = new QHBoxLayout( frame );
424       QLineEdit* v_string = new QLineEdit( frame );
425       v_string->setObjectName( pIt->first.c_str( ) );
426       v_string->setText( pIt->second.second.c_str( ) );
427       QPushButton* v_button = new QPushButton( frame );
428       v_button->setObjectName( ( pIt->first + "_=?btn" ).c_str( ) );
429       v_button->setText( "+" );
430       v_button->connect(
431         v_button, SIGNAL( clicked( ) ),
432         this, SLOT( _dlg_AddInt( ) )
433         );
434       layout->addWidget( v_string );
435       layout->addWidget( v_button );
436       w_input = frame;
437     }
438     break;
439     case Parameters::UintList:
440     {
441       QFrame* frame = new QFrame( this );
442       QHBoxLayout* layout = new QHBoxLayout( frame );
443       QLineEdit* v_string = new QLineEdit( frame );
444       v_string->setObjectName( pIt->first.c_str( ) );
445       v_string->setText( pIt->second.second.c_str( ) );
446       QPushButton* v_button = new QPushButton( frame );
447       v_button->setObjectName( ( pIt->first + "_=?btn" ).c_str( ) );
448       v_button->setText( "+" );
449       v_button->connect(
450         v_button, SIGNAL( clicked( ) ),
451         this, SLOT( _dlg_AddUint( ) )
452         );
453       layout->addWidget( v_string );
454       layout->addWidget( v_button );
455       w_input = frame;
456     }
457     break;
458     case Parameters::RealList:
459     {
460       QFrame* frame = new QFrame( this );
461       QHBoxLayout* layout = new QHBoxLayout( frame );
462       QLineEdit* v_string = new QLineEdit( frame );
463       v_string->setObjectName( pIt->first.c_str( ) );
464       v_string->setText( pIt->second.second.c_str( ) );
465       QPushButton* v_button = new QPushButton( frame );
466       v_button->setObjectName( ( pIt->first + "_=?btn" ).c_str( ) );
467       v_button->setText( "+" );
468       v_button->connect(
469         v_button, SIGNAL( clicked( ) ),
470         this, SLOT( _dlg_AddReal( ) )
471         );
472       layout->addWidget( v_string );
473       layout->addWidget( v_button );
474       w_input = frame;
475     }
476     break;
477     case Parameters::OpenFileNameList:
478     {
479       QFrame* frame = new QFrame( this );
480       QHBoxLayout* layout = new QHBoxLayout( frame );
481       QLineEdit* v_string = new QLineEdit( frame );
482       v_string->setObjectName( pIt->first.c_str( ) );
483       v_string->setMaxLength( std::numeric_limits< int >::max( ) );
484       v_string->setText( pIt->second.second.c_str( ) );
485       QPushButton* v_button = new QPushButton( frame );
486       v_button->setObjectName( ( pIt->first + "_=?btn" ).c_str( ) );
487       v_button->setText( "..." );
488       v_button->connect(
489         v_button, SIGNAL( clicked( ) ),
490         this, SLOT( _dlg_OpenMultipleFiles( ) )
491         );
492       layout->addWidget( v_string );
493       layout->addWidget( v_button );
494       w_input = frame;
495     }
496     break;
497     case Parameters::SaveFileNameList:
498       break;
499     case Parameters::PathNameList:
500       break;
501     case Parameters::Choices:
502     {
503       QComboBox* v_choices = new QComboBox( this );
504       v_choices->setObjectName( pIt->first.c_str( ) );
505
506       std::istringstream str0( pIt->second.second );
507       std::string choices;
508       std::getline( str0, choices, '@' );
509       std::istringstream str1( choices );
510       std::string token;
511       int id = 0;
512       while( std::getline( str1, token, '#' ) )
513         v_choices->insertItem( id++, token.c_str( ) );
514       w_input = v_choices;
515     }
516     break;
517     default:
518       w_input = NULL;
519       break;
520     } // hctiws
521
522     // Ok, a representation was created
523     if( w_input != NULL )
524     {
525       QHBoxLayout* new_layout = new QHBoxLayout( );
526       QLabel* label = new QLabel( this );
527       label->setText( QString( pIt->first.c_str( ) ) );
528       new_layout->addWidget( label );
529       new_layout->addWidget( w_input );
530       this->m_ToolsLayout->addLayout( new_layout );
531
532     } // fi
533
534   } // rof
535
536   // Update values
537   this->_addButtons( );
538 }
539
540 // -------------------------------------------------------------------------
541 void cpPlugins::Interface::ParametersQtDialog::
542 _dlg_OpenSingleFile( )
543 {
544   QPushButton* btn = dynamic_cast< QPushButton* >( this->sender( ) );
545   if( btn != NULL )
546   {
547     std::string bName = btn->objectName( ).toStdString( );
548     std::string line_name = bName.substr( 0, bName.find( "_=?btn" ) );
549     QLineEdit* line = this->findChild< QLineEdit* >( line_name.c_str( ) );
550     if( line != NULL )
551     {
552       std::string param_name = line->objectName( ).toStdString( );
553       if( param_name != "" )
554       {
555         std::string param_value =
556           this->m_Parameters->GetOpenFileName( param_name );
557         if( param_value == "" )
558           param_value = ".";
559         QStringList dialog_filters;
560         std::string extensions =
561           this->m_Parameters->GetAcceptedFileExtensions( param_name );
562         if( extensions != "" )
563           dialog_filters << extensions.c_str( );
564         dialog_filters << "Any file (*)";
565
566         // Show dialog and check if it was accepted
567         QFileDialog dialog( this );
568         dialog.setFileMode( QFileDialog::ExistingFile );
569         dialog.setDirectory( QFileDialog::tr( param_value.c_str( ) ) );
570         dialog.setNameFilters( dialog_filters );
571         dialog.setAcceptMode( QFileDialog::AcceptOpen );
572         if( dialog.exec( ) )
573           line->setText( *( dialog.selectedFiles( ).begin( ) ) );
574
575       } // fi
576
577     } // fi
578
579   } // fi
580 }
581
582 // -------------------------------------------------------------------------
583 void cpPlugins::Interface::ParametersQtDialog::
584 _dlg_SaveSingleFile( )
585 {
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 =
598           this->m_Parameters->GetSaveFileName( param_name );
599         if( param_value == "" )
600           param_value = ".";
601         QStringList dialog_filters;
602         std::string extensions =
603           this->m_Parameters->GetAcceptedFileExtensions( param_name );
604         if( extensions != "" )
605           dialog_filters << extensions.c_str( );
606         dialog_filters << "Any file (*)";
607
608         // Show dialog and check if it was accepted
609         QFileDialog dialog( this );
610         dialog.setFileMode( QFileDialog::AnyFile );
611         dialog.setDirectory( QFileDialog::tr( param_value.c_str( ) ) );
612         dialog.setNameFilters( dialog_filters );
613         dialog.setAcceptMode( QFileDialog::AcceptSave );
614         if( dialog.exec( ) )
615           line->setText( *( dialog.selectedFiles( ).begin( ) ) );
616
617       } // fi
618
619     } // fi
620
621   } // fi
622 }
623
624 // -------------------------------------------------------------------------
625 void cpPlugins::Interface::ParametersQtDialog::
626 _dlg_OpenSinglePath( )
627 {
628   QPushButton* btn = dynamic_cast< QPushButton* >( this->sender( ) );
629   if( btn != NULL )
630   {
631     std::string bName = btn->objectName( ).toStdString( );
632     std::string line_name = bName.substr( 0, bName.find( "_=?btn" ) );
633     QLineEdit* line = this->findChild< QLineEdit* >( line_name.c_str( ) );
634     if( line != NULL )
635     {
636       std::string param_name = line->objectName( ).toStdString( );
637       if( param_name != "" )
638       {
639         std::string param_value =
640           this->m_Parameters->GetPathName( param_name );
641         if( param_value == "" )
642           param_value = ".";
643
644         // Show dialog and check if it was accepted
645         QFileDialog dialog( this );
646         dialog.setFileMode( QFileDialog::Directory );
647         dialog.setDirectory( QFileDialog::tr( param_value.c_str( ) ) );
648         dialog.setAcceptMode( QFileDialog::AcceptOpen );
649         if( dialog.exec( ) )
650           line->setText( *( dialog.selectedFiles( ).begin( ) ) );
651
652       } // fi
653
654     } // fi
655
656   } // fi
657 }
658
659 // -------------------------------------------------------------------------
660 void cpPlugins::Interface::ParametersQtDialog::
661 _dlg_OpenMultipleFiles( )
662 {
663   QPushButton* btn = dynamic_cast< QPushButton* >( this->sender( ) );
664   if( btn != NULL )
665   {
666     std::string bName = btn->objectName( ).toStdString( );
667     std::string line_name = bName.substr( 0, bName.find( "_=?btn" ) );
668
669     QLineEdit* line = this->findChild< QLineEdit* >( line_name.c_str( ) );
670     if( line != NULL )
671     {
672       std::string param_name = line->objectName( ).toStdString( );
673       if( param_name != "" )
674       {
675         QStringList dialog_filters;
676         std::string extensions =
677           this->m_Parameters->GetAcceptedFileExtensions( param_name );
678         if( extensions != "" )
679           dialog_filters << extensions.c_str( );
680         dialog_filters << "Any file (*)";
681
682         // Show dialog and check if it was accepted
683         QFileDialog dialog( this );
684         dialog.setFileMode( QFileDialog::ExistingFiles );
685         dialog.setNameFilters( dialog_filters );
686         dialog.setAcceptMode( QFileDialog::AcceptOpen );
687         if( dialog.exec( ) )
688         {
689           if( dialog.selectedFiles( ).size( ) > 0 )
690           {
691             std::stringstream str;
692             auto files = dialog.selectedFiles( );
693             auto fIt = files.begin( );
694             str << fIt->toStdString( );
695             ++fIt;
696             for( ; fIt != files.end( ); ++fIt )
697               str << "#" << fIt->toStdString( );
698             line->setText( str.str( ).c_str( ) );
699
700           } // fi
701
702         } // fi
703
704       } // fi
705
706     } // fi
707
708   } // fi
709 }
710
711 // -------------------------------------------------------------------------
712 void cpPlugins::Interface::ParametersQtDialog::
713 _dlg_AddInt( )
714 {
715   QPushButton* btn = dynamic_cast< QPushButton* >( this->sender( ) );
716   if( btn != NULL )
717   {
718     std::string bName = btn->objectName( ).toStdString( );
719     std::string line_name = bName.substr( 0, bName.find( "_=?btn" ) );
720     QLineEdit* line = this->findChild< QLineEdit* >( line_name.c_str( ) );
721     if( line != NULL )
722     {
723       std::string param_name = line->objectName( ).toStdString( );
724       if( param_name != "" )
725       {
726         bool ok;
727         int value =
728           QInputDialog::getInt(
729             this,
730             (
731               std::string( "Add new value to \"" ) +
732               param_name +
733               std::string( "\"" )
734               ).c_str( ),
735             "Value:",
736             0,
737             -std::numeric_limits< int >::max( ),
738             std::numeric_limits< int >::max( ),
739             1, &ok
740             );
741         if( ok )
742         {
743           std::string values = line->text( ).toStdString( );
744           if( values != "" )
745             values += "#";
746           std::stringstream str;
747           str << values << value;
748           line->setText( str.str( ).c_str( ) );
749
750         } // fi
751
752       } // fi
753
754     } // fi
755
756   } // fi
757 }
758
759 // -------------------------------------------------------------------------
760 void cpPlugins::Interface::ParametersQtDialog::
761 _dlg_AddUint( )
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     QLineEdit* line = this->findChild< QLineEdit* >( line_name.c_str( ) );
769     if( line != NULL )
770     {
771       std::string param_name = line->objectName( ).toStdString( );
772       if( param_name != "" )
773       {
774         bool ok;
775         int value =
776           QInputDialog::getInt(
777             this,
778             (
779               std::string( "Add new value to \"" ) +
780               param_name +
781               std::string( "\"" )
782               ).c_str( ),
783             "Value:",
784             0, 0, std::numeric_limits< int >::max( ), 1,
785             &ok
786             );
787         if( ok )
788         {
789           std::string values = line->text( ).toStdString( );
790           if( values != "" )
791             values += "#";
792           std::stringstream str;
793           str << values << value;
794           line->setText( str.str( ).c_str( ) );
795
796         } // fi
797
798       } // fi
799
800     } // fi
801
802   } // fi
803 }
804
805 // -------------------------------------------------------------------------
806 void cpPlugins::Interface::ParametersQtDialog::
807 _dlg_AddReal( )
808 {
809   QPushButton* btn = dynamic_cast< QPushButton* >( this->sender( ) );
810   if( btn != NULL )
811   {
812     std::string bName = btn->objectName( ).toStdString( );
813     std::string line_name = bName.substr( 0, bName.find( "_=?btn" ) );
814     QLineEdit* line = this->findChild< QLineEdit* >( line_name.c_str( ) );
815     if( line != NULL )
816     {
817       std::string param_name = line->objectName( ).toStdString( );
818       if( param_name != "" )
819       {
820         bool ok;
821         double value =
822           QInputDialog::getDouble(
823             this,
824             (
825               std::string( "Add new value to \"" ) +
826               param_name +
827               std::string( "\"" )
828               ).c_str( ),
829             "Value:",
830             0,
831             -std::numeric_limits< double >::max( ),
832             std::numeric_limits< double >::max( ),
833             1, &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 #endif // cpPlugins_Interface_QT4
854
855 // eof - $RCSfile$