[opengtl-commits] [627] move the marshaling of value to widgets in the proxy

[ Thread Index | Date Index | More lists.tuxfamily.org/opengtl-commits Archives ]


Revision: 627
Author:   cyrille
Date:     2009-03-15 13:15:24 +0100 (Sun, 15 Mar 2009)

Log Message:
-----------
move the marshaling of value to widgets in the proxy

Modified Paths:
--------------
    trunk/libQtGTL/QtShiva/ColorButton_p.h
    trunk/libQtGTL/QtShiva/ParametersWidgetBase.cpp
    trunk/libQtGTL/QtShiva/ParametersWidgetBase.h
    trunk/libQtGTL/QtShiva/ParametersWidgetBase_p.cpp
    trunk/libQtGTL/QtShiva/Proxy_p.cpp
    trunk/libQtGTL/QtShiva/Proxy_p.h
    trunk/libQtGTL/QtShiva/SourceParametersWidget.cpp
    trunk/libQtGTL/QtShiva/SourceParametersWidget.h


Modified: trunk/libQtGTL/QtShiva/ColorButton_p.h
===================================================================
--- trunk/libQtGTL/QtShiva/ColorButton_p.h	2009-03-14 22:00:15 UTC (rev 626)
+++ trunk/libQtGTL/QtShiva/ColorButton_p.h	2009-03-15 12:15:24 UTC (rev 627)
@@ -32,10 +32,11 @@
     public:
       ColorButton( QWidget* _parent, bool _showAlpha );
       ~ColorButton();
-      void setCurrentColor( const QColor& _color );
       const QColor& currentColor() const;
     signals:
       void colorChanged( const QColor& );
+    public slots:
+      void setCurrentColor( const QColor& _color );
     private slots:
       void activated();
     private:

Modified: trunk/libQtGTL/QtShiva/ParametersWidgetBase.cpp
===================================================================
--- trunk/libQtGTL/QtShiva/ParametersWidgetBase.cpp	2009-03-14 22:00:15 UTC (rev 626)
+++ trunk/libQtGTL/QtShiva/ParametersWidgetBase.cpp	2009-03-15 12:15:24 UTC (rev 627)
@@ -38,6 +38,11 @@
   delete d;
 }
 
