/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. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License along
  12. with this program; if not, write to the Free Software Foundation, Inc.,
  13. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  14. */
  15. #include "SourceTreeItem.h"
  16. #include "utils/Logger.h"
  17. using namespace Tomahawk;
  18. SourceTreeItem::SourceTreeItem( SourcesModel* model, SourceTreeItem* parent, SourcesModel::RowType thisType, int peerSortValue, int index )
  19. : QObject()
  20. , m_type( thisType )
  21. , m_parent( parent )
  22. , m_model( model )
  23. , m_peerSortValue( peerSortValue )
  24. {
  25. connect( this, SIGNAL( beginChildRowsAdded( int, int ) ), m_model, SLOT( onItemRowsAddedBegin( int, int ) ) );
  26. connect( this, SIGNAL( beginChildRowsRemoved( int, int ) ), m_model, SLOT( onItemRowsRemovedBegin( int, int ) ) );
  27. connect( this, SIGNAL( childRowsAdded() ), m_model, SLOT( onItemRowsAddedDone() ) );
  28. connect( this, SIGNAL( childRowsRemoved() ), m_model, SLOT( onItemRowsRemovedDone() ) );
  29. connect( this, SIGNAL( updated() ), m_model, SLOT( itemUpdated() ) );
  30. connect( this, SIGNAL( selectRequest( SourceTreeItem* ) ), m_model, SLOT( itemSelectRequest( SourceTreeItem* ) ) );
  31. connect( this, SIGNAL( expandRequest( SourceTreeItem* ) ), m_model, SLOT( itemExpandRequest( SourceTreeItem* ) ) );
  32. connect( this, SIGNAL( toggleExpandRequest( SourceTreeItem* ) ), m_model, SLOT( itemToggleExpandRequest( SourceTreeItem* ) ) );
  33. if ( !m_parent )
  34. return;
  35. // caller must call begin/endInsertRows
  36. if ( index < 0 )
  37. m_parent->appendChild( this );
  38. else
  39. m_parent->insertChild( index, this );
  40. }
  41. SourceTreeItem::~SourceTreeItem()
  42. {
  43. qDeleteAll( m_children );
  44. }
  45. SourcesModel::RowType
  46. SourceTreeItem::type() const
  47. {
  48. return m_type;
  49. }
  50. SourceTreeItem*
  51. SourceTreeItem::parent() const
  52. {
  53. return m_parent;
  54. }
  55. SourcesModel*
  56. SourceTreeItem::model() const
  57. {
  58. return m_model;
  59. }
  60. QList< SourceTreeItem* >
  61. SourceTreeItem::children() const
  62. {
  63. return m_children;
  64. }
  65. void
  66. SourceTreeItem::appendChild(SourceTreeItem* item)
  67. {
  68. m_children.append( item );
  69. }
  70. void
  71. SourceTreeItem::insertChild(int index, SourceTreeItem* item)
  72. {
  73. m_children.insert( index, item );
  74. }
  75. void
  76. SourceTreeItem::removeChild(SourceTreeItem* item)
  77. {
  78. m_children.removeAll( item );
  79. }
  80. QString
  81. SourceTreeItem::text() const
  82. {
  83. return QString();
  84. }
  85. QString
  86. SourceTreeItem::tooltip() const
  87. {
  88. return QString();
  89. }
  90. Qt::ItemFlags
  91. SourceTreeItem::flags() const
  92. {
  93. return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
  94. }
  95. QIcon
  96. SourceTreeItem::icon() const
  97. {
  98. return QIcon();
  99. }
  100. bool
  101. SourceTreeItem::willAcceptDrag(const QMimeData*) const
  102. {
  103. return false;
  104. }
  105. bool
  106. SourceTreeItem::dropMimeData(const QMimeData*, Qt::DropAction)
  107. {
  108. return false;
  109. }
  110. bool
  111. SourceTreeItem::setData(const QVariant&, bool)
  112. {
  113. return false;
  114. }
  115. int
  116. SourceTreeItem::peerSortValue() const
  117. {
  118. return m_peerSortValue;
  119. }
  120. int
  121. SourceTreeItem::IDValue() const
  122. {
  123. return 0;
  124. }
  125. SourceTreeItem::DropTypes
  126. SourceTreeItem::supportedDropTypes(const QMimeData* mimeData) const
  127. {
  128. Q_UNUSED( mimeData );
  129. return DropTypesNone;
  130. }
  131. void
  132. SourceTreeItem::setDropType(SourceTreeItem::DropType type)
  133. {
  134. m_dropType = type;
  135. }
  136. SourceTreeItem::DropType
  137. SourceTreeItem::dropType() const
  138. {
  139. return m_dropType;
  140. }
  141. bool
  142. SourceTreeItem::isBeingPlayed() const
  143. {
  144. return false;
  145. }
  146. QList< QAction* >
  147. SourceTreeItem::customActions() const
  148. {
  149. return QList< QAction* >();
  150. }
  151. void
  152. SourceTreeItem::beginRowsAdded(int from, int to)
  153. {
  154. emit beginChildRowsAdded( from, to );
  155. }
  156. void
  157. SourceTreeItem::endRowsAdded()
  158. {
  159. emit childRowsAdded();
  160. }
  161. void
  162. SourceTreeItem::beginRowsRemoved(int from, int to)
  163. {
  164. emit beginChildRowsRemoved( from, to );
  165. }
  166. void
  167. SourceTreeItem::endRowsRemoved()
  168. {
  169. emit childRowsRemoved();
  170. }
  171. void
  172. SourceTreeItem::setRowType(SourcesModel::RowType t)
  173. {
  174. m_type = t;
  175. }
  176. void
  177. SourceTreeItem::setParentItem(SourceTreeItem* item)
  178. {
  179. m_parent = item;
  180. }