Commit 40307710 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

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

parent f5adb7b4
...@@ -93,15 +93,16 @@ EffectInstanceListModel::moveDown( const QModelIndex &index ) ...@@ -93,15 +93,16 @@ EffectInstanceListModel::moveDown( const QModelIndex &index )
emit layoutChanged(); emit layoutChanged();
} }
void EffectsEngine::EffectHelper*
EffectInstanceListModel::add( const QString &effectName ) EffectInstanceListModel::add( const QString &effectName )
{ {
if ( effectName.isEmpty() == true ) if ( effectName.isEmpty() == true )
return ; return NULL;
Effect *effect = EffectsEngine::getInstance()->effect( effectName ); Effect *effect = EffectsEngine::getInstance()->effect( effectName );
if ( effect == NULL ) if ( effect == NULL )
return ; return NULL;
beginInsertRows( QModelIndex(), m_user->count( Effect::Filter ), m_user->count( Effect::Filter ) ); beginInsertRows( QModelIndex(), m_user->count( Effect::Filter ), m_user->count( Effect::Filter ) );
m_user->addEffect( effect ); EffectsEngine::EffectHelper *helper = m_user->addEffect( effect );
endInsertRows(); endInsertRows();
return helper;
} }
...@@ -38,7 +38,7 @@ class EffectInstanceListModel : public QAbstractListModel ...@@ -38,7 +38,7 @@ class EffectInstanceListModel : public QAbstractListModel
virtual bool removeRows( int row, int count, const QModelIndex &parent = QModelIndex() ); virtual bool removeRows( int row, int count, const QModelIndex &parent = QModelIndex() );
void moveUp( const QModelIndex &index ); void moveUp( const QModelIndex &index );
void moveDown( const QModelIndex &index ); void moveDown( const QModelIndex &index );
void add( const QString &effectName ); EffectsEngine::EffectHelper* add( const QString &effectName );
private: private:
EffectUser *m_user; EffectUser *m_user;
......
...@@ -22,9 +22,13 @@ ...@@ -22,9 +22,13 @@
#include "EffectStack.h" #include "EffectStack.h"
#include "ui_EffectStack.h" #include "ui_EffectStack.h"
#include "EffectInstance.h"
#include "EffectInstanceWidget.h"
#include "EffectUser.h"
#include "EffectInstanceListModel.h" #include "EffectInstanceListModel.h"
#include <QStackedLayout>
EffectStack::EffectStack( EffectUser *user, QWidget *parent ): EffectStack::EffectStack( EffectUser *user, QWidget *parent ):
QDialog( parent ), QDialog( parent ),
m_ui( new Ui::EffectStack ), m_ui( new Ui::EffectStack ),
...@@ -42,6 +46,13 @@ EffectStack::EffectStack( EffectUser *user, QWidget *parent ): ...@@ -42,6 +46,13 @@ EffectStack::EffectStack( EffectUser *user, QWidget *parent ):
connect( m_ui->addButton, SIGNAL( clicked() ), this, SLOT( add() ) ); connect( m_ui->addButton, SIGNAL( clicked() ), this, SLOT( add() ) );
m_ui->addComboBox->addItems( EffectsEngine::getInstance()->effects( Effect::Filter ) ); 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() EffectStack::~EffectStack()
...@@ -50,10 +61,20 @@ EffectStack::~EffectStack() ...@@ -50,10 +61,20 @@ EffectStack::~EffectStack()
delete m_ui; delete m_ui;
} }
void
EffectStack::addInstanceWidget( EffectInstance *instance )
{
EffectInstanceWidget *w = new EffectInstanceWidget( this );
w->setEffectInstance( instance );
m_stackedLayout->addWidget( w );
m_instanceWidgets[instance->effect()->name()] = w;
}
void void
EffectStack::selectedChanged( const QModelIndex &index ) 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 void
...@@ -81,5 +102,6 @@ EffectStack::remove() ...@@ -81,5 +102,6 @@ EffectStack::remove()
void void
EffectStack::add() EffectStack::add()
{ {
m_model->add( m_ui->addComboBox->currentText() ); EffectsEngine::EffectHelper *helper = m_model->add( m_ui->addComboBox->currentText() );
addInstanceWidget( helper->effect );
} }
...@@ -29,7 +29,11 @@ class EffectUser; ...@@ -29,7 +29,11 @@ class EffectUser;
#include <QStandardItemModel> #include <QStandardItemModel>
class EffectInstance;
class EffectInstanceListModel; class EffectInstanceListModel;
class EffectInstanceWidget;
class QStackedLayout;
namespace Ui namespace Ui
{ {
...@@ -44,6 +48,9 @@ class EffectStack : public QDialog ...@@ -44,6 +48,9 @@ class EffectStack : public QDialog
explicit EffectStack( EffectUser *user, QWidget *parent = 0 ); explicit EffectStack( EffectUser *user, QWidget *parent = 0 );
~EffectStack(); ~EffectStack();
private:
void addInstanceWidget( EffectInstance *instance );
private slots: private slots:
void selectedChanged( const QModelIndex &index ); void selectedChanged( const QModelIndex &index );
void moveUp(); void moveUp();
...@@ -55,6 +62,8 @@ class EffectStack : public QDialog ...@@ -55,6 +62,8 @@ class EffectStack : public QDialog
Ui::EffectStack *m_ui; Ui::EffectStack *m_ui;
EffectInstanceListModel *m_model; EffectInstanceListModel *m_model;
EffectUser *m_user; EffectUser *m_user;
QStackedLayout *m_stackedLayout;
QHash<QString, EffectInstanceWidget*> m_instanceWidgets;
}; };
#endif // EFFECTSTACK_H #endif // EFFECTSTACK_H
...@@ -120,9 +120,6 @@ ...@@ -120,9 +120,6 @@
</item> </item>
</layout> </layout>
</item> </item>
<item>
<widget class="EffectInstanceWidget" name="instanceWidget" native="true"/>
</item>
</layout> </layout>
</item> </item>
<item> <item>
...@@ -137,14 +134,6 @@ ...@@ -137,14 +134,6 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<customwidgets>
<customwidget>
<class>EffectInstanceWidget</class>
<extends>QWidget</extends>
<header>EffectInstanceWidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources> <resources>
<include location="../../../../resources.qrc"/> <include location="../../../../resources.qrc"/>
</resources> </resources>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment