1 #include "channelsmodel.h"
3 #include "mainwindow.h"
5 ChannelsModel::ChannelsModel(QObject *parent) : QSqlQueryModel(parent) {
9 QVariant ChannelsModel::data(const QModelIndex &index, int role) const {
15 case ChannelsModel::ItemTypeRole:
16 return ChannelsModel::ItemChannel;
19 case ChannelsModel::DataObjectRole:
20 user = userForIndex(index);
21 return QVariant::fromValue(QPointer<YTUser>(user));
24 case ChannelsModel::HoveredItemRole:
25 return hoveredRow == index.row();
28 case Qt::StatusTipRole:
29 user = userForIndex(index);
30 return user->getDescription();
37 YTUser* ChannelsModel::userForIndex(const QModelIndex &index) const {
38 return YTUser::forId(QSqlQueryModel::data(QSqlQueryModel::index(index.row(), 0)).toString());
41 void ChannelsModel::setHoveredRow(int row) {
42 int oldRow = hoveredRow;
44 emit dataChanged( createIndex( oldRow, 0 ), createIndex( oldRow, columnCount() - 1 ) );
45 emit dataChanged( createIndex( hoveredRow, 0 ), createIndex( hoveredRow, columnCount() - 1 ) );
48 void ChannelsModel::clearHover() {
49 emit dataChanged( createIndex( hoveredRow, 0 ), createIndex( hoveredRow, columnCount() - 1 ) );
53 // --- Sturm und drang ---
56 Qt::DropActions ChannelsModel::supportedDragActions() const {
57 return Qt::CopyAction;
60 Qt::DropActions ChannelsModel::supportedDropActions() const {
61 return Qt::CopyAction;
64 Qt::ItemFlags ChannelsModel::flags(const QModelIndex &index) const {
66 return Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
70 QStringList ChannelsModel::mimeTypes() const {
72 types << "x-minitube/channel";
76 QMimeData* ChannelsModel::mimeData( const QModelIndexList &indexes ) const {
79 UserMimeData* mime = new TrackMimeData();
81 foreach( const QModelIndex &index, indexes ) {
82 Item *item = userForIndex(index);
84 mime->addTracks(item->getTracks());