Commit 968dd88a authored by Jakob Leben's avatar Jakob Leben Committed by Rémi Denis-Courmont

Qt4 Playlist: Disable dropping on non-container items

New protected field bool PLItem::b_is_node to have the data at hand.
Then only check this field in PLModel::flags().
Signed-off-by: default avatarRémi Denis-Courmont <remi@remlab.net>
parent 0ce4275a
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
*/ */
void PLItem::init( int _i_id, int _i_input_id, PLItem *parent, PLModel *m, QSettings *settings ) void PLItem::init( int _i_id, int _i_input_id, bool _is_node, PLItem *parent, PLModel *m, QSettings *settings )
{ {
parentItem = parent; /* Can be NULL, but only for the rootItem */ parentItem = parent; /* Can be NULL, but only for the rootItem */
i_id = _i_id; /* Playlist item specific id */ i_id = _i_id; /* Playlist item specific id */
...@@ -56,6 +56,7 @@ void PLItem::init( int _i_id, int _i_input_id, PLItem *parent, PLModel *m, QSett ...@@ -56,6 +56,7 @@ void PLItem::init( int _i_id, int _i_input_id, PLItem *parent, PLModel *m, QSett
model = m; /* PLModel (QAbsmodel) */ model = m; /* PLModel (QAbsmodel) */
i_type = -1; /* Item type - Avoid segfault */ i_type = -1; /* Item type - Avoid segfault */
b_current = false; /* Is the item the current Item or not */ b_current = false; /* Is the item the current Item or not */
b_is_node = _is_node;
assert( model ); /* We need a model */ assert( model ); /* We need a model */
...@@ -91,19 +92,21 @@ void PLItem::init( int _i_id, int _i_input_id, PLItem *parent, PLModel *m, QSett ...@@ -91,19 +92,21 @@ void PLItem::init( int _i_id, int _i_input_id, PLItem *parent, PLModel *m, QSett
Call the above function init Call the above function init
So far the first constructor isn't used... So far the first constructor isn't used...
*/ */
PLItem::PLItem( int _i_id, int _i_input_id, PLItem *parent, PLModel *m ) PLItem::PLItem( int _i_id, int _i_input_id, bool _is_node, PLItem *parent, PLModel *m )
{ {
init( _i_id, _i_input_id, parent, m, NULL ); init( _i_id, _i_input_id, _is_node, parent, m, NULL );
} }
PLItem::PLItem( playlist_item_t * p_item, PLItem *parent, PLModel *m ) PLItem::PLItem( playlist_item_t * p_item, PLItem *parent, PLModel *m )
{ {
init( p_item->i_id, p_item->p_input->i_id, parent, m, NULL ); init( p_item->i_id, p_item->p_input->i_id, p_item->i_children > -1,
parent, m, NULL );
} }
PLItem::PLItem( playlist_item_t * p_item, QSettings *settings, PLModel *m ) PLItem::PLItem( playlist_item_t * p_item, QSettings *settings, PLModel *m )
{ {
init( p_item->i_id, p_item->p_input->i_id, NULL, m, settings ); init( p_item->i_id, p_item->p_input->i_id, p_item->i_children > -1,
NULL, m, settings );
} }
PLItem::~PLItem() PLItem::~PLItem()
...@@ -174,6 +177,7 @@ void PLItem::update( playlist_item_t *p_item, bool iscurrent ) ...@@ -174,6 +177,7 @@ void PLItem::update( playlist_item_t *p_item, bool iscurrent )
/* Useful for the model */ /* Useful for the model */
i_type = p_item->p_input->i_type; i_type = p_item->p_input->i_type;
b_current = iscurrent; b_current = iscurrent;
b_is_node = p_item->i_children > -1;
item_col_strings.clear(); item_col_strings.clear();
......
...@@ -40,7 +40,7 @@ class PLItem ...@@ -40,7 +40,7 @@ class PLItem
{ {
friend class PLModel; friend class PLModel;
public: public:
PLItem( int, int, PLItem *parent , PLModel * ); PLItem( int, int, bool, PLItem *parent , PLModel * );
PLItem( playlist_item_t *, PLItem *parent, PLModel * ); PLItem( playlist_item_t *, PLItem *parent, PLModel * );
PLItem( playlist_item_t *, QSettings *, PLModel * ); PLItem( playlist_item_t *, QSettings *, PLModel * );
~PLItem(); ~PLItem();
...@@ -72,9 +72,10 @@ protected: ...@@ -72,9 +72,10 @@ protected:
int i_id; int i_id;
int i_input_id; int i_input_id;
int i_showflags; int i_showflags;
bool b_is_node;
private: private:
void init( int, int, PLItem *, PLModel *, QSettings * ); void init( int, int, bool, PLItem *, PLModel *, QSettings * );
void updateColumnHeaders(); void updateColumnHeaders();
PLItem *parentItem; PLItem *parentItem;
PLModel *model; PLModel *model;
......
...@@ -117,7 +117,12 @@ Qt::ItemFlags PLModel::flags( const QModelIndex &index ) const ...@@ -117,7 +117,12 @@ Qt::ItemFlags PLModel::flags( const QModelIndex &index ) const
{ {
Qt::ItemFlags defaultFlags = QAbstractItemModel::flags( index ); Qt::ItemFlags defaultFlags = QAbstractItemModel::flags( index );
if( index.isValid() ) if( index.isValid() )
return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags; {
PLItem *item = static_cast<PLItem*>( index.internalPointer() );
if ( item->b_is_node )
defaultFlags |= Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
else defaultFlags |= Qt::ItemIsDragEnabled;
}
else if ( rootItem->i_id != p_playlist->p_root_onelevel->i_id else if ( rootItem->i_id != p_playlist->p_root_onelevel->i_id
&& rootItem->i_id != p_playlist->p_root_category->i_id ) && rootItem->i_id != p_playlist->p_root_category->i_id )
defaultFlags |= Qt::ItemIsDropEnabled; defaultFlags |= Qt::ItemIsDropEnabled;
......
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