Commit 856d5fe0 authored by Francois Cartegnie's avatar Francois Cartegnie

Qt: PLModel: Use Model Indexes instead of PLItem references for external

methods.

The model/view is broken as the internal PLItem elements are accessed
from outside the model.
We need to change calls to make use of Model Indexes, and then can move
away some methods that belongs to views.
parent c6a5ad0b
...@@ -280,17 +280,7 @@ void LocationBar::setIndex( const QModelIndex &index ) ...@@ -280,17 +280,7 @@ void LocationBar::setIndex( const QModelIndex &index )
while( true ) while( true )
{ {
PLItem *item = model->getItem( i ); QString text = model->getTitle( i );
QString text;
char *fb_name = input_item_GetTitle( item->inputItem() );
if( EMPTY_STR( fb_name ) )
{
free( fb_name );
fb_name = input_item_GetName( item->inputItem() );
}
text = qfu(fb_name);
free(fb_name);
QAbstractButton *btn = new LocationButton( text, first, !first, this ); QAbstractButton *btn = new LocationButton( text, first, !first, this );
btn->setSizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed ); btn->setSizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
...@@ -300,7 +290,7 @@ void LocationBar::setIndex( const QModelIndex &index ) ...@@ -300,7 +290,7 @@ void LocationBar::setIndex( const QModelIndex &index )
actions.append( action ); actions.append( action );
CONNECT( btn, clicked(), action, trigger() ); CONNECT( btn, clicked(), action, trigger() );
mapper->setMapping( action, item->id() ); mapper->setMapping( action, model->itemId( i ) );
CONNECT( action, triggered(), mapper, map() ); CONNECT( action, triggered(), mapper, map() );
first = false; first = false;
......
...@@ -34,8 +34,11 @@ class PLItem ...@@ -34,8 +34,11 @@ class PLItem
{ {
friend class PLModel; friend class PLModel;
public: public:
PLItem( playlist_item_t *, PLItem *parent );
~PLItem(); ~PLItem();
bool hasSameParent( PLItem *other ) { return parent() == other->parent(); }
bool operator< ( PLItem& );
protected:
PLItem( playlist_item_t *, PLItem *parent );
int row() const; int row() const;
...@@ -51,9 +54,7 @@ public: ...@@ -51,9 +54,7 @@ public:
PLItem *parent() { return parentItem; } PLItem *parent() { return parentItem; }
input_item_t *inputItem() const { return p_input; } input_item_t *inputItem() const { return p_input; }
int id() { return i_id; } int id() { return i_id; }
bool operator< ( PLItem& );
protected:
QList<PLItem*> children; QList<PLItem*> children;
PLItem *parentItem; PLItem *parentItem;
int i_id; int i_id;
......
...@@ -98,8 +98,19 @@ public: ...@@ -98,8 +98,19 @@ public:
/* Lookups */ /* Lookups */
QModelIndex index( const int i_id, const int c ); QModelIndex index( const int i_id, const int c );
QModelIndex rootIndex() const;
bool isTree() const;
bool canEdit() const;
virtual QModelIndex currentIndex() const; virtual QModelIndex currentIndex() const;
int itemId( const QModelIndex &index ) const; int itemId( const QModelIndex &index ) const;
QString getURI( const QModelIndex &index ) const;
QString getTitle( const QModelIndex &index ) const;
enum playLocation
{
IN_PLAYLIST,
IN_MEDIALIBRARY
};
bool isCurrentItem( const QModelIndex &index, playLocation where ) const;
/* */ /* */
void search( const QString& search_text, const QModelIndex & root, bool b_recursive ); void search( const QString& search_text, const QModelIndex & root, bool b_recursive );
...@@ -109,13 +120,6 @@ public: ...@@ -109,13 +120,6 @@ public:
virtual bool popup( const QModelIndex & index, const QPoint &point, const QModelIndexList &list ); virtual bool popup( const QModelIndex & index, const QPoint &point, const QModelIndexList &list );
virtual void doDelete( QModelIndexList selected ); virtual void doDelete( QModelIndexList selected );
PLItem *getItem( const QModelIndex & index ) const
{
if( index.isValid() )
return static_cast<PLItem*>( index.internalPointer() );
else return rootItem;
}
signals: signals:
void currentIndexChanged( const QModelIndex& ); void currentIndexChanged( const QModelIndex& );
void rootIndexChanged(); void rootIndexChanged();
...@@ -144,6 +148,12 @@ private: ...@@ -144,6 +148,12 @@ private:
/* Custom model private methods */ /* Custom model private methods */
/* Lookups */ /* Lookups */
PLItem *getItem( const QModelIndex & index ) const
{
if( index.isValid() )
return static_cast<PLItem*>( index.internalPointer() );
else return rootItem;
}
QStringList selectedURIs(); QStringList selectedURIs();
QModelIndex index( PLItem *, const int c ) const; QModelIndex index( PLItem *, const int c ) const;
bool isCurrent( const QModelIndex &index ) const; bool isCurrent( const QModelIndex &index ) const;
...@@ -165,10 +175,10 @@ private: ...@@ -165,10 +175,10 @@ private:
void dropMove( const PlMimeData * data, PLItem *target, int new_pos ); void dropMove( const PlMimeData * data, PLItem *target, int new_pos );
/* */ /* */
void sort( const int i_root_id, const int column, Qt::SortOrder order ); void sort( QModelIndex rootIndex, const int column, Qt::SortOrder order );
/* Popup */ /* Popup */
int i_popup_item, i_popup_parent; QModelIndex popupLauncherIndex;
QModelIndexList current_selection; QModelIndexList current_selection;
QMenu *sortingMenu; QMenu *sortingMenu;
QSignalMapper *sortingMapper; QSignalMapper *sortingMapper;
...@@ -177,7 +187,6 @@ private: ...@@ -177,7 +187,6 @@ private:
PLItem *findById( PLItem *, int ) const; PLItem *findById( PLItem *, int ) const;
PLItem *findByInput( PLItem *, int ) const; PLItem *findByInput( PLItem *, int ) const;
PLItem *findInner(PLItem *, int , bool ) const; PLItem *findInner(PLItem *, int , bool ) const;
bool canEdit() const;
PLItem *p_cached_item; PLItem *p_cached_item;
PLItem *p_cached_item_bi; PLItem *p_cached_item_bi;
......
...@@ -502,9 +502,7 @@ QRect PictureFlowSoftwareRenderer::renderSlide(const SlideInfo &slide, int col1, ...@@ -502,9 +502,7 @@ QRect PictureFlowSoftwareRenderer::renderSlide(const SlideInfo &slide, int col1,
index = ((PLModel*)state->model)->index( slide.slideIndex, 0, state->model->currentIndex().parent() ); index = ((PLModel*)state->model)->index( slide.slideIndex, 0, state->model->currentIndex().parent() );
if( !index.isValid() ) if( !index.isValid() )
return QRect(); return QRect();
artURL = plm->data( index, COLUMN_COVER ).toString();
PLItem *item = static_cast<PLItem*>( index.internalPointer() );
artURL = InputManager::decodeArtURL( item->inputItem() );
} }
#ifdef MEDIA_LIBRARY #ifdef MEDIA_LIBRARY
else if( mlm != 0 ) else if( mlm != 0 )
......
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