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 )
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;
}
......@@ -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;
......
......@@ -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()
......@@ -50,10 +61,20 @@ EffectStack::~EffectStack()
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
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 );
}
......@@ -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
......@@ -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>
......
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