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 )
setMinimumWidth( 400 );
VLCProxyModel *model = new VLCProxyModel( this );
PLModel *plmodel = PLModel::getPLModel( p_intf );
model->setModel( VLCProxyModel::PL_MODEL, plmodel );
model->switchToModel( VLCProxyModel::PL_MODEL );
PLModel *model = PLModel::getPLModel( p_intf );
mainView = new StandardPLPanel( this, p_intf, p_root, selector, model );
......@@ -233,7 +229,7 @@ void PlaylistWidget::changeView( const QModelIndex& index )
#include <QSignalMapper>
#include <QMenu>
#include <QPainter>
LocationBar::LocationBar( VLCProxyModel *m )
LocationBar::LocationBar( VLCModel *m )
{
setModel( m );
mapper = new QSignalMapper( this );
......
......@@ -118,16 +118,16 @@ private:
bool b_arrow;
};
class VLCProxyModel;
class VLCModel;
class QHBoxLayout;
class LocationBar : public QWidget
{
Q_OBJECT
public:
LocationBar( VLCProxyModel * );
LocationBar( VLCModel * );
void setIndex( const QModelIndex & );
void setModel( VLCProxyModel * _model ) { model = _model; };
void setModel( VLCModel * _model ) { model = _model; };
virtual QSize sizeHint() const;
protected:
virtual void resizeEvent ( QResizeEvent * event );
......@@ -135,7 +135,7 @@ protected:
private:
void layOut( const QSize& size );
VLCProxyModel *model;
VLCModel *model;
QSignalMapper *mapper;
QWidgetList buttons;
QList<QAction*> actions;
......
......@@ -42,66 +42,6 @@
#include <QAction>
#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
*************************************************************************/
......@@ -626,7 +566,7 @@ void PLModel::processInputItemUpdate( input_thread_t *p_input )
if( p_input && !( p_input->b_dead || !vlc_object_alive( p_input ) ) )
{
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 ) );
......@@ -679,7 +619,7 @@ void PLModel::processItemAppend( int i_pl_itemid, int i_pl_itemidparent )
nodeParentItem->insertChild( newItem, pos );
endInsertRows();
if ( newItem->inputItem() == THEMIM->currentInputItem() )
sigs->emit_currentIndexChanged( index( newItem, 0 ) );
emit currentIndexChanged( index( newItem, 0 ) );
if( latestSearch.isEmpty() ) return;
filter( latestSearch, index( rootItem, 0), false /*FIXME*/ );
......@@ -703,7 +643,7 @@ void PLModel::rebuild( playlist_item_t *p_root )
/* And signal the view */
endResetModel();
if( p_root ) sigs->emit_rootIndexChanged();
if( p_root ) emit rootIndexChanged();
}
void PLModel::takeItem( PLItem *item )
......@@ -868,9 +808,9 @@ void PLModel::sort( QModelIndex caller, QModelIndex rootIndex, const int column,
}
PL_UNLOCK;
/* 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 )
......
......@@ -39,7 +39,6 @@
#include <QSignalMapper>
#include <QMimeData>
#include <QAbstractItemModel>
#include <QSortFilterProxyModel>
#include <QVariant>
#include <QModelIndex>
#include <QAction>
......@@ -48,78 +47,6 @@ class PLItem;
class PLSelector;
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
{
Q_OBJECT
......
......@@ -78,7 +78,7 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent,
intf_thread_t *_p_intf,
playlist_item_t *p_root,
PLSelector *_p_selector,
VLCProxyModel *_p_model )
VLCModel *_p_model )
: QWidget( _parent ),
model( _p_model ),
p_intf( _p_intf ),
......@@ -113,9 +113,9 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent,
DCONNECT( THEMIM, leafBecameParent( int ),
this, browseInto( int ) );
CONNECT( model->sigs, currentIndexChanged( const QModelIndex& ),
CONNECT( model, currentIndexChanged( const QModelIndex& ),
this, handleExpansion( const QModelIndex& ) );
CONNECT( model->sigs, rootIndexChanged(), this, browseInto() );
CONNECT( model, rootIndexChanged(), this, browseInto() );
setRootItem( p_root, false );
}
......@@ -164,7 +164,7 @@ void StandardPLPanel::popupPlView( const QPoint &point )
bool StandardPLPanel::popup( const QPoint &point )
{
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 ) \
if ( model->isSupportedAction( act, index ) )\
......@@ -279,7 +279,7 @@ bool StandardPLPanel::popup( const QPoint &point )
void StandardPLPanel::popupAction( QAction *action )
{
VLCProxyModel *model = qobject_cast<VLCProxyModel *>(currentView->model());
VLCModel *model = qobject_cast<VLCModel *>(currentView->model());
VLCModelSubInterface::actionsContainerType a =
action->data().value<VLCModelSubInterface::actionsContainerType>();
QModelIndexList list = currentView->selectionModel()->selectedRows();
......@@ -478,8 +478,7 @@ void StandardPLPanel::searchDelayed( const QString& searchText )
void StandardPLPanel::setRootItem( playlist_item_t *p_item, bool b )
{
Q_UNUSED( b );
if ( model->switchToModel( VLCProxyModel::PL_MODEL ) )
model->rebuild( p_item );
model->rebuild( p_item );
}
void StandardPLPanel::browseInto( const QModelIndex &index )
......
......@@ -60,7 +60,7 @@ class StandardPLPanel: public QWidget
public:
StandardPLPanel( PlaylistWidget *, intf_thread_t *,
playlist_item_t *, PLSelector *, VLCProxyModel * );
playlist_item_t *, PLSelector *, VLCModel * );
virtual ~StandardPLPanel();
enum { ICON_VIEW = 0,
......@@ -74,7 +74,7 @@ public:
static QMenu *viewSelectionMenu(StandardPLPanel *obj);
protected:
VLCProxyModel *model;
VLCModel *model;
virtual void wheelEvent( QWheelEvent *e );
bool popup( const QPoint &point );
......
......@@ -453,7 +453,7 @@ void PlTreeView::setModel( QAbstractItemModel * model )
QTreeView::setModel( model );
VLCModel *m = static_cast<VLCModel*>(model);
CONNECT( this, expanded( const QModelIndex & ),
m->sigs, ensureArtRequestedSlot( const QModelIndex & ) );
m, ensureArtRequested( const QModelIndex & ) );
}
void PlTreeView::startDrag ( Qt::DropActions supportedActions )
......
......@@ -27,12 +27,10 @@
VLCModelSubInterface::VLCModelSubInterface()
{
sigs = new VLCModelSignalsHandler( this );
}
VLCModelSubInterface::~VLCModelSubInterface()
{
delete sigs;
}
int VLCModelSubInterface::columnFromMeta( int meta_col )
......
......@@ -43,7 +43,6 @@
#include <QIcon>
class QAction;
class VLCModelSignalsHandler;
/* Provides non Q_Object interface for Models.
This allows multiple inheritance on already QAbstractModel based
......@@ -108,34 +107,10 @@ public:
virtual bool isSupportedAction( actions action, const QModelIndex & ) const = 0;
static int columnFromMeta( int meta_col );
/* Indirect slots handlers */
VLCModelSignalsHandler *sigs;
virtual void activateItem( 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.
Only implements methods sharing the same code that would be
implemented in subclasses.
......@@ -158,15 +133,20 @@ public:
virtual input_item_t *getInputItem( const QModelIndex & ) const;
virtual QString getTitle( const QModelIndex &index ) const;
/* VLCModelSubInterface Indirect slots handlers */
virtual void ensureArtRequested( const QModelIndex &index );
/* Custom */
static int columnToMeta( int _column );
static int metaToColumn( int meta );
static QString getMeta( const QModelIndex & index, int meta );
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:
/* Custom methods / helpers */
virtual bool isCurrent( const QModelIndex &index ) const;
......
......@@ -1107,7 +1107,7 @@ void VLCMenuBar::PopupMenu( intf_thread_t *p_intf, bool show )
PLModel *model = PLModel::getPLModel( p_intf );
plMenu->setModel( model );
CONNECT( plMenu, activated(const QModelIndex&),
model->sigs, activateItemSlot(const QModelIndex&));
model, activateItem(const QModelIndex&));
menu->addMenu( plMenu );
/* 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