[vlmc-devel] commit: EffectStack: Don' t recreate widget each time the selected effect changes. ( Hugo Beauzée-Luyssen )

git at videolan.org git at videolan.org
Sat Sep 4 19:05:43 CEST 2010


vlmc | branch: master | Hugo Beauzée-Luyssen <beauze.h at gmail.com> | Sat Sep  4 18:25:08 2010 +0200| [40307710b519f8de7fa71629b446c349c1cf7d1c] | committer: Hugo Beauzée-Luyssen 

EffectStack: Don't recreate widget each time the selected effect changes.

> http://git.videolan.org/gitweb.cgi/vlmc.git/?a=commit;h=40307710b519f8de7fa71629b446c349c1cf7d1c
---

 src/Gui/effectsengine/EffectInstanceListModel.cpp |    9 +++---
 src/Gui/effectsengine/EffectInstanceListModel.h   |    2 +-
 src/Gui/effectsengine/EffectStack.cpp             |   28 ++++++++++++++++++--
 src/Gui/effectsengine/EffectStack.h               |    9 ++++++
 src/Gui/effectsengine/ui/EffectStack.ui           |   11 --------
 5 files changed, 40 insertions(+), 19 deletions(-)

diff --git a/src/Gui/effectsengine/EffectInstanceListModel.cpp b/src/Gui/effectsengine/EffectInstanceListModel.cpp
index 83ca865..fba1753 100644
--- a/src/Gui/effectsengine/EffectInstanceListModel.cpp
+++ b/src/Gui/effectsengine/EffectInstanceListModel.cpp
@@ -93,15 +93,16 @@ EffectInstanceListModel::moveDown( const QModelIndex &index )
     emit layoutChanged();
 }
 
-void
+EffectsEngine::EffectHelper*
 EffectInstanceListModel::add( const QString &effectName )
 {
     if ( effectName.isEmpty() == true )
-        return ;
+        return NULL;
     Effect  *effect = EffectsEngine::getInstance()->effect( effectName );
     if ( effect == NULL )
-        return ;
+        return NULL;
     beginInsertRows( QModelIndex(), m_user->count( Effect::Filter ), m_user->count( Effect::Filter ) );
-    m_user->addEffect( effect );
+    EffectsEngine::EffectHelper    *helper = m_user->addEffect( effect );
     endInsertRows();
+    return helper;
 }
diff --git a/src/Gui/effectsengine/EffectInstanceListModel.h b/src/Gui/effectsengine/EffectInstanceListModel.h
index 363b5c7..e5f8456 100644
--- a/src/Gui/effectsengine/EffectInstanceListModel.h
+++ b/src/Gui/effectsengine/EffectInstanceListModel.h
@@ -38,7 +38,7 @@ class EffectInstanceListModel : public QAbstractListModel
         virtual bool        removeRows( int row, int count, const QModelIndex &parent = QModelIndex() );
         void                moveUp( const QModelIndex &index );
         void                moveDown( const QModelIndex &index );
-        void                add( const QString &effectName );
+        EffectsEngine::EffectHelper*    add( const QString &effectName );
 
     private:
         EffectUser          *m_user;
diff --git a/src/Gui/effectsengine/EffectStack.cpp b/src/Gui/effectsengine/EffectStack.cpp
index 0f64b64..9a82fea 100644
--- a/src/Gui/effectsengine/EffectStack.cpp
+++ b/src/Gui/effectsengine/EffectStack.cpp
@@ -22,9 +22,13 @@
 
 #include "EffectStack.h"
 #include "ui_EffectStack.h"
-
+#include "EffectInstance.h"
+#include "EffectInstanceWidget.h"
+#include "EffectUser.h"
 #include "EffectInstanceListModel.h"
 
+#include <QStackedLayout>
+
 EffectStack::EffectStack( EffectUser *user, QWidget *parent ):
     QDialog( parent ),
     m_ui( new Ui::EffectStack ),
@@ -42,6 +46,13 @@ EffectStack::EffectStack( EffectUser *user, QWidget *parent ):
     connect( m_ui->addButton, SIGNAL( clicked() ), this, SLOT( add() ) );
 
     m_ui->addComboBox->addItems( EffectsEngine::getInstance()->effects( Effect::Filter ) );
