[vlc-commits] Qt: MLModel: Use Model Indexes instead of MLItem.
Francois Cartegnie
git at videolan.org
Thu Jul 19 14:23:22 CEST 2012
vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Wed Jul 18 20:25:15 2012 +0200| [d4a2b7486c44eb9d7b98ddacec92c48e78b1010c] | committer: Francois Cartegnie
Qt: MLModel: Use Model Indexes instead of MLItem.
(see prev commit)
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=d4a2b7486c44eb9d7b98ddacec92c48e78b1010c
---
modules/gui/qt4/components/playlist/ml_item.cpp | 5 ++
modules/gui/qt4/components/playlist/ml_item.hpp | 3 ++
modules/gui/qt4/components/playlist/ml_model.cpp | 55 +++++++++++++++++-----
modules/gui/qt4/components/playlist/ml_model.hpp | 23 ++++++---
modules/gui/qt4/util/pictureflow.cpp | 4 +-
5 files changed, 69 insertions(+), 21 deletions(-)
diff --git a/modules/gui/qt4/components/playlist/ml_item.cpp b/modules/gui/qt4/components/playlist/ml_item.cpp
index 3dd7db9..7c17b74 100644
--- a/modules/gui/qt4/components/playlist/ml_item.cpp
+++ b/modules/gui/qt4/components/playlist/ml_item.cpp
@@ -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
diff --git a/modules/gui/qt4/components/playlist/ml_item.hpp b/modules/gui/qt4/components/playlist/ml_item.hpp
index 6c781f4..03ebd5a 100644
--- a/modules/gui/qt4/components/playlist/ml_item.hpp
+++ b/modules/gui/qt4/components/playlist/ml_item.hpp
@@ -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 );
diff --git a/modules/gui/qt4/components/playlist/ml_model.cpp b/modules/gui/qt4/components/playlist/ml_model.cpp
index 8680939..607d94d 100644
--- a/modules/gui/qt4/components/playlist/ml_model.cpp
+++ b/modules/gui/qt4/components/playlist/ml_model.cpp
@@ -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;
diff --git a/modules/gui/qt4/components/playlist/ml_model.hpp b/modules/gui/qt4/components/playlist/ml_model.hpp
index 17bafc1..10e5e52 100644
--- a/modules/gui/qt4/components/playlist/ml_model.hpp
+++ b/modules/gui/qt4/components/playlist/ml_model.hpp
@@ -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;
diff --git a/modules/gui/qt4/util/pictureflow.cpp b/modules/gui/qt4/util/pictureflow.cpp
index acb079b..4325491 100644
--- a/modules/gui/qt4/util/pictureflow.cpp
+++ b/modules/gui/qt4/util/pictureflow.cpp
@@ -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 );
More information about the vlc-commits
mailing list