PageRenderTime 46ms CodeModel.GetById 29ms app.highlight 15ms RepoModel.GetById 1ms app.codeStats 0ms

/src/sourcetree/items/sourcetreeitem.cpp

http://github.com/tomahawk-player/tomahawk
C++ | 246 lines | 165 code | 63 blank | 18 comment | 2 complexity | 856bce68378036ee6c2f539b5f19cac4 MD5 | raw file
  1/*
  2    Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
  3
  4    This program is free software; you can redistribute it and/or modify
  5    it under the terms of the GNU General Public License as published by
  6    the Free Software Foundation; either version 2 of the License, or
  7    (at your option) any later version.
  8
  9    This program is distributed in the hope that it will be useful,
 10    but WITHOUT ANY WARRANTY; without even the implied warranty of
 11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 12    GNU General Public License for more details.
 13
 14    You should have received a copy of the GNU General Public License along
 15    with this program; if not, write to the Free Software Foundation, Inc.,
 16    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 17*/
 18
 19#include "SourceTreeItem.h"
 20
 21#include "utils/Logger.h"
 22
 23using namespace Tomahawk;
 24
 25
 26SourceTreeItem::SourceTreeItem( SourcesModel* model, SourceTreeItem* parent, SourcesModel::RowType thisType, int peerSortValue, int index )
 27    : QObject()
 28    , m_type( thisType )
 29    , m_parent( parent )
 30    , m_model( model )
 31    , m_peerSortValue( peerSortValue )
 32{
 33    connect( this, SIGNAL( beginChildRowsAdded( int, int ) ), m_model, SLOT( onItemRowsAddedBegin( int, int ) ) );
 34    connect( this, SIGNAL( beginChildRowsRemoved( int, int ) ), m_model, SLOT( onItemRowsRemovedBegin( int, int ) ) );
 35    connect( this, SIGNAL( childRowsAdded() ), m_model, SLOT( onItemRowsAddedDone() ) );
 36    connect( this, SIGNAL( childRowsRemoved() ), m_model, SLOT( onItemRowsRemovedDone() ) );
 37    connect( this, SIGNAL( updated() ), m_model, SLOT( itemUpdated() ) );
 38    connect( this, SIGNAL( selectRequest( SourceTreeItem* ) ), m_model, SLOT( itemSelectRequest( SourceTreeItem* ) ) );
 39    connect( this, SIGNAL( expandRequest( SourceTreeItem* ) ), m_model, SLOT( itemExpandRequest( SourceTreeItem* ) ) );
 40    connect( this, SIGNAL( toggleExpandRequest( SourceTreeItem* ) ), m_model, SLOT( itemToggleExpandRequest( SourceTreeItem* ) ) );
 41
 42    if ( !m_parent )
 43        return;
 44
 45    // caller must call begin/endInsertRows
 46    if ( index < 0 )
 47        m_parent->appendChild( this );
 48    else
 49        m_parent->insertChild( index, this );
 50}
 51
 52
 53SourceTreeItem::~SourceTreeItem()
 54{
 55    qDeleteAll( m_children );
 56}
 57
 58
 59SourcesModel::RowType
 60SourceTreeItem::type() const
 61{
 62    return m_type;
 63}
 64
 65
 66SourceTreeItem*
 67SourceTreeItem::parent() const
 68{
 69    return m_parent;
 70}
 71
 72
 73SourcesModel*
 74SourceTreeItem::model() const
 75{
 76    return m_model;
 77}
 78
 79
 80QList< SourceTreeItem* >
 81SourceTreeItem::children() const
 82{
 83    return m_children;
 84}
 85
 86
 87void
 88SourceTreeItem::appendChild(SourceTreeItem* item)
 89{
 90    m_children.append( item );
 91}
 92
 93
 94void
 95SourceTreeItem::insertChild(int index, SourceTreeItem* item)
 96{
 97    m_children.insert( index, item );
 98}
 99
100
101void
102SourceTreeItem::removeChild(SourceTreeItem* item)
103{
104    m_children.removeAll( item );
105}
106
107
108QString
109SourceTreeItem::text() const
110{
111    return QString();
112}
113
114
115QString
116SourceTreeItem::tooltip() const
117{
118    return QString();
119}
120
121
122Qt::ItemFlags
123SourceTreeItem::flags() const
124{
125    return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
126}
127
128
129QIcon
130SourceTreeItem::icon() const
131{
132    return QIcon();
133}
134
135
136bool
137SourceTreeItem::willAcceptDrag(const QMimeData*) const
138{
139    return false;
140}
141
142
143bool
144SourceTreeItem::dropMimeData(const QMimeData*, Qt::DropAction)
145{
146    return false;
147}
148
149
150bool
151SourceTreeItem::setData(const QVariant&, bool)
152{
153    return false;
154}
155
156
157int
158SourceTreeItem::peerSortValue() const
159{
160    return m_peerSortValue;
161}
162
163
164int
165SourceTreeItem::IDValue() const
166{
167    return 0;
168}
169
170
171SourceTreeItem::DropTypes
172SourceTreeItem::supportedDropTypes(const QMimeData* mimeData) const
173{
174    Q_UNUSED( mimeData );
175    return DropTypesNone;
176}
177
178
179void
180SourceTreeItem::setDropType(SourceTreeItem::DropType type)
181{
182    m_dropType = type;
183}
184
185
186SourceTreeItem::DropType
187SourceTreeItem::dropType() const
188{
189    return m_dropType;
190}
191
192
193bool
194SourceTreeItem::isBeingPlayed() const
195{
196    return false;
197}
198
199
200QList< QAction* >
201SourceTreeItem::customActions() const
202{
203    return QList< QAction* >();
204}
205
206
207void
208SourceTreeItem::beginRowsAdded(int from, int to)
209{
210    emit beginChildRowsAdded( from, to );
211}
212
213
214void
215SourceTreeItem::endRowsAdded()
216{
217    emit childRowsAdded();
218}
219
220
221void
222SourceTreeItem::beginRowsRemoved(int from, int to)
223{
224    emit beginChildRowsRemoved( from, to );
225}
226
227
228void
229SourceTreeItem::endRowsRemoved()
230{
231    emit childRowsRemoved();
232}
233
234
235void
236SourceTreeItem::setRowType(SourcesModel::RowType t)
237{
238    m_type = t;
239}
240
241
242void
243SourceTreeItem::setParentItem(SourceTreeItem* item)
244{
245    m_parent = item;
246}