/src/libtomahawk/jobview/JobStatusModel.h

http://github.com/tomahawk-player/tomahawk · C Header · 101 lines · 62 code · 19 blank · 20 comment · 0 complexity · 99250c40382355d3495b75e9195fa7f6 MD5 · raw file

  1. /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
  2. *
  3. * Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
  4. *
  5. * Tomahawk is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * Tomahawk is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef JOBSTATUSMODEL_H
  19. #define JOBSTATUSMODEL_H
  20. #include "DllMacro.h"
  21. #include <QModelIndex>
  22. #include <QSortFilterProxyModel>
  23. #include <QQueue>
  24. class QStyledItemDelegate;
  25. class JobStatusItem;
  26. class DLLEXPORT JobStatusModel : public QAbstractListModel
  27. {
  28. Q_OBJECT
  29. public:
  30. enum JobRoles {
  31. // DecorationRole is icon
  32. // DisplayRole is main col
  33. RightColumnRole = Qt::UserRole + 1,
  34. AllowMultiLineRole = Qt::UserRole + 2,
  35. JobDataRole = Qt::UserRole + 3,
  36. SortRole = Qt::UserRole + 4,
  37. AgeRole = Qt::UserRole + 5
  38. };
  39. explicit JobStatusModel( QObject* parent = 0 );
  40. virtual ~JobStatusModel();
  41. virtual Qt::ItemFlags flags( const QModelIndex& index ) const;
  42. virtual QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const;
  43. virtual int rowCount( const QModelIndex& parent = QModelIndex() ) const;
  44. signals:
  45. void customDelegateJobInserted( int row, JobStatusItem* item );
  46. void customDelegateJobRemoved( int row );
  47. void refreshDelegates();
  48. public slots:
  49. /// Takes ownership of job
  50. void addJob( JobStatusItem* item );
  51. private slots:
  52. void itemUpdated();
  53. void itemFinished();
  54. private:
  55. QList< JobStatusItem* > m_items;
  56. QHash< QString, QList< JobStatusItem* > > m_collapseCount;
  57. QHash< QString, QQueue< JobStatusItem* > > m_jobQueue;
  58. QHash< QString, int > m_jobTypeCount;
  59. };
  60. class DLLEXPORT JobStatusSortModel : public QSortFilterProxyModel
  61. {
  62. Q_OBJECT
  63. public:
  64. JobStatusSortModel( QObject* parent = 0 );
  65. virtual ~JobStatusSortModel();
  66. void setJobModel( JobStatusModel* model );
  67. signals:
  68. void checkCount();
  69. void customDelegateJobInserted( int row, JobStatusItem* item );
  70. void customDelegateJobRemoved( int row );
  71. void refreshDelegates();
  72. public slots:
  73. void addJob( JobStatusItem* item );
  74. void customDelegateJobInsertedSlot( int row, JobStatusItem* item);
  75. void customDelegateJobRemovedSlot( int row );
  76. void refreshDelegatesSlot();
  77. protected:
  78. virtual bool lessThan( const QModelIndex & left, const QModelIndex & right ) const;
  79. private:
  80. JobStatusModel* m_sourceModel;
  81. };
  82. #endif // JOBSTATUSMODEL_H