[vlc-commits] qt4: preferences_widget: Use inheritance instead of switch.

Hugo Beauzée-Luyssen git at videolan.org
Fri Apr 22 16:27:38 CEST 2011


vlc | branch: master | Hugo Beauzée-Luyssen <beauze.h at gmail.com> | Fri Apr 22 16:15:24 2011 +0200| [d3f18b520be1facb50a3f23a0d0429e41a26e00f] | committer: Jean-Baptiste Kempf

qt4: preferences_widget: Use inheritance instead of switch.

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=d3f18b520be1facb50a3f23a0d0429e41a26e00f
---

 modules/gui/qt4/components/preferences_widgets.cpp |   57 +++++++-------------
 modules/gui/qt4/components/preferences_widgets.hpp |    7 ++-
 2 files changed, 24 insertions(+), 40 deletions(-)

diff --git a/modules/gui/qt4/components/preferences_widgets.cpp b/modules/gui/qt4/components/preferences_widgets.cpp
index cd85008..b343f9d 100644
--- a/modules/gui/qt4/components/preferences_widgets.cpp
+++ b/modules/gui/qt4/components/preferences_widgets.cpp
@@ -162,43 +162,6 @@ ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
     return p_control;
 }
 
-void ConfigControl::doApply( intf_thread_t *p_intf )
-{
-    switch( getType() )
-    {
-        case CONFIG_ITEM_INTEGER:
-        case CONFIG_ITEM_BOOL:
-        {
-            VIntConfigControl *vicc = qobject_cast<VIntConfigControl *>(this);
-            assert( vicc );
-            config_PutInt( p_intf, vicc->getName(), vicc->getValue() );
-            break;
-        }
-        case CONFIG_ITEM_FLOAT:
-        {
-            VFloatConfigControl *vfcc =
-                                    qobject_cast<VFloatConfigControl *>(this);
-            assert( vfcc );
-            config_PutFloat( p_intf, vfcc->getName(), vfcc->getValue() );
-            break;
-        }
-        case CONFIG_ITEM_STRING:
-        {
-            VStringConfigControl *vscc =
-                            qobject_cast<VStringConfigControl *>(this);
-            assert( vscc );
-            config_PutPsz( p_intf, vscc->getName(), qtu( vscc->getValue() ) );
-            break;
-        }
-        case CONFIG_ITEM_KEY:
-        {
-            KeySelectorControl *ksc = qobject_cast<KeySelectorControl *>(this);
-            assert( ksc );
-            ksc->doApply();
-        }
-    }
-}
-
 /*******************************************************
  * Simple widgets
  *******************************************************/
@@ -241,6 +204,12 @@ void InterfacePreviewWidget::setPreview( enum_style e_style )
  * String-based controls
  *************************************************************************/
 
+void
+VStringConfigControl::doApply( intf_thread_t *p_intf )
+{
+    config_PutPsz( p_intf, getName(), qtu( getValue() ) );
+}
+
 /*********** String **************/
 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
                                           module_config_t *_p_item,
@@ -844,6 +813,12 @@ void ModuleListConfigControl::onUpdate()
  * Integer-based controls
  *************************************************************************/
 
+void
+VIntConfigControl::doApply( intf_thread_t *p_intf )
+{
+    config_PutInt( p_intf, getName(), getValue() );
+}
+
 /*********** Integer **************/
 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
                                             module_config_t *_p_item,
@@ -1123,6 +1098,12 @@ int BoolConfigControl::getValue() const
  * Float-based controls
  *************************************************************************/
 
+void
+VFloatConfigControl::doApply( intf_thread_t *p_intf )
+{
+    config_PutFloat( p_intf, getName(), getValue() );
+}
+
 /*********** Float **************/
 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
                                         module_config_t *_p_item,
@@ -1416,7 +1397,7 @@ void KeySelectorControl::setTheKey()
                                    Qt::UserRole, shortcutValue->getValue() );
 }
 
-void KeySelectorControl::doApply()
+void KeySelectorControl::doApply( intf_thread_t* )
 {
     QTreeWidgetItem *it;
     for( int i = 0; i < table->topLevelItemCount() ; i++ )
diff --git a/modules/gui/qt4/components/preferences_widgets.hpp b/modules/gui/qt4/components/preferences_widgets.hpp
index 7b4230c..0dd97c5 100644
--- a/modules/gui/qt4/components/preferences_widgets.hpp
+++ b/modules/gui/qt4/components/preferences_widgets.hpp
@@ -101,7 +101,7 @@ public:
     static ConfigControl * createControl( vlc_object_t*,
                                           module_config_t*,QWidget*,
                                           QGridLayout *, int& );
-    void doApply( intf_thread_t *);
+    virtual void doApply( intf_thread_t *) = 0;
 protected:
     vlc_object_t *p_this;
     module_config_t *p_item;
@@ -127,6 +127,7 @@ public:
                 ConfigControl(a,b) {};
     virtual int getValue() const = 0;
     virtual int getType() const { return CONFIG_ITEM_INTEGER; }
+    virtual void doApply( intf_thread_t *);
 };
 
 class IntegerConfigControl : public VIntConfigControl
@@ -223,6 +224,7 @@ public:
                 ConfigControl(a,b) {};
     virtual float getValue() const = 0;
     virtual int getType() const { return CONFIG_ITEM_FLOAT; }
+    virtual void doApply( intf_thread_t *);
 };
 
 class FloatConfigControl : public VFloatConfigControl
@@ -270,6 +272,7 @@ public:
                 ConfigControl(a,b) {};
     virtual QString getValue() const = 0;
     virtual int getType() const { return CONFIG_ITEM_STRING; }
+    virtual void doApply( intf_thread_t *);
 };
 
 class StringConfigControl : public VStringConfigControl
@@ -454,7 +457,7 @@ public:
     virtual int getType() const { return CONFIG_ITEM_KEY; }
     virtual void hide() { table->hide(); if( label ) label->hide(); }
     virtual void show() { table->show(); if( label ) label->show(); }
-    void doApply();
+    virtual void doApply( intf_thread_t *);
 private:
     void finish();
     QLabel *label;



More information about the vlc-commits mailing list