+    m_stackedLayout = new QStackedLayout;
+    m_ui->horizontalLayout->addLayout( m_stackedLayout );
+    //Add an empty instance widget.
+    m_stackedLayout->addWidget( new EffectInstanceWidget( this ) );
+    //Create instance widgets for already inserted effects
+    foreach ( EffectsEngine::EffectHelper *helper, user->effects( Effect::Filter ) )
+        addInstanceWidget( helper->effect );
 }
 
 EffectStack::~EffectStack()
@@ -51,9 +62,19 @@ EffectStack::~EffectStack()
 }
 
 void
+EffectStack::addInstanceWidget( EffectInstance *instance )
+{
+    EffectInstanceWidget    *w = new EffectInstanceWidget( this );
+    w->setEffectInstance( instance );
+    m_stackedLayout->addWidget( w );
+    m_instanceWidgets[instance->effect()->name()] = w;
+}
+
+void
 EffectStack::selectedChanged( const QModelIndex &index )
 {
-    m_ui->instanceWidget->setEffectInstance( m_model->data( index, Qt::EditRole ).value<EffectsEngine::EffectHelper*>()->effect );
+    EffectInstance  *inst = m_model->data( index, Qt::EditRole ).value<EffectsEngine::EffectHelper*>()->effect;
+    m_stackedLayout->setCurrentWidget( m_instanceWidgets[inst->effect()->name()] );
 }
 
 void
@@ -81,5 +102,6 @@ EffectStack::remove()
 void
 EffectStack::add()
 {
-    m_model->add( m_ui->addComboBox->currentText() );
+    EffectsEngine::EffectHelper *helper = m_model->add( m_ui->addComboBox->currentText() );
+    addInstanceWidget( helper->effect );
 }
diff --git a/src/Gui/effectsengine/EffectStack.h b/src/Gui/effectsengine/EffectStack.h
index 6be236a..6c74442 100644
--- a/src/Gui/effectsengine/EffectStack.h
+++ b/src/Gui/effectsengine/EffectStack.h
@@ -29,7 +29,11 @@ class   EffectUser;
 
 #include <QStandardItemModel>
 
+class   EffectInstance;
 class   EffectInstanceListModel;
+class   EffectInstanceWidget;
+
+class   QStackedLayout;
 
 namespace Ui
 {
@@ -44,6 +48,9 @@ class EffectStack : public QDialog
         explicit EffectStack( EffectUser *user, QWidget *parent = 0 );
         ~EffectStack();
 
+    private:
+        void        addInstanceWidget( EffectInstance *instance );
+
     private slots:
         void        selectedChanged( const QModelIndex &index );
         void        moveUp();
@@ -55,6 +62,8 @@ class EffectStack : public QDialog
         Ui::EffectStack                 *m_ui;
         EffectInstanceListModel         *m_model;
         EffectUser                      *m_user;
+        QStackedLayout                  *m_stackedLayout;
+        QHash<QString, EffectInstanceWidget*>   m_instanceWidgets;
 };
 
 #endif // EFFECTSTACK_H
diff --git a/src/Gui/effectsengine/ui/EffectStack.ui b/src/Gui/effectsengine/ui/EffectStack.ui
index dfa5551..417d7ef 100644
--- a/src/Gui/effectsengine/ui/EffectStack.ui
+++ b/src/Gui/effectsengine/ui/EffectStack.ui
@@ -120,9 +120,6 @@
        </item>
       </layout>
      </item>
-     <item>
-      <widget class="EffectInstanceWidget" name="instanceWidget" native="true"/>
-     </item>
     </layout>
    </item>
    <item>
@@ -137,14 +134,6 @@
    </item>
   </layout>
  </widget>
- <customwidgets>
-  <customwidget>
-   <class>EffectInstanceWidget</class>
-   <extends>QWidget</extends>
-   <header>EffectInstanceWidget.h</header>
-   <container>1</container>
-  </customwidget>
- </customwidgets>
  <resources>
   <include location="../../../../resources.qrc"/>
  </resources>



More information about the Vlmc-devel mailing list