]> Creatis software - cpPlugins.git/blobdiff - lib/cpPlugins/Interface/ParametersQtDialog.cxx
...
[cpPlugins.git] / lib / cpPlugins / Interface / ParametersQtDialog.cxx
index 3df62ee731aa417a959b043eafebffde64ad42e9..0c3d4377151a8e1c97012442ac66fb5ef0b8521e 100644 (file)
@@ -5,11 +5,13 @@
 #include <limits>
 
 #include <cpPlugins/Interface/ParametersListWidget.h>
+#include <cpPlugins/Interface/ProcessObject.h>
 
 #include <vtkCommand.h>
 #include <vtkRenderWindowInteractor.h>
 
 #include <QCheckBox>
+#include <QComboBox>
 #include <QDoubleSpinBox>
 #include <QFileDialog>
 #include <QHBoxLayout>
 #include <QPushButton>
 #include <QWidget>
 
-// -------------------------------------------------------------------------
-#include <cpPlugins/Interface/ProcessObject.h>
-#include <cpPlugins/Interface/Plugins.h>
-#include <cpPlugins/Interface/BaseApplication.h>
-
+/* TODO
 class SingleSeedCommand
   : public vtkCommand
 {
@@ -86,12 +84,14 @@ public:
   cpPlugins::Interface::ParametersQtDialog* Dialog;
   std::string Name;
 };
+*/
 
 // -------------------------------------------------------------------------
 cpPlugins::Interface::ParametersQtDialog::
 ParametersQtDialog( QWidget* parent, Qt::WindowFlags f )
   : QDialog( parent, f ),
-    m_Parameters( NULL )
+    m_Parameters( NULL ),
+    m_Interactive( false )
 {
   this->m_Title = new QLabel( this );
   this->m_Title->setText( "Parameters dialog title" );
@@ -142,6 +142,34 @@ getInteractors( ) const
   return( this->m_Interactors );
 }
 
+// -------------------------------------------------------------------------
+bool cpPlugins::Interface::ParametersQtDialog::
+isInteractive( ) const
+{
+  return( this->m_Interactive );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::ParametersQtDialog::
+setInteractive( bool i )
+{
+  this->m_Interactive = i;
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::ParametersQtDialog::
+interactiveOn( )
+{
+  this->m_Interactive = true;
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::ParametersQtDialog::
+interactiveOff( )
+{
+  this->m_Interactive = false;
+}
+
 // -------------------------------------------------------------------------
 bool cpPlugins::Interface::ParametersQtDialog::
 setParameters( Parameters* parameters )
@@ -157,6 +185,7 @@ setParameters( Parameters* parameters )
   this->m_Title->setText( title.str( ).c_str( ) );
 
   // Put values
+  this->m_Widgets.clear( );
   auto& raw_params = this->m_Parameters->GetRawParameters( );
   for( auto pIt = raw_params.begin( ); pIt != raw_params.end( ); ++pIt )
   {
@@ -211,12 +240,6 @@ setParameters( Parameters* parameters )
       w_input = v_double;
     }
     break;
-    case Parameters::Index:
-      break;
-    case Parameters::Point:
-      break;
-    case Parameters::Vector:
-      break;
     case Parameters::OpenFileName:
     {
       QFrame* frame = new QFrame( this );
@@ -334,12 +357,6 @@ setParameters( Parameters* parameters )
       w_input = frame;
     }
     break;
-    case Parameters::IndexList:
-      break;
-    case Parameters::PointList:
-      break;
-    case Parameters::VectorList:
-      break;
     case Parameters::OpenFileNameList:
     {
       QFrame* frame = new QFrame( this );
@@ -364,7 +381,21 @@ setParameters( Parameters* parameters )
     case Parameters::PathNameList:
       break;
     case Parameters::Choices:
-      break;
+    {
+      QComboBox* v_choices = new QComboBox( this );
+      v_choices->setObjectName( pIt->first.c_str( ) );
+
+      std::istringstream str0( pIt->second.second );
+      std::string choices;
+      std::getline( str0, choices, '@' );
+      std::istringstream str1( choices );
+      std::string token;
+      int id = 0;
+      while( std::getline( str1, token, '#' ) )
+        v_choices->insertItem( id++, token.c_str( ) );
+      w_input = v_choices;
+    }
+    break;
     default:
       w_input = NULL;
       break;
@@ -396,6 +427,9 @@ setParameters( Parameters* parameters )
     );
   this->m_ToolsLayout->addWidget( this->m_Buttons );
 
+  // Update values
+  this->updateView( );
+
   return( true );
 }
 
@@ -478,28 +512,29 @@ updateParameters( )
       } // fi
     }
     break;
-    case Parameters::Index:
-      break;
-    case Parameters::Point:
-      break;
-    case Parameters::Vector:
-      break;
     case Parameters::StringList:
       break;
     case Parameters::BoolList:
       break;
-    case Parameters::IndexList:
-      break;
-    case Parameters::PointList:
-      break;
-    case Parameters::VectorList:
-      break;
     case Parameters::SaveFileNameList:
       break;
     case Parameters::PathNameList:
       break;
     case Parameters::Choices:
-      break;
+    {
+      QComboBox* v_choices = this->findChild< QComboBox* >( pName );
+      if( v_choices != NULL )
+      {
+        std::istringstream str_choices( pIt->second.second );
+        std::string real_choices;
+        std::getline( str_choices, real_choices, '@' );
+        pIt->second.second =
+          real_choices + "@" +
+          v_choices->currentText( ).toStdString( );
+
+      } // fi
+    }
+    break;
     default:
       break;
     } // hctiws
@@ -569,28 +604,40 @@ updateView( )
       } // fi
     }
     break;
-    case Parameters::Index:
-      break;
-    case Parameters::Point:
-      break;
-    case Parameters::Vector:
-      break;
     case Parameters::StringList:
       break;
     case Parameters::BoolList:
       break;
-    case Parameters::IndexList:
-      break;
-    case Parameters::PointList:
-      break;
-    case Parameters::VectorList:
-      break;
     case Parameters::SaveFileNameList:
       break;
     case Parameters::PathNameList:
       break;
     case Parameters::Choices:
-      break;
+    {
+      QComboBox* v_choices = this->findChild< QComboBox* >( pName );
+      if( v_choices != NULL )
+      {
+        std::istringstream str_choices( pIt->second.second );
+        std::string choices, real_choice;
+        std::getline( str_choices, choices, '@' );
+        std::getline( str_choices, real_choice, '@' );
+        std::istringstream str( choices );
+        std::string token;
+        int id = -1, cont = 0;
+        while( std::getline( str, token, '#' ) )
+        {
+          if( token == real_choice )
+            id = cont;
+          cont++;
+
+        } // elihw
+
+        if( id > -1 )
+          v_choices->setCurrentIndex( id );
+
+      } // fi
+    }
+    break;
     default:
       break;
     } // hctiws