Commit d4a2b748 authored by Francois Cartegnie's avatar Francois Cartegnie

Qt: MLModel: Use Model Indexes instead of MLItem.

(see prev commit)
parent 856d5fe0
......@@ -151,6 +151,11 @@ MLItem* MLItem::parent() const
return parentItem;
}
input_item_t* MLItem::inputItem()
{
return ml_CreateInputItem( p_ml, id() );
}
/**
* @brief Get a QVariant representing the data on a column
* @param column
......
......@@ -45,11 +45,13 @@ class MLModel;
class MLItem
{
friend class MLModel;
public:
MLItem( const MLModel *p_model, intf_thread_t *_p_intf,
ml_media_t *p_media, MLItem *p_parent );
virtual ~MLItem();
protected:
void addChild( MLItem *child, int row = -1 );
void delChild( int row );
void clearChildren();
......@@ -58,6 +60,7 @@ public:
int childCount() const;
MLItem* parent() const;
input_item_t *inputItem();
QVariant data( int column ) const;
bool setData( ml_select_e meta, const QVariant &data );
......
......@@ -504,6 +504,37 @@ void MLModel::play( const QModelIndex &idx )
AddItemToPlaylist( item->id(), true, p_ml, true );
}
QString MLModel::getURI( const QModelIndex &index ) const
{
return QString();
}
QModelIndex MLModel::rootIndex() const
{
// FIXME
return QModelIndex();
}
bool MLModel::isTree() const
{
// FIXME ?
return false;
}
bool MLModel::canEdit() const
{
/* can always insert */
return true;
}
bool MLModel::isCurrentItem( const QModelIndex &index, playLocation where ) const
{
Q_UNUSED( index );
if ( where == IN_MEDIALIBRARY )
return true;
return false;
}
bool MLModel::popup( const QModelIndex & index, const QPoint &point, const QModelIndexList &list )
{
current_selection = list;
......@@ -586,6 +617,18 @@ void MLModel::popupSave()
THEDP->streamingDialog( NULL, mrls[0] );
}
QModelIndex MLModel::getIndexByMLID( int id ) const
{
for( int i = 0; i < rowCount( ); i++ )
{
QModelIndex idx = index( i, 0 );
MLItem *item = static_cast< MLItem* >( idx.internalPointer() );
if( item->id() == id )
return idx;
}
return QModelIndex();
}
static int mediaAdded( vlc_object_t *p_this, char const *psz_var,
vlc_value_t oldval, vlc_value_t newval,
void *data )
......@@ -614,17 +657,7 @@ static int mediaDeleted( vlc_object_t *p_this, char const *psz_var,
VLC_UNUSED( p_this ); VLC_UNUSED( psz_var ); VLC_UNUSED( oldval );
MLModel* p_model = ( MLModel* )data;
QModelIndex remove_idx = QModelIndex();
for( int i = 0; i < p_model->rowCount( ); i++ )
{
QModelIndex idx = p_model->index( i, 0 );
MLItem *item = static_cast< MLItem* >( idx.internalPointer() );
if( item->id() == newval.i_int )
{
remove_idx = idx;
break;
}
}
QModelIndex remove_idx = p_model->getIndexByMLID( newval.i_int );
if( remove_idx.isValid() )
p_model->remove( remove_idx );
return VLC_SUCCESS;
......
......@@ -54,12 +54,7 @@ public:
// Basic QAbstractItemModel implementation
MLModel( intf_thread_t *_p_intf, QObject *parent = NULL );
virtual ~MLModel();
inline MLItem *getItem( QModelIndex index ) const
{
if( index.isValid() )
return static_cast<MLItem*>( index.internalPointer() );
else return NULL;
}
virtual int itemId( const QModelIndex & ) const;
QVariant data( const QModelIndex &idx, const int role = Qt::DisplayRole ) const;
......@@ -95,13 +90,18 @@ public:
bool bSignal = true );
virtual void doDelete( QModelIndexList list );
void remove( MLItem *item );
void remove( QModelIndex idx );
void clear();
virtual bool popup( const QModelIndex & index, const QPoint &point, const QModelIndexList &list );
void play( const QModelIndex &idx );
QStringList selectedURIs();
virtual QString getURI( const QModelIndex &index ) const;
virtual QModelIndex rootIndex() const;
virtual bool isTree() const;
virtual bool canEdit() const;
virtual bool isCurrentItem( const QModelIndex &index, playLocation where ) const;
QModelIndex getIndexByMLID( int id ) const;
public slots:
void activateItem( const QModelIndex &index );
......@@ -113,6 +113,15 @@ protected slots:
void popupStream();
void popupSave();
protected:
void remove( MLItem *item );
inline MLItem *getItem( QModelIndex index ) const
{
if( index.isValid() )
return static_cast<MLItem*>( index.internalPointer() );
else return NULL;
}
private:
QList< MLItem* > items;
media_library_t* p_ml;
......
......@@ -510,9 +510,7 @@ QRect PictureFlowSoftwareRenderer::renderSlide(const SlideInfo &slide, int col1,
index = ((MLModel*)state->model)->index( slide.slideIndex, 0, QModelIndex() );
if( !index.isValid() )
return QRect();
MLItem *item = static_cast<MLItem*>( index.internalPointer() );
artURL = qfu( item->getMedia()->psz_cover );
artURL = mlm->data( index, COLUMN_COVER ).toString();
}
#endif
QString key = QString("%1%2%3%4").arg(VLCModel::getMeta( index, COLUMN_TITLE )).arg( VLCModel::getMeta( index, COLUMN_ARTIST ) ).arg(index.data( VLCModel::IsCurrentRole ).toBool() ).arg( artURL );
......
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