Qt: correctly display the right treeView columns
[vlc.git] / modules / gui / qt4 / components / playlist / playlist_item.cpp
blobcb9bde33516742bab4e0a699a597e97b526bd014
1 /*****************************************************************************
2 * playlist_item.cpp : Manage playlist item
3 ****************************************************************************
4 * Copyright © 2006-2011 the VideoLAN team
5 * $Id$
7 * Authors: Clément Stenac <zorglub@videolan.org>
8 * Jean-Baptiste Kempf <jb@videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
29 #include <assert.h>
31 #include "qt4.hpp"
32 #include "playlist_item.hpp"
34 #include "sorting.h"
36 /*************************************************************************
37 * Playlist item implementation
38 *************************************************************************/
41 Playlist item is just a wrapper, an abstraction of the playlist_item
42 in order to be managed by PLModel
44 PLItem have a parent, and id and a input Id
47 void PLItem::init( playlist_item_t *_playlist_item, PLItem *parent )
49 parentItem = parent; /* Can be NULL, but only for the rootItem */
50 i_id = _playlist_item->i_id; /* Playlist item specific id */
51 p_input = _playlist_item->p_input;
52 vlc_gc_incref( p_input );
56 Constructors
57 Call the above function init
59 PLItem::PLItem( playlist_item_t *p_item, PLItem *parent )
61 init( p_item, parent );
64 PLItem::PLItem( playlist_item_t * p_item )
66 init( p_item, NULL );
69 PLItem::~PLItem()
71 vlc_gc_decref( p_input );
72 qDeleteAll( children );
73 children.clear();
76 void PLItem::insertChild( PLItem *item, int i_pos )
78 children.insert( i_pos, item );
81 void PLItem::appendChild( PLItem *item )
83 children.insert( children.count(), item );
86 void PLItem::removeChild( PLItem *item )
88 children.removeOne( item );
89 delete item;
92 void PLItem::removeChildren()
94 qDeleteAll( children );
95 children.clear();
98 void PLItem::takeChildAt( int index )
100 PLItem *child = children[index];
101 child->parentItem = NULL;
102 children.removeAt( index );
105 /* This function is used to get one's parent's row number in the model */
106 int PLItem::row() const
108 if( parentItem )
109 return parentItem->children.indexOf( const_cast<PLItem*>(this) );
110 // We don't ever inherit PLItem, yet, but it might come :D
111 return 0;
114 bool PLItem::operator< ( PLItem& other )
116 PLItem *item1 = this;
117 while( item1->parentItem )
119 PLItem *item2 = &other;
120 while( item2->parentItem )
122 if( item1 == item2->parentItem ) return true;
123 if( item2 == item1->parentItem ) return false;
124 if( item1->parentItem == item2->parentItem )
125 return item1->parentItem->children.indexOf( item1 ) <
126 item1->parentItem->children.indexOf( item2 );
127 item2 = item2->parentItem;
129 item1 = item1->parentItem;
131 return false;