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