[vlc-devel] commit: Qt4 Playlist: Disable dropping on non-container items (Jakob Leben )

git version control git at videolan.org
Thu Aug 13 17:23:32 CEST 2009


vlc | branch: 1.0-bugfix | Jakob Leben <jakob.leben at gmail.com> | Sun Aug  2 16:57:50 2009 +0200| [c10bdb0712b9dcb42c459927609f2c8bbba6bd40] | committer: 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: Rémi Denis-Courmont <remi at remlab.net>
(cherry picked from commit 968dd88aac2c29dc31bd6ce08f3f4a77a87f166e)

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=c10bdb0712b9dcb42c459927609f2c8bbba6bd40
---

 .../gui/qt4/components/playlist/playlist_item.cpp  |   14 +++++++++-----
 .../gui/qt4/components/playlist/playlist_item.hpp  |    5 +++--
 .../gui/qt4/components/playlist/playlist_model.cpp |    7 ++++++-
 3 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/modules/gui/qt4/components/playlist/playlist_item.cpp b/modules/gui/qt4/components/playlist/playlist_item.cpp
index 0edde6a..b0436f0 100644
--- a/modules/gui/qt4/components/playlist/playlist_item.cpp
+++ b/modules/gui/qt4/components/playlist/playlist_item.cpp
@@ -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();
 
diff --git a/modules/gui/qt4/components/playlist/playlist_item.hpp b/modules/gui/qt4/components/playlist/playlist_item.hpp
index 26ce13c..c9d186b 100644
--- a/modules/gui/qt4/components/playlist/playlist_item.hpp
+++ b/modules/gui/qt4/components/playlist/playlist_item.hpp
@@ -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;
diff --git a/modules/gui/qt4/components/playlist/playlist_model.cpp b/modules/gui/qt4/components/playlist/playlist_model.cpp
index add3ddc..9a28d42 100644
--- a/modules/gui/qt4/components/playlist/playlist_model.cpp
+++ b/modules/gui/qt4/components/playlist/playlist_model.cpp
@@ -119,7 +119,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;




More information about the vlc-devel mailing list