Commit 29f10d48 authored by Francois Cartegnie's avatar Francois Cartegnie

Qt4: remove models and signals proxying

Was introduced as workaround for the SQL ML Classes design mess

refs 2f353e18
parent 2f353e18
...@@ -93,11 +93,7 @@ PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i, QWidget *_par ) ...@@ -93,11 +93,7 @@ PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i, QWidget *_par )
setMinimumWidth( 400 ); setMinimumWidth( 400 );
VLCProxyModel *model = new VLCProxyModel( this ); PLModel *model = PLModel::getPLModel( p_intf );
PLModel *plmodel = PLModel::getPLModel( p_intf );
model->setModel( VLCProxyModel::PL_MODEL, plmodel );
model->switchToModel( VLCProxyModel::PL_MODEL );
mainView = new StandardPLPanel( this, p_intf, p_root, selector, model ); mainView = new StandardPLPanel( this, p_intf, p_root, selector, model );
...@@ -233,7 +229,7 @@ void PlaylistWidget::changeView( const QModelIndex& index ) ...@@ -233,7 +229,7 @@ void PlaylistWidget::changeView( const QModelIndex& index )
#include <QSignalMapper> #include <QSignalMapper>
#include <QMenu> #include <QMenu>
#include <QPainter> #include <QPainter>
LocationBar::LocationBar( VLCProxyModel *m ) LocationBar::LocationBar( VLCModel *m )
{ {
setModel( m ); setModel( m );
mapper = new QSignalMapper( this ); mapper = new QSignalMapper( this );
......
...@@ -118,16 +118,16 @@ private: ...@@ -118,16 +118,16 @@ private:
bool b_arrow; bool b_arrow;
}; };
class VLCProxyModel; class VLCModel;
class QHBoxLayout; class QHBoxLayout;
class LocationBar : public QWidget class LocationBar : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
LocationBar( VLCProxyModel * ); LocationBar( VLCModel * );
void setIndex( const QModelIndex & ); void setIndex( const QModelIndex & );
void setModel( VLCProxyModel * _model ) { model = _model; }; void setModel( VLCModel * _model ) { model = _model; };
virtual QSize sizeHint() const; virtual QSize sizeHint() const;
protected: protected:
virtual void resizeEvent ( QResizeEvent * event ); virtual void resizeEvent ( QResizeEvent * event );
...@@ -135,7 +135,7 @@ protected: ...@@ -135,7 +135,7 @@ protected:
private: private:
void layOut( const QSize& size ); void layOut( const QSize& size );
VLCProxyModel *model; VLCModel *model;
QSignalMapper *mapper; QSignalMapper *mapper;
QWidgetList buttons; QWidgetList buttons;
QList<QAction*> actions; QList<QAction*> actions;
......
...@@ -42,66 +42,6 @@ ...@@ -42,66 +42,6 @@
#include <QAction> #include <QAction>
#include <QBuffer> #include <QBuffer>
/*************************************************************************
* Proxy model implementation
*************************************************************************/
VLCProxyModel::VLCProxyModel( QObject *parent )
: QSortFilterProxyModel( parent ), VLCModelSubInterface()
{
for ( int i = 0; i <= SQLML_MODEL ; i++ ) sourcemodels[ i ] = NULL;
/* Because we can't directly plug the signal without mapping
the index to the proxy model, we need a conversion step.
*/
connect( this, SIGNAL( currentIndexChanged_Converted(const QModelIndex&) ),
this->sigs, SIGNAL( currentIndexChanged(const QModelIndex&) ) );
}
bool VLCProxyModel::switchToModel( models type )
{
VLCModel *previousModel = model();
VLCModel *newModel = sourcemodels[ type ];
if ( ! newModel /*|| newModel == previousModel*/ ) return false;
setSourceModel( newModel );
if ( previousModel )
{
/* First disconnect previous signals */
disconnect( previousModel->sigs, SIGNAL( currentIndexChanged(const QModelIndex&) ),
this, SIGNAL( currentIndexChanged_IndexConversion(const QModelIndex&) ) );
disconnect( previousModel->sigs, SIGNAL( rootIndexChanged() ),
this->sigs, SIGNAL( rootIndexChanged() ) );
}
/* wire to propagate sourceModel's signals */
connect( model()->sigs, SIGNAL( currentIndexChanged(const QModelIndex&) ),
this, SLOT( currentIndexChanged_IndexConversion(const QModelIndex&) ) );
connect( model()->sigs, SIGNAL( rootIndexChanged() ),
this->sigs, SIGNAL( rootIndexChanged() ) );
return true;
}
QModelIndexList VLCProxyModel::mapListToSource( const QModelIndexList& list )
{
QModelIndexList newlist;
foreach( const QModelIndex &index, list )
{
if ( index.isValid() )
newlist << mapToSource( index );
}
return newlist;
}
void VLCProxyModel::sort( const int column, Qt::SortOrder order )
{
/* sorting on PLModel affects playlist order. */
if ( model() == sourcemodels[ PL_MODEL ] )
model()->sort( column, order );
else
/* otherwise we just use native proxy sorting */
QSortFilterProxyModel::sort( column, order );
}
/************************************************************************* /*************************************************************************
* Playlist model implementation * Playlist model implementation
*************************************************************************/ *************************************************************************/
...@@ -626,7 +566,7 @@ void PLModel::processInputItemUpdate( input_thread_t *p_input ) ...@@ -626,7 +566,7 @@ void PLModel::processInputItemUpdate( input_thread_t *p_input )
if( p_input && !( p_input->b_dead || !vlc_object_alive( p_input ) ) ) if( p_input && !( p_input->b_dead || !vlc_object_alive( p_input ) ) )
{ {
PLItem *item = findByInputId( rootItem, input_GetItem( p_input )->i_id ); PLItem *item = findByInputId( rootItem, input_GetItem( p_input )->i_id );
if( item ) sigs->emit_currentIndexChanged( index( item, 0 ) ); if( item ) emit currentIndexChanged( index( item, 0 ) );
} }
processInputItemUpdate( input_GetItem( p_input ) ); processInputItemUpdate( input_GetItem( p_input ) );
...@@ -679,7 +619,7 @@ void PLModel::processItemAppend( int i_pl_itemid, int i_pl_itemidparent ) ...@@ -679,7 +619,7 @@ void PLModel::processItemAppend( int i_pl_itemid, int i_pl_itemidparent )
nodeParentItem->insertChild( newItem, pos ); nodeParentItem->insertChild( newItem, pos );
endInsertRows(); endInsertRows();
if ( newItem->inputItem() == THEMIM->currentInputItem() ) if ( newItem->inputItem() == THEMIM->currentInputItem() )
sigs->emit_currentIndexChanged( index( newItem, 0 ) ); emit currentIndexChanged( index( newItem, 0 ) );
if( latestSearch.isEmpty() ) return; if( latestSearch.isEmpty() ) return;
filter( latestSearch, index( rootItem, 0), false /*FIXME*/ ); filter( latestSearch, index( rootItem, 0), false /*FIXME*/ );
...@@ -703,7 +643,7 @@ void PLModel::rebuild( playlist_item_t *p_root ) ...@@ -703,7 +643,7 @@ void PLModel::rebuild( playlist_item_t *p_root )
/* And signal the view */ /* And signal the view */
endResetModel(); endResetModel();
if( p_root ) sigs->emit_rootIndexChanged(); if( p_root ) emit rootIndexChanged();
} }
void PLModel::takeItem( PLItem *item ) void PLModel::takeItem( PLItem *item )
...@@ -868,9 +808,9 @@ void PLModel::sort( QModelIndex caller, QModelIndex rootIndex, const int column, ...@@ -868,9 +808,9 @@ void PLModel::sort( QModelIndex caller, QModelIndex rootIndex, const int column,
} }
PL_UNLOCK; PL_UNLOCK;
/* if we have popup item, try to make sure that you keep that item visible */ /* if we have popup item, try to make sure that you keep that item visible */
if( caller.isValid() ) sigs->emit_currentIndexChanged( caller ); if( caller.isValid() ) emit currentIndexChanged( caller );
else if( currentIndex().isValid() ) sigs->emit_currentIndexChanged( currentIndex() ); else if( currentIndex().isValid() ) emit currentIndexChanged( currentIndex() );
} }
void PLModel::filter( const QString& search_text, const QModelIndex & idx, bool b_recursive ) void PLModel::filter( const QString& search_text, const QModelIndex & idx, bool b_recursive )
......
...@@ -39,7 +39,6 @@ ...@@ -39,7 +39,6 @@
#include <QSignalMapper> #include <QSignalMapper>
#include <QMimeData> #include <QMimeData>
#include <QAbstractItemModel> #include <QAbstractItemModel>
#include <QSortFilterProxyModel>
#include <QVariant> #include <QVariant>
#include <QModelIndex> #include <QModelIndex>
#include <QAction> #include <QAction>
...@@ -48,78 +47,6 @@ class PLItem; ...@@ -48,78 +47,6 @@ class PLItem;
class PLSelector; class PLSelector;
class PlMimeData; class PlMimeData;
class VLCProxyModel : public QSortFilterProxyModel, public VLCModelSubInterface
{
Q_OBJECT
public:
VLCProxyModel( QObject *parent = 0 );
inline VLCModel *model() const
{
return qobject_cast<VLCModel *>( sourceModel() );
}
/* Different Models Handling */
enum models
{
PL_MODEL = 0,
SQLML_MODEL /* note: keep it last */
};
bool switchToModel( models type );
void setModel( models type, VLCModel *model )
{
sourcemodels[ type ] = model;
}
QModelIndexList mapListToSource( const QModelIndexList& list );
/* VLCModelSubInterface Methods */
virtual void rebuild( playlist_item_t * p = NULL ) { model()->rebuild( p ); }
virtual void doDelete( QModelIndexList list ) { model()->doDelete( mapListToSource( list ) ); }
virtual void createNode( QModelIndex a, QString b ) { model()->createNode( mapToSource( a ), b ); }
virtual void renameNode( QModelIndex a, QString b ) { model()->renameNode( mapToSource( a ), b ); }
virtual void removeAll() { model()->removeAll(); }
virtual QModelIndex rootIndex() const { return mapFromSource( model()->rootIndex() ); }
virtual void filter( const QString& text, const QModelIndex & root, bool b_recursive )
{
model()->filter( text, mapToSource( root ), b_recursive );
}
virtual QModelIndex currentIndex() const { return mapFromSource( model()->currentIndex() ); }
virtual QModelIndex indexByPLID( const int i_plid, const int c ) const { return mapFromSource( model()->indexByPLID( i_plid, c ) ); }
virtual QModelIndex indexByInputItemID( const int i_inputitem_id, const int c ) const { return mapFromSource( model()->indexByInputItemID( i_inputitem_id, c ) ); }
virtual int itemId( const QModelIndex &index, int type ) const { return model()->itemId( mapToSource( index ), type ); }
virtual bool isTree() const { return model()->isTree(); }
virtual bool canEdit() const { return model()->canEdit(); }
virtual QString getURI( const QModelIndex &index ) const { return model()->getURI( mapToSource( index ) ); }
virtual input_item_t *getInputItem( const QModelIndex &index ) const { return model()->getInputItem( mapToSource( index ) ); }
virtual QString getTitle( const QModelIndex &index ) const { return model()->getTitle( mapToSource( index ) ); }
virtual bool action( QAction *action, const QModelIndexList &indexes )
{
return model()->action( action, mapListToSource( indexes ) );
}
virtual bool isSupportedAction( actions action, const QModelIndex &index ) const { return model()->isSupportedAction( action, mapToSource( index ) ); }
/* Indirect slots handlers */
virtual void activateItem( const QModelIndex &index ) { model()->activateItem( mapToSource( index ) ); }
virtual void ensureArtRequested( const QModelIndex &index ) { model()->ensureArtRequested( mapToSource( index ) ); }
/* AbstractItemModel subclassing */
virtual void sort( const int column, Qt::SortOrder order = Qt::AscendingOrder );
/* Local signals for index conversion */
public slots:
void currentIndexChanged_IndexConversion( const QModelIndex &index )
{
emit currentIndexChanged_Converted( mapFromSource( index ) );
}
signals:
void currentIndexChanged_Converted( const QModelIndex & );
private:
VLCModel * sourcemodels[SQLML_MODEL + 1];
};
class PLModel : public VLCModel class PLModel : public VLCModel
{ {
Q_OBJECT Q_OBJECT
......
...@@ -78,7 +78,7 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent, ...@@ -78,7 +78,7 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent,
intf_thread_t *_p_intf, intf_thread_t *_p_intf,
playlist_item_t *p_root, playlist_item_t *p_root,
PLSelector *_p_selector, PLSelector *_p_selector,
VLCProxyModel *_p_model ) VLCModel *_p_model )
: QWidget( _parent ), : QWidget( _parent ),
model( _p_model ), model( _p_model ),
p_intf( _p_intf ), p_intf( _p_intf ),
...@@ -113,9 +113,9 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent, ...@@ -113,9 +113,9 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent,
DCONNECT( THEMIM, leafBecameParent( int ), DCONNECT( THEMIM, leafBecameParent( int ),
this, browseInto( int ) ); this, browseInto( int ) );
CONNECT( model->sigs, currentIndexChanged( const QModelIndex& ), CONNECT( model, currentIndexChanged( const QModelIndex& ),
this, handleExpansion( const QModelIndex& ) ); this, handleExpansion( const QModelIndex& ) );
CONNECT( model->sigs, rootIndexChanged(), this, browseInto() ); CONNECT( model, rootIndexChanged(), this, browseInto() );
setRootItem( p_root, false ); setRootItem( p_root, false );
} }
...@@ -164,7 +164,7 @@ void StandardPLPanel::popupPlView( const QPoint &point ) ...@@ -164,7 +164,7 @@ void StandardPLPanel::popupPlView( const QPoint &point )
bool StandardPLPanel::popup( const QPoint &point ) bool StandardPLPanel::popup( const QPoint &point )
{ {
QModelIndex index = popupIndex( currentView ); /* index for menu logic only. Do not store.*/ QModelIndex index = popupIndex( currentView ); /* index for menu logic only. Do not store.*/
VLCProxyModel *model = qobject_cast<VLCProxyModel *>(currentView->model()); VLCModel *model = qobject_cast<VLCModel *>(currentView->model());
#define ADD_MENU_ENTRY( icon, title, act ) \ #define ADD_MENU_ENTRY( icon, title, act ) \
if ( model->isSupportedAction( act, index ) )\ if ( model->isSupportedAction( act, index ) )\
...@@ -279,7 +279,7 @@ bool StandardPLPanel::popup( const QPoint &point ) ...@@ -279,7 +279,7 @@ bool StandardPLPanel::popup( const QPoint &point )
void StandardPLPanel::popupAction( QAction *action ) void StandardPLPanel::popupAction( QAction *action )
{ {
VLCProxyModel *model = qobject_cast<VLCProxyModel *>(currentView->model()); VLCModel *model = qobject_cast<VLCModel *>(currentView->model());
VLCModelSubInterface::actionsContainerType a = VLCModelSubInterface::actionsContainerType a =
action->data().value<VLCModelSubInterface::actionsContainerType>(); action->data().value<VLCModelSubInterface::actionsContainerType>();
QModelIndexList list = currentView->selectionModel()->selectedRows(); QModelIndexList list = currentView->selectionModel()->selectedRows();
...@@ -478,8 +478,7 @@ void StandardPLPanel::searchDelayed( const QString& searchText ) ...@@ -478,8 +478,7 @@ void StandardPLPanel::searchDelayed( const QString& searchText )
void StandardPLPanel::setRootItem( playlist_item_t *p_item, bool b ) void StandardPLPanel::setRootItem( playlist_item_t *p_item, bool b )
{ {
Q_UNUSED( b ); Q_UNUSED( b );
if ( model->switchToModel( VLCProxyModel::PL_MODEL ) ) model->rebuild( p_item );
model->rebuild( p_item );
} }
void StandardPLPanel::browseInto( const QModelIndex &index ) void StandardPLPanel::browseInto( const QModelIndex &index )
......
...@@ -60,7 +60,7 @@ class StandardPLPanel: public QWidget ...@@ -60,7 +60,7 @@ class StandardPLPanel: public QWidget
public: public:
StandardPLPanel( PlaylistWidget *, intf_thread_t *, StandardPLPanel( PlaylistWidget *, intf_thread_t *,
playlist_item_t *, PLSelector *, VLCProxyModel * ); playlist_item_t *, PLSelector *, VLCModel * );
virtual ~StandardPLPanel(); virtual ~StandardPLPanel();
enum { ICON_VIEW = 0, enum { ICON_VIEW = 0,
...@@ -74,7 +74,7 @@ public: ...@@ -74,7 +74,7 @@ public:
static QMenu *viewSelectionMenu(StandardPLPanel *obj); static QMenu *viewSelectionMenu(StandardPLPanel *obj);
protected: protected:
VLCProxyModel *model; VLCModel *model;
virtual void wheelEvent( QWheelEvent *e ); virtual void wheelEvent( QWheelEvent *e );
bool popup( const QPoint &point ); bool popup( const QPoint &point );
......
...@@ -453,7 +453,7 @@ void PlTreeView::setModel( QAbstractItemModel * model ) ...@@ -453,7 +453,7 @@ void PlTreeView::setModel( QAbstractItemModel * model )
QTreeView::setModel( model ); QTreeView::setModel( model );
VLCModel *m = static_cast<VLCModel*>(model); VLCModel *m = static_cast<VLCModel*>(model);
CONNECT( this, expanded( const QModelIndex & ), CONNECT( this, expanded( const QModelIndex & ),
m->sigs, ensureArtRequestedSlot( const QModelIndex & ) ); m, ensureArtRequested( const QModelIndex & ) );
} }
void PlTreeView::startDrag ( Qt::DropActions supportedActions ) void PlTreeView::startDrag ( Qt::DropActions supportedActions )
......
...@@ -27,12 +27,10 @@ ...@@ -27,12 +27,10 @@
VLCModelSubInterface::VLCModelSubInterface() VLCModelSubInterface::VLCModelSubInterface()
{ {
sigs = new VLCModelSignalsHandler( this );
} }
VLCModelSubInterface::~VLCModelSubInterface() VLCModelSubInterface::~VLCModelSubInterface()
{ {
delete sigs;
} }
int VLCModelSubInterface::columnFromMeta( int meta_col ) int VLCModelSubInterface::columnFromMeta( int meta_col )
......
...@@ -43,7 +43,6 @@ ...@@ -43,7 +43,6 @@
#include <QIcon> #include <QIcon>
class QAction; class QAction;
class VLCModelSignalsHandler;
/* Provides non Q_Object interface for Models. /* Provides non Q_Object interface for Models.
This allows multiple inheritance on already QAbstractModel based This allows multiple inheritance on already QAbstractModel based
...@@ -108,34 +107,10 @@ public: ...@@ -108,34 +107,10 @@ public:
virtual bool isSupportedAction( actions action, const QModelIndex & ) const = 0; virtual bool isSupportedAction( actions action, const QModelIndex & ) const = 0;
static int columnFromMeta( int meta_col ); static int columnFromMeta( int meta_col );
/* Indirect slots handlers */
VLCModelSignalsHandler *sigs;
virtual void activateItem( const QModelIndex &index ) = 0; virtual void activateItem( const QModelIndex &index ) = 0;
virtual void ensureArtRequested( const QModelIndex &index ) = 0; virtual void ensureArtRequested( const QModelIndex &index ) = 0;
}; };
class VLCModelSignalsHandler : public QObject
{
Q_OBJECT
public:
VLCModelSignalsHandler( VLCModelSubInterface *_parent ) { parent = _parent; }
void emit_currentIndexChanged( const QModelIndex &index ) { emit currentIndexChanged( index ); }
void emit_rootIndexChanged() { emit rootIndexChanged(); }
public slots:
void activateItemSlot( const QModelIndex &index ) { parent->activateItem( index ); }
void ensureArtRequestedSlot( const QModelIndex &index ) { parent->ensureArtRequested( index ); }
signals:
void currentIndexChanged( const QModelIndex& );
void rootIndexChanged();
private:
VLCModelSubInterface *parent;
};
/* Abstract VLC Model ; Base for custom models. /* Abstract VLC Model ; Base for custom models.
Only implements methods sharing the same code that would be Only implements methods sharing the same code that would be
implemented in subclasses. implemented in subclasses.
...@@ -158,15 +133,20 @@ public: ...@@ -158,15 +133,20 @@ public:
virtual input_item_t *getInputItem( const QModelIndex & ) const; virtual input_item_t *getInputItem( const QModelIndex & ) const;
virtual QString getTitle( const QModelIndex &index ) const; virtual QString getTitle( const QModelIndex &index ) const;
/* VLCModelSubInterface Indirect slots handlers */
virtual void ensureArtRequested( const QModelIndex &index );
/* Custom */ /* Custom */
static int columnToMeta( int _column ); static int columnToMeta( int _column );
static int metaToColumn( int meta ); static int metaToColumn( int meta );
static QString getMeta( const QModelIndex & index, int meta ); static QString getMeta( const QModelIndex & index, int meta );
static QPixmap getArtPixmap( const QModelIndex & index, const QSize & size ); static QPixmap getArtPixmap( const QModelIndex & index, const QSize & size );
public slots:
/* slots handlers */
virtual void ensureArtRequested( const QModelIndex &index );
signals:
void currentIndexChanged( const QModelIndex& );
void rootIndexChanged();
protected: protected:
/* Custom methods / helpers */ /* Custom methods / helpers */
virtual bool isCurrent( const QModelIndex &index ) const; virtual bool isCurrent( const QModelIndex &index ) const;
......
...@@ -1107,7 +1107,7 @@ void VLCMenuBar::PopupMenu( intf_thread_t *p_intf, bool show ) ...@@ -1107,7 +1107,7 @@ void VLCMenuBar::PopupMenu( intf_thread_t *p_intf, bool show )
PLModel *model = PLModel::getPLModel( p_intf ); PLModel *model = PLModel::getPLModel( p_intf );
plMenu->setModel( model ); plMenu->setModel( model );
CONNECT( plMenu, activated(const QModelIndex&), CONNECT( plMenu, activated(const QModelIndex&),
model->sigs, activateItemSlot(const QModelIndex&)); model, activateItem(const QModelIndex&));
menu->addMenu( plMenu ); menu->addMenu( plMenu );
/* Static entries for ending, like open */ /* Static entries for ending, like open */
......
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