+void ParametersWidgetBase::setParameter(const GTLCore::String& _name, const GTLCore::Value& _value)
+{
+  Q_ASSERT(false);
+}
+
 void ParametersWidgetBase::setParametrisation( Parametrisation* _parametrisation)
 {
   delete d->parametrisation;

Modified: trunk/libQtGTL/QtShiva/ParametersWidgetBase.h
===================================================================
--- trunk/libQtGTL/QtShiva/ParametersWidgetBase.h	2009-03-14 22:00:15 UTC (rev 626)
+++ trunk/libQtGTL/QtShiva/ParametersWidgetBase.h	2009-03-15 12:15:24 UTC (rev 627)
@@ -22,12 +22,19 @@
 
 #include <QWidget>
 
+namespace GTLCore {
+  class String;
+  class Value;
+};
+
 namespace QtShiva {
   class ParametersWidgetBase : public QWidget {
     Q_OBJECT
     public:
       ParametersWidgetBase( QWidget* );
       ~ParametersWidgetBase();
+    public:
+      void setParameter(const GTLCore::String& _name, const GTLCore::Value& _value);
     signals:
       void configurationChanged();
     public:

Modified: trunk/libQtGTL/QtShiva/ParametersWidgetBase_p.cpp
===================================================================
--- trunk/libQtGTL/QtShiva/ParametersWidgetBase_p.cpp	2009-03-14 22:00:15 UTC (rev 626)
+++ trunk/libQtGTL/QtShiva/ParametersWidgetBase_p.cpp	2009-03-15 12:15:24 UTC (rev 627)
@@ -113,7 +113,7 @@
   QString caption = ( ( _parameterEntry->label() == "" ) ? _parameterEntry->name() : _parameterEntry->label() ).c_str();
   QLabel* label = new QLabel( caption + ":", _parent);
   _gridLayout->addWidget(label, _layoutIndex, 0, 1, 1);
-  Proxy* proxy = new Proxy( _parent, _parameterEntry->name(), parametrisation );
+  Proxy* proxy = new Proxy( _parent, _parameterEntry->name(), parametrisation, _parameterEntry->widgetType() );
   switch( _parameterEntry->widgetType() )
   {
     case GTLCore::Metadata::ParameterEntry::IntegerWidget:
@@ -132,16 +132,15 @@
       connect( spinBox, SIGNAL(valueChanged(int)), self, SIGNAL(configurationChanged()));
       
       connect( spinBox, SIGNAL(valueChanged(int)), proxy, SLOT(setIntValue(int)));
+      connect( proxy, SIGNAL(intValueChanged(int)), spinBox, SLOT(setValue(int)));
       
       int min = _parameterEntry->minimumValue().asInt32();
       int max = _parameterEntry->maximumValue().asInt32();
-      int val = _parameterEntry->defaultValue().asInt32();
+      
       spinBox->setMinimum( min );
       spinBox->setMaximum( max );
-      spinBox->setValue( val );
       horizontalSlider->setMinimum( min );
       horizontalSlider->setMaximum( max );
-      horizontalSlider->setValue( val );
     }
       break;
     case GTLCore::Metadata::ParameterEntry::FloatWidget:
@@ -162,11 +161,11 @@
       SpinBoxSliderConnector* connector = new SpinBoxSliderConnector( _parent, doubleSpinBox, horizontalSlider);
       connect( connector, SIGNAL(valueChanged(double)), self, SIGNAL(configurationChanged()));
       connect( connector, SIGNAL(valueChanged(double)), proxy, SLOT(setDoubleValue(double)));
+      connect( proxy, SIGNAL(intValueChanged(int)), doubleSpinBox, SLOT(setValue(double)));
       
       // Set parameters
       doubleSpinBox->setMinimum( _parameterEntry->minimumValue().asFloat() );
       doubleSpinBox->setMaximum( _parameterEntry->maximumValue().asFloat() );
-      doubleSpinBox->setValue( _parameterEntry->defaultValue().asFloat() );
     }
       break;
     case GTLCore::Metadata::ParameterEntry::CurveWidget:
@@ -175,33 +174,21 @@
     case GTLCore::Metadata::ParameterEntry::RgbColorWidget:
     {
       ColorButton* colorButton = new ColorButton( _parent, false );
-      const std::vector< GTLCore::Value >* valArr = _parameterEntry->defaultValue().asArray();
-      Q_ASSERT( valArr );
-      Q_ASSERT( valArr->size() >= 3 );
-      double r = (*valArr)[0].asFloat() * 255;
-      double g = (*valArr)[1].asFloat() * 255;
-      double b = (*valArr)[2].asFloat() * 255;
-      colorButton->setCurrentColor( QColor(r,g,b ) );
       _gridLayout->addWidget(colorButton, _layoutIndex, 1, 1, 1);
       connect( colorButton, SIGNAL(colorChanged(const QColor&)), proxy, SLOT(setRgb(const QColor&)));
+      connect( proxy, SIGNAL(rgbValueChanged(QColor)), colorButton, SLOT(setCurrentColor(QColor)));
     }
       break;
     case GTLCore::Metadata::ParameterEntry::RgbaColorWidget:
     {
       ColorButton* colorButton = new ColorButton( _parent, true );
-      const std::vector< GTLCore::Value >* valArr = _parameterEntry->defaultValue().asArray();
-      Q_ASSERT( valArr );
-      Q_ASSERT( valArr->size() >= 3 );
-      double r = (*valArr)[0].asFloat() * 255;
-      double g = (*valArr)[1].asFloat() * 255;
-      double b = (*valArr)[2].asFloat() * 255;
-      double a = (*valArr)[3].asFloat() * 255;
-      colorButton->setCurrentColor( QColor(r,g,b, a ) );
       _gridLayout->addWidget(colorButton, _layoutIndex, 1, 1, 1);
       connect( colorButton, SIGNAL(colorChanged(const QColor&)), proxy, SLOT(setRgba(const QColor&)));
+      connect( proxy, SIGNAL(rgbaValueChanged(QColor)), colorButton, SLOT(setCurrentColor(QColor)));
     }
       break;
   }
+  proxy->setValue(_parameterEntry->defaultValue());
 }
 
 #include "ParametersWidgetBase_p.moc"

Modified: trunk/libQtGTL/QtShiva/Proxy_p.cpp
===================================================================
--- trunk/libQtGTL/QtShiva/Proxy_p.cpp	2009-03-14 22:00:15 UTC (rev 626)
+++ trunk/libQtGTL/QtShiva/Proxy_p.cpp	2009-03-15 12:15:24 UTC (rev 627)
@@ -31,7 +31,7 @@
 
 using namespace QtShiva;
 
-Proxy::Proxy( QObject* parent, const GTLCore::String& _name, ParametersWidgetBase::Parametrisation* _kernel ) : QObject( parent ), m_name(_name), m_kernel( _kernel )
+Proxy::Proxy( QObject* parent, const GTLCore::String& _name, ParametersWidgetBase::Parametrisation* _kernel, GTLCore::Metadata::ParameterEntry::WidgetType _type ) : QObject( parent ), m_name(_name), m_kernel( _kernel ), m_type(_type)
 {
   
 }
@@ -70,4 +70,47 @@
   m_kernel->setParameter( m_name, GTLCore::Value( cv, GTLCore::TypesManager::getVector( GTLCore::Type::Float, 4 ) ) );
 }
 
+void Proxy::setValue( const GTLCore::Value& value)
+{
+  switch( m_type )
+  {
+    case GTLCore::Metadata::ParameterEntry::IntegerWidget:
+    {
+      emit intValueChanged( value.asInt32() );
+    }
+      break;
+    case GTLCore::Metadata::ParameterEntry::FloatWidget:
+    {
+      emit doubleValueChanged(value.asFloat());
+    }
+      break;
+    case GTLCore::Metadata::ParameterEntry::CurveWidget:
+      
+      break;
+    case GTLCore::Metadata::ParameterEntry::RgbColorWidget:
+    {
+      const std::vector< GTLCore::Value >* valArr = value.asArray();
+      Q_ASSERT( valArr );
+      Q_ASSERT( valArr->size() >= 3 );
+      double r = (*valArr)[0].asFloat() * 255;
+      double g = (*valArr)[1].asFloat() * 255;
+      double b = (*valArr)[2].asFloat() * 255;
+      emit( rgbValueChanged(QColor(r,g,b)) );
+    }
+      break;
+    case GTLCore::Metadata::ParameterEntry::RgbaColorWidget:
+    {
+      const std::vector< GTLCore::Value >* valArr = value.asArray();
+      Q_ASSERT( valArr );
+      Q_ASSERT( valArr->size() >= 3 );
+      double r = (*valArr)[0].asFloat() * 255;
+      double g = (*valArr)[1].asFloat() * 255;
+      double b = (*valArr)[2].asFloat() * 255;
+      double a = (*valArr)[3].asFloat() * 255;
+      emit( rgbaValueChanged(QColor(r,g,b,a)) );
+    }
+      break;
+  }
+}
+
 #include "Proxy_p.moc"

Modified: trunk/libQtGTL/QtShiva/Proxy_p.h
===================================================================
--- trunk/libQtGTL/QtShiva/Proxy_p.h	2009-03-14 22:00:15 UTC (rev 626)
+++ trunk/libQtGTL/QtShiva/Proxy_p.h	2009-03-15 12:15:24 UTC (rev 627)
@@ -25,6 +25,8 @@
 
 #include "ParametersWidgetBase.h"
 
+#include <GTLCore/Metadata/ParameterEntry.h>
+
 namespace OpenShiva {
   class Kernel;
 }
@@ -35,16 +37,24 @@
   class Proxy : public QObject {
     Q_OBJECT
     public:
-      Proxy( QObject* parent, const GTLCore::String& _name, ParametersWidgetBase::Parametrisation* _kernel );
+      Proxy( QObject* parent, const GTLCore::String& _name, ParametersWidgetBase::Parametrisation* _kernel, GTLCore::Metadata::ParameterEntry::WidgetType _type );
       ~Proxy();
     public slots:
       void setIntValue( int );
       void setDoubleValue( double );
       void setRgb( const QColor& );
       void setRgba( const QColor& );
+    public:
+      void setValue( const GTLCore::Value& value);
+    signals:
+      void intValueChanged( int );
+      void doubleValueChanged( double );
+      void rgbValueChanged( const QColor& );
+      void rgbaValueChanged( const QColor& );
     private:
       GTLCore::String m_name;
       ParametersWidgetBase::Parametrisation* m_kernel;
+      GTLCore::Metadata::ParameterEntry::WidgetType m_type;
   };
 }
 

Modified: trunk/libQtGTL/QtShiva/SourceParametersWidget.cpp
===================================================================
--- trunk/libQtGTL/QtShiva/SourceParametersWidget.cpp	2009-03-14 22:00:15 UTC (rev 626)
+++ trunk/libQtGTL/QtShiva/SourceParametersWidget.cpp	2009-03-15 12:15:24 UTC (rev 627)
@@ -33,10 +33,10 @@
     virtual const GTLCore::Metadata::Group* parameters() const;
     virtual const GTLCore::String& name() const;
     virtual void setParameter( const GTLCore::String& _name, GTLCore::Value );
-    void setSource( OpenShiva::Source* _kernel );
+    void setSource( const OpenShiva::Source* _kernel );
     const std::map< GTLCore::String, GTLCore::Value>& parametersMap() const;
   private:
-    OpenShiva::Source* m_source;
+    const OpenShiva::Source* m_source;
     std::map< GTLCore::String, GTLCore::Value> m_parameters;
 };
 
@@ -61,7 +61,7 @@
   m_parameters[_name] = _value;
 }
 
-void SourceParametersWidget::SourceParametrisation::setSource( OpenShiva::Source* _source )
+void SourceParametersWidget::SourceParametrisation::setSource( const OpenShiva::Source* _source )
 {
   m_source = _source;
   p->regenerateWidget();
@@ -89,7 +89,7 @@
   delete d;
 }
 
-void SourceParametersWidget::setSource( OpenShiva::Source* _source )
+void SourceParametersWidget::setSource( const OpenShiva::Source* _source )
 {
   d->parametrisation->setSource(_source);
 }

Modified: trunk/libQtGTL/QtShiva/SourceParametersWidget.h
===================================================================
--- trunk/libQtGTL/QtShiva/SourceParametersWidget.h	2009-03-14 22:00:15 UTC (rev 626)
+++ trunk/libQtGTL/QtShiva/SourceParametersWidget.h	2009-03-15 12:15:24 UTC (rev 627)
@@ -39,7 +39,7 @@
     public:
       SourceParametersWidget( QWidget* );
       ~SourceParametersWidget();
-      void setSource( OpenShiva::Source* );
+      void setSource( const OpenShiva::Source* );
       const std::map< GTLCore::String, GTLCore::Value>& parameters() const;
     private:
       struct Private;


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/