]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/ParametersQtDialog.cxx
First dump for version 0.1.0
[cpPlugins.git] / lib / cpPlugins / ParametersQtDialog.cxx
1 #include <cpPlugins/ParametersQtDialog.h>
2
3 #ifdef cpPlugins_QT4
4
5 #include <limits>
6
7 #include <cpPlugins/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::ParametersQtDialog::
21 ParametersQtDialog( QWidget* parent, Qt::WindowFlags f )
22   : QDialog( parent, f ),
23     m_ProcessObject( 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::ParametersQtDialog::
37 ~ParametersQtDialog( )
38 {
39   delete this->m_Title;
40   delete this->m_ToolsLayout;
41   delete this->m_MainLayout;
42 }
43
44 // -------------------------------------------------------------------------
45 cpPlugins::
46 ProcessObject* cpPlugins::ParametersQtDialog::
47 getProcessObject( ) const
48 {
49   return( this->m_ProcessObject );
50 }
51
52 // -------------------------------------------------------------------------
53 bool cpPlugins::ParametersQtDialog::
54 setProcessObject( ProcessObject* obj )
55 {
56   if( this->m_ProcessObject != NULL || obj == NULL )
57     return( false );
58   this->m_ProcessObject = obj;
59   this->m_WidgetsUpdated = false;
60   return( true );
61 }
62
63 // -------------------------------------------------------------------------
64 int cpPlugins::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::ParametersQtDialog::
80 updateParameters( )
81 {
82   if( this->m_ProcessObject == NULL )
83     return;
84
85   // Put values
86   auto parameters = this->m_ProcessObject->GetParameters( );
87   auto& raw_params = parameters->GetRawParameters( );
88   for( auto pIt = raw_params.begin( ); pIt != raw_params.end( ); ++pIt )
89   {
90     QString pName = pIt->first.c_str( );
91     switch( pIt->second.first )
92     {
93     case Parameters::String:
94     case Parameters::OpenFileName:
95     case Parameters::SaveFileName:
96     case Parameters::PathName:
97     case Parameters::IntList:
98     case Parameters::UintList:
99     case Parameters::RealList:
100     case Parameters::OpenFileNameList:
101     {
102       QLineEdit* v_string = this->findChild< QLineEdit* >( pName );
103       if( v_string != NULL )
104         pIt->second.second = v_string->text( ).toStdString( );
105     }
106     break;
107     case Parameters::Bool:
108     {
109       QCheckBox* v_bool = this->findChild< QCheckBox* >( pName );
110       if( v_bool != NULL )
111         pIt->second.second = ( v_bool->isChecked( ) )? "1": "0";
112     }
113     break;
114     case Parameters::Int:
115     case Parameters::Uint:
116     {
117       QSpinBox* v_uint = this->findChild< QSpinBox* >( pName );
118       if( v_uint )
119       {
120         std::stringstream str;
121         str << v_uint->value( );
122         pIt->second.second = str.str( );
123
124       } // fi
125     }
126     break;
127     case Parameters::Real:
128     {
129       QDoubleSpinBox* v_double = this->findChild< QDoubleSpinBox* >( pName );
130       if( v_double )
131       {
132         std::stringstream str;
133         str << v_double->value( );
134         pIt->second.second = str.str( );
135
136       } // fi
137     }
138     break;
139     case Parameters::StringList:
140       break;
141     case Parameters::BoolList:
142       break;
143     case Parameters::SaveFileNameList:
144       break;
145     case Parameters::PathNameList:
146       break;
147     case Parameters::Choices:
148     {
149       QComboBox* v_choices = this->findChild< QComboBox* >( pName );
150       if( v_choices != NULL )
151       {
152         std::istringstream str_choices( pIt->second.second );
153         std::string real_choices;
154         std::getline( str_choices, real_choices, '@' );
155         pIt->second.second =
156           real_choices + "@" +
157           v_choices->currentText( ).toStdString( );
158
159       } // fi
160     }
161     break;
162     default:
163       break;
164     } // hctiws
165
166   } // rof
167   this->m_ProcessObject->Modified( );
168 }
169
170 // -------------------------------------------------------------------------
171 void cpPlugins::ParametersQtDialog::
172 updateView( )
173 {
174   if( this->m_ProcessObject == NULL )
175     return;
176
177   // Put values
178   auto parameters = this->m_ProcessObject->GetParameters( );
179   auto& raw_params = parameters->GetRawParameters( );
180   for( auto pIt = raw_params.begin( ); pIt != raw_params.end( ); ++pIt )
181   {
182     QString pName = pIt->first.c_str( );
183     switch( pIt->second.first )
184     {
185     case Parameters::String:
186     case Parameters::OpenFileName:
187     case Parameters::SaveFileName:
188     case Parameters::PathName:
189     case Parameters::IntList:
190     case Parameters::UintList:
191     case Parameters::RealList:
192     case Parameters::OpenFileNameList:
193     {
194       QLineEdit* v_string = this->findChild< QLineEdit* >( pName );
195       if( v_string != NULL )
196         v_string->setText( pIt->second.second.c_str( ) );
197     }
198     break;
199     case Parameters::Bool:
200     {
201       QCheckBox* v_bool = this->findChild< QCheckBox* >( pName );
202       if( v_bool != NULL )
203         v_bool->setChecked( pIt->second.second == "1" );
204     }
205     break;
206     case Parameters::Int:
207     case Parameters::Uint:
208     {
209       QSpinBox* v_uint = this->findChild< QSpinBox* >( pName );
210       if( v_uint )
211       {
212         std::istringstream tok_str( pIt->second.second );
213         int v;
214         tok_str >> v;
215         v_uint->setValue( v );
216
217       } // fi
218     }
219     break;
220     case Parameters::Real:
221     {
222       QDoubleSpinBox* v_double = this->findChild< QDoubleSpinBox* >( pName );
223       if( v_double )
224       {
225         std::istringstream tok_str( pIt->second.second );
226         double v;
227         tok_str >> v;
228         v_double->setValue( v );
229
230       } // fi
231     }
232     break;
233     case Parameters::StringList:
234       break;
235     case Parameters::BoolList:
236       break;
237     case Parameters::SaveFileNameList:
238       break;
239     case Parameters::PathNameList:
240       break;
241     case Parameters::Choices:
242     {
243       QComboBox* v_choices = this->findChild< QComboBox* >( pName );
244       if( v_choices != NULL )
245       {
246         std::istringstream str_choices( pIt->second.second );
247         std::string choices, real_choice;
248         std::getline( str_choices, choices, '@' );
249         std::getline( str_choices, real_choice, '@' );
250         std::istringstream str( choices );
251         std::string token;
252         int id = -1, cont = 0;
253         while( std::getline( str, token, '#' ) )
254         {
255           if( token == real_choice )
256             id = cont;
257           cont++;
258
259         } // elihw
260
261         if( id > -1 )
262           v_choices->setCurrentIndex( id );
263
264       } // fi
265     }
266     break;
267     default:
268       break;
269     } // hctiws
270
271   } // rof
272 }
273
274 // -------------------------------------------------------------------------
275 void cpPlugins::ParametersQtDialog::
276 _addButtons( )
277 {
278   // Add buttons
279   this->m_Buttons = new QDialogButtonBox(
280     QDialogButtonBox::Ok | QDialogButtonBox::Cancel
281     );
282   this->connect(
283     this->m_Buttons, SIGNAL( accepted( ) ), this, SLOT( accept( ) )
284     );
285   this->connect(
286     this->m_Buttons, SIGNAL( rejected( ) ), this, SLOT( reject( ) )
287     );
288   this->m_ToolsLayout->addWidget( this->m_Buttons );
289
290   this->updateView( );
291   this->m_WidgetsUpdated = true;
292 }
293
294 // -------------------------------------------------------------------------
295 void cpPlugins::ParametersQtDialog::
296 _updateWidgets( )
297 {
298   if( this->m_WidgetsUpdated || this->m_ProcessObject == NULL )
299     return;
300
301   // Set dialog title
302   std::stringstream title;
303   title
304     << "Parameters for an object of class \""
305     << this->m_ProcessObject->GetClassName( )
306     << "\"";
307   this->m_Title->setText( title.str( ).c_str( ) );
308
309   // Put values
310   auto parameters = this->m_ProcessObject->GetParameters( );
311   auto& raw_params = parameters->GetRawParameters( );
312   for( auto pIt = raw_params.begin( ); pIt != raw_params.end( ); ++pIt )
313   {
314     QWidget* w_input = NULL;
315     switch( pIt->second.first )
316     {
317     case Parameters::String:
318     {
319       QLineEdit* v_string = new QLineEdit( this );
320       v_string->setObjectName( pIt->first.c_str( ) );
321       v_string->setText( pIt->second.second.c_str( ) );
322       w_input = v_string;
323     }
324     break;
325     case Parameters::Bool:
326     {
327       QCheckBox* v_bool = new QCheckBox( this );
328       v_bool->setObjectName( pIt->first.c_str( ) );
329       v_bool->setText( "[ON/OFF]" );
330       v_bool->setChecked( pIt->second.second == "1" );
331       w_input = v_bool;
332     }
333     break;
334     case Parameters::Int:
335     case Parameters::Uint:
336     {
337       std::istringstream tok_str( pIt->second.second );
338       int v;
339       tok_str >> v;
340       QSpinBox* v_uint = new QSpinBox( this );
341       v_uint->setObjectName( pIt->first.c_str( ) );
342       if( pIt->second.first == Parameters::Uint )
343         v_uint->setMinimum( 0 );
344       else
345         v_uint->setMinimum( -std::numeric_limits< int >::max( ) );
346       v_uint->setMaximum( std::numeric_limits< int >::max( ) );
347       v_uint->setValue( v );
348       w_input = v_uint;
349     }
350     break;
351     case Parameters::Real:
352     {
353       std::istringstream tok_str( pIt->second.second );
354       double v;
355       tok_str >> v;
356       QDoubleSpinBox* v_double = new QDoubleSpinBox( this );
357       v_double->setObjectName( pIt->first.c_str( ) );
358       v_double->setDecimals( 3 );
359       v_double->setMinimum( -std::numeric_limits< double >::max( ) );
360       v_double->setMaximum(  std::numeric_limits< double >::max( ) );
361       v_double->setValue( v );
362       w_input = v_double;
363     }
364     break;
365     case Parameters::OpenFileName:
366     {
367       QFrame* frame = new QFrame( this );
368       QHBoxLayout* layout = new QHBoxLayout( frame );
369       QLineEdit* v_string = new QLineEdit( frame );
370       v_string->setObjectName( pIt->first.c_str( ) );
371       v_string->setText( pIt->second.second.c_str( ) );
372       QPushButton* v_button = new QPushButton( frame );
373       v_button->setObjectName( ( pIt->first + "_=?btn" ).c_str( ) );
374       v_button->setText( "..." );
375       v_button->connect(
376         v_button, SIGNAL( clicked( ) ),
377         this, SLOT( _dlg_OpenSingleFile( ) )
378         );
379       layout->addWidget( v_string );
380       layout->addWidget( v_button );
381       w_input = frame;
382     }
383     case Parameters::SaveFileName:
384     {
385       QFrame* frame = new QFrame( this );
386       QHBoxLayout* layout = new QHBoxLayout( frame );
387       QLineEdit* v_string = new QLineEdit( frame );
388       v_string->setObjectName( pIt->first.c_str( ) );
389       v_string->setText( pIt->second.second.c_str( ) );
390       QPushButton* v_button = new QPushButton( frame );
391       v_button->setObjectName( ( pIt->first + "_=?btn" ).c_str( ) );
392       v_button->setText( "..." );
393       v_button->connect(
394         v_button, SIGNAL( clicked( ) ),
395         this, SLOT( _dlg_SaveSingleFile( ) )
396         );
397       layout->addWidget( v_string );
398       layout->addWidget( v_button );
399       w_input = frame;
400     }
401     break;
402     case Parameters::PathName:
403     {
404       QFrame* frame = new QFrame( this );
405       QHBoxLayout* layout = new QHBoxLayout( frame );
406       QLineEdit* v_string = new QLineEdit( frame );
407       v_string->setObjectName( pIt->first.c_str( ) );
408       v_string->setText( pIt->second.second.c_str( ) );
409       QPushButton* v_button = new QPushButton( frame );
410       v_button->setObjectName( ( pIt->first + "_=?btn" ).c_str( ) );
411       v_button->setText( "..." );
412       v_button->connect(
413         v_button, SIGNAL( clicked( ) ),
414         this, SLOT( _dlg_OpenSinglePath( ) )
415         );
416       layout->addWidget( v_string );
417       layout->addWidget( v_button );
418       w_input = frame;
419     }
420     break;
421     case Parameters::StringList:
422       break;
423     case Parameters::BoolList:
424       break;
425     case Parameters::IntList:
426     {
427       QFrame* frame = new QFrame( this );
428       QHBoxLayout* layout = new QHBoxLayout( frame );
429       QLineEdit* v_string = new QLineEdit( frame );
430       v_string->setObjectName( pIt->first.c_str( ) );
431       v_string->setText( pIt->second.second.c_str( ) );
432       QPushButton* v_button = new QPushButton( frame );
433       v_button->setObjectName( ( pIt->first + "_=?btn" ).c_str( ) );
434       v_button->setText( "+" );
435       v_button->connect(
436         v_button, SIGNAL( clicked( ) ),
437         this, SLOT( _dlg_AddInt( ) )
438         );
439       layout->addWidget( v_string );
440       layout->addWidget( v_button );
441       w_input = frame;
442     }
443     break;
444     case Parameters::UintList:
445     {
446       QFrame* frame = new QFrame( this );
447       QHBoxLayout* layout = new QHBoxLayout( frame );
448       QLineEdit* v_string = new QLineEdit( frame );
449       v_string->setObjectName( pIt->first.c_str( ) );
450       v_string->setText( pIt->second.second.c_str( ) );
451       QPushButton* v_button = new QPushButton( frame );
452       v_button->setObjectName( ( pIt->first + "_=?btn" ).c_str( ) );
453       v_button->setText( "+" );
454       v_button->connect(
455         v_button, SIGNAL( clicked( ) ),
456         this, SLOT( _dlg_AddUint( ) )
457         );
458       layout->addWidget( v_string );
459       layout->addWidget( v_button );
460       w_input = frame;
461     }
462     break;
463     case Parameters::RealList:
464     {
465       QFrame* frame = new QFrame( this );
466       QHBoxLayout* layout = new QHBoxLayout( frame );
467       QLineEdit* v_string = new QLineEdit( frame );
468       v_string->setObjectName( pIt->first.c_str( ) );
469       v_string->setText( pIt->second.second.c_str( ) );
470       QPushButton* v_button = new QPushButton( frame );
471       v_button->setObjectName( ( pIt->first + "_=?btn" ).c_str( ) );
472       v_button->setText( "+" );
473       v_button->connect(
474         v_button, SIGNAL( clicked( ) ),
475         this, SLOT( _dlg_AddReal( ) )
476         );
477       layout->addWidget( v_string );
478       layout->addWidget( v_button );
479       w_input = frame;
480     }
481     break;
482     case Parameters::OpenFileNameList:
483     {
484       QFrame* frame = new QFrame( this );
485       QHBoxLayout* layout = new QHBoxLayout( frame );
486       QLineEdit* v_string = new QLineEdit( frame );
487       v_string->setObjectName( pIt->first.c_str( ) );
488       v_string->setMaxLength( std::numeric_limits< int >::max( ) );
489       v_string->setText( pIt->second.second.c_str( ) );
490       QPushButton* v_button = new QPushButton( frame );
491       v_button->setObjectName( ( pIt->first + "_=?btn" ).c_str( ) );
492       v_button->setText( "..." );
493       v_button->connect(
494         v_button, SIGNAL( clicked( ) ),
495         this, SLOT( _dlg_OpenMultipleFiles( ) )
496         );
497       layout->addWidget( v_string );
498       layout->addWidget( v_button );
499       w_input = frame;
500     }
501     break;
502     case Parameters::SaveFileNameList:
503       break;
504     case Parameters::PathNameList:
505       break;
506     case Parameters::Choices:
507     {
508       QComboBox* v_choices = new QComboBox( this );
509       v_choices->setObjectName( pIt->first.c_str( ) );
510
511       std::istringstream str0( pIt->second.second );
512       std::string choices;
513       std::getline( str0, choices, '@' );
514       std::istringstream str1( choices );
515       std::string token;
516       int id = 0;
517       while( std::getline( str1, token, '#' ) )
518         v_choices->insertItem( id++, token.c_str( ) );
519       w_input = v_choices;
520     }
521     break;
522     default:
523       w_input = NULL;
524       break;
525     } // hctiws
526
527     // Ok, a representation was created
528     if( w_input != NULL )
529     {
530       QHBoxLayout* new_layout = new QHBoxLayout( );
531       QLabel* label = new QLabel( this );
532       label->setText( QString( pIt->first.c_str( ) ) );
533       new_layout->addWidget( label );
534       new_layout->addWidget( w_input );
535       this->m_ToolsLayout->addLayout( new_layout );
536
537     } // fi
538
539   } // rof
540
541   // Update values
542   this->_addButtons( );
543 }
544
545 // -------------------------------------------------------------------------
546 void cpPlugins::ParametersQtDialog::
547 _dlg_OpenSingleFile( )
548 {
549   auto parameters = this->m_ProcessObject->GetParameters( );
550   QPushButton* btn = dynamic_cast< QPushButton* >( this->sender( ) );
551   if( btn != NULL )
552   {
553     std::string bName = btn->objectName( ).toStdString( );
554     std::string line_name = bName.substr( 0, bName.find( "_=?btn" ) );
555     QLineEdit* line = this->findChild< QLineEdit* >( line_name.c_str( ) );
556     if( line != NULL )
557     {
558       std::string param_name = line->objectName( ).toStdString( );
559       if( param_name != "" )
560       {
561         std::string param_value = parameters->GetOpenFileName( param_name );
562         if( param_value == "" )
563           param_value = ".";
564         QStringList dialog_filters;
565         std::string extensions = parameters->GetAcceptedFileExtensions( param_name );
566         if( extensions != "" )
567           dialog_filters << extensions.c_str( );
568         dialog_filters << "Any file (*)";
569
570         // Show dialog and check if it was accepted
571         QFileDialog dialog( this );
572         dialog.setFileMode( QFileDialog::ExistingFile );
573         dialog.setDirectory( QFileDialog::tr( param_value.c_str( ) ) );
574         dialog.setNameFilters( dialog_filters );
575         dialog.setAcceptMode( QFileDialog::AcceptOpen );
576         if( dialog.exec( ) )
577           line->setText( *( dialog.selectedFiles( ).begin( ) ) );
578
579       } // fi
580
581     } // fi
582
583   } // fi
584 }
585
586 // -------------------------------------------------------------------------
587 void cpPlugins::ParametersQtDialog::
588 _dlg_SaveSingleFile( )
589 {
590   auto parameters = this->m_ProcessObject->GetParameters( );
591   QPushButton* btn = dynamic_cast< QPushButton* >( this->sender( ) );
592   if( btn != NULL )
593   {
594     std::string bName = btn->objectName( ).toStdString( );
595     std::string line_name = bName.substr( 0, bName.find( "_=?btn" ) );
596     QLineEdit* line = this->findChild< QLineEdit* >( line_name.c_str( ) );
597     if( line != NULL )
598     {
599       std::string param_name = line->objectName( ).toStdString( );
600       if( param_name != "" )
601       {
602         std::string param_value = parameters->GetSaveFileName( param_name );
603         if( param_value == "" )
604           param_value = ".";
605         QStringList dialog_filters;
606         std::string extensions = 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::ParametersQtDialog::
629 _dlg_OpenSinglePath( )
630 {
631   auto parameters = this->m_ProcessObject->GetParameters( );
632   QPushButton* btn = dynamic_cast< QPushButton* >( this->sender( ) );
633   if( btn != NULL )
634   {
635     std::string bName = btn->objectName( ).toStdString( );
636     std::string line_name = bName.substr( 0, bName.find( "_=?btn" ) );
637     QLineEdit* line = this->findChild< QLineEdit* >( line_name.c_str( ) );
638     if( line != NULL )
639     {
640       std::string param_name = line->objectName( ).toStdString( );
641       if( param_name != "" )
642       {
643         std::string param_value = 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::ParametersQtDialog::
664 _dlg_OpenMultipleFiles( )
665 {
666   auto parameters = this->m_ProcessObject->GetParameters( );
667   QPushButton* btn = dynamic_cast< QPushButton* >( this->sender( ) );
668   if( btn != NULL )
669   {
670     std::string bName = btn->objectName( ).toStdString( );
671     std::string line_name = bName.substr( 0, bName.find( "_=?btn" ) );
672
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         QStringList dialog_filters;
680         std::string extensions = 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::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::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::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_QT4
857
858 // eof - $RCSfile$