]> git.sesse.net Git - vlc/commitdiff
Qt4 Playlist: Disable dropping on non-container items
authorJakob Leben <jakob.leben@gmail.com>
Sun, 2 Aug 2009 14:57:50 +0000 (16:57 +0200)
committerRémi Denis-Courmont <remi@remlab.net>
Sat, 8 Aug 2009 17:16:44 +0000 (20:16 +0300)
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: Rémi Denis-Courmont <remi@remlab.net>
modules/gui/qt4/components/playlist/playlist_item.cpp
modules/gui/qt4/components/playlist/playlist_item.hpp
modules/gui/qt4/components/playlist/playlist_model.cpp

index 0edde6a5f91c338b4de5c1333dd0fb0bfc70b3e1..b0436f0e1e2e6d783bdac00e82a76d423b65b4db 100644 (file)
@@ -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 */
     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
     model      = m;               /* PLModel (QAbsmodel) */
     i_type     = -1;              /* Item type - Avoid segfault */
     b_current  = false;           /* Is the item the current Item or not */
+    b_is_node = _is_node;
 
     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
    Call the above function init
    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 )
 {
-    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 )
 {
-    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()
@@ -174,6 +177,7 @@ void PLItem::update( playlist_item_t *p_item, bool iscurrent )
     /* Useful for the model */
     i_type = p_item->p_input->i_type;
     b_current = iscurrent;
+    b_is_node = p_item->i_children > -1;
 
     item_col_strings.clear();
 
index 26ce13c5896f43ed103757b7caf31b1befe809df..c9d186b3b2307f18b0fc15e52cd27ad5b7bf7aeb 100644 (file)
@@ -40,7 +40,7 @@ class PLItem
 {
     friend class PLModel;
 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 *, QSettings *, PLModel * );
     ~PLItem();
@@ -72,9 +72,10 @@ protected:
     int i_id;
     int i_input_id;
     int i_showflags;
+    bool b_is_node;
 
 private:
-    void init( int, int, PLItem *, PLModel *, QSettings * );
+    void init( int, int, bool, PLItem *, PLModel *, QSettings * );
     void updateColumnHeaders();
     PLItem *parentItem;
     PLModel *model;
index d2fc147814460eec8ebe09af1047f9df546d744a..2288e72440914db740a27640a3a73322e79297ab 100644 (file)
@@ -117,7 +117,12 @@ Qt::ItemFlags PLModel::flags( const QModelIndex &index ) const
 {
     Qt::ItemFlags defaultFlags = QAbstractItemModel::flags( index );
     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
           && rootItem->i_id != p_playlist->p_root_category->i_id )
               defaultFlags |= Qt::ItemIsDropEnabled;