From 23e1a368bd364fbd003912af9b81439a14a002f3 Mon Sep 17 00:00:00 2001 From: Tobias Doerffel Date: Sun, 4 May 2008 22:33:27 +0000 Subject: [PATCH] fixed crash when adding an effect although none is selected and improved overall usability git-svn-id: https://lmms.svn.sf.net/svnroot/lmms/trunk/lmms@954 0778d3d1-df1d-0410-868b-ea421aaaa00d --- ChangeLog | 6 +++++ include/effect_select_dialog.h | 9 ++----- include/plugin.h | 10 +++++++ src/gui/effect_select_dialog.cpp | 46 +++++++++++++++++--------------- 4 files changed, 43 insertions(+), 28 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6965c9501..a260d6677 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2008-05-04 Tobias Doerffel + * include/effect_select_dialog.h: + * include/plugin.h: + * src/gui/effect_select_dialog.cpp: + fixed crash when adding an effect although none is selected and + improved overall usability + * plugins/organic/organic.cpp: fixed knob-inheritance problems diff --git a/include/effect_select_dialog.h b/include/effect_select_dialog.h index 9057619e8..966247985 100644 --- a/include/effect_select_dialog.h +++ b/include/effect_select_dialog.h @@ -76,19 +76,14 @@ public: signals: void highlighted( const effectKey & _key ); - void addPlugin( const effectKey & _key ); void doubleClicked( const effectKey & _key ); -protected: - virtual void resizeEvent( QResizeEvent * ); - - protected slots: void rowChanged( const QModelIndex &, const QModelIndex & ); - void onAddButtonReleased( void ); void onDoubleClicked( const QModelIndex & ); - + void updateSelection( void ); + private: QVector m_pluginDescriptors; diff --git a/include/plugin.h b/include/plugin.h index 8265256d9..1757487cc 100644 --- a/include/plugin.h +++ b/include/plugin.h @@ -108,18 +108,28 @@ public: user = l[1]; } } + inline QString dumpBase64( void ) const { return( base64::encode( QList() << name << user ) ); } + + inline bool isValid( void ) const + { + return( desc != NULL && + name != QString::null ); + } + plugin::descriptor * desc; QString name; QVariant user; }; + typedef QList keyList; + subPluginFeatures( plugin::PluginTypes _type ) : m_type( _type ) { diff --git a/src/gui/effect_select_dialog.cpp b/src/gui/effect_select_dialog.cpp index 5e208d8f7..936fa4c6f 100644 --- a/src/gui/effect_select_dialog.cpp +++ b/src/gui/effect_select_dialog.cpp @@ -125,7 +125,10 @@ void effectSelectDialog::setSelection( const effectKey & _selection ) void effectSelectDialog::selectPlugin( void ) { - accept(); + if( m_currentSelection.isValid() ) + { + accept(); + } } @@ -194,6 +197,8 @@ effectListWidget::effectListWidget( QWidget * _parent ) : m_filterEdit = new QLineEdit( this ); connect( m_filterEdit, SIGNAL( textChanged( const QString & ) ), &m_model, SLOT( setFilterRegExp( const QString & ) ) ); + connect( m_filterEdit, SIGNAL( textChanged( const QString & ) ), + this, SLOT( updateSelection() ) ); m_pluginList = new QListView( this ); m_pluginList->setModel( &m_model ); @@ -228,11 +233,7 @@ effectListWidget::effectListWidget( QWidget * _parent ) : vboxl->addWidget( m_pluginList ); vboxl->addWidget( groupbox ); - if( m_sourceModel.rowCount() > 0 ) - { -// m_pluginList->setCurrentRow( 0 ); - //rowChanged( 0 ); - } + updateSelection(); } @@ -253,10 +254,15 @@ void effectListWidget::rowChanged( const QModelIndex & _idx, if( m_model.mapToSource( _idx ).row() < 0 ) { - return; + // invalidate current selection + m_currentSelection = + plugin::descriptor::subPluginFeatures::key(); + } + else + { + m_currentSelection = + m_effectKeys[m_model.mapToSource( _idx ).row()]; } - - m_currentSelection = m_effectKeys[m_model.mapToSource( _idx ).row()]; if( m_currentSelection.desc && m_currentSelection.desc->sub_plugin_features ) { @@ -286,6 +292,7 @@ void effectListWidget::rowChanged( const QModelIndex & _idx, + void effectListWidget::onDoubleClicked( const QModelIndex & ) { emit( doubleClicked( m_currentSelection ) ); @@ -294,22 +301,19 @@ void effectListWidget::onDoubleClicked( const QModelIndex & ) -void effectListWidget::onAddButtonReleased() +void effectListWidget::updateSelection( void ) { - emit( addPlugin( m_currentSelection ) ); + // no valid selection anymore due to changed filter? + if( m_pluginList->selectionModel()->selection().size() <= 0 ) + { + // then select our first item + m_pluginList->selectionModel()->select( m_model.index( 0, 0 ), + QItemSelectionModel::ClearAndSelect ); + rowChanged( m_model.index( 0, 0 ), QModelIndex() ); + } } - - -void effectListWidget::resizeEvent( QResizeEvent * ) -{ - //m_descriptionWidget->setFixedWidth( width() - 40 ); -} - - - - #include "effect_select_dialog.moc" #endif