PageRenderTime 216ms CodeModel.GetById 81ms app.highlight 6ms RepoModel.GetById 74ms app.codeStats 0ms

/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
 19#ifndef JOBSTATUSMODEL_H
 20#define JOBSTATUSMODEL_H
 21
 22#include "DllMacro.h"
 23
 24#include <QModelIndex>
 25#include <QSortFilterProxyModel>
 26#include <QQueue>
 27
 28class QStyledItemDelegate;
 29class JobStatusItem;
 30
 31class DLLEXPORT JobStatusModel : public QAbstractListModel
 32{
 33    Q_OBJECT
 34public:
 35    enum JobRoles {
 36        // DecorationRole is icon
 37        // DisplayRole is main col
 38        RightColumnRole = Qt::UserRole + 1,
 39        AllowMultiLineRole = Qt::UserRole + 2,
 40        JobDataRole = Qt::UserRole + 3,
 41        SortRole = Qt::UserRole + 4,
 42        AgeRole = Qt::UserRole + 5
 43    };
 44
 45    explicit JobStatusModel( QObject* parent = 0 );
 46    virtual ~JobStatusModel();
 47
 48    virtual Qt::ItemFlags flags( const QModelIndex& index ) const;
 49    virtual QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const;
 50    virtual int rowCount( const QModelIndex& parent = QModelIndex() ) const;
 51
 52signals:
 53    void customDelegateJobInserted( int row, JobStatusItem* item );
 54    void customDelegateJobRemoved( int row );
 55    void refreshDelegates();
 56
 57public slots:
 58    /// Takes ownership of job
 59    void addJob( JobStatusItem* item );
 60
 61private slots:
 62    void itemUpdated();
 63    void itemFinished();
 64
 65private:
 66    QList< JobStatusItem* > m_items;
 67    QHash< QString, QList< JobStatusItem* > > m_collapseCount;
 68    QHash< QString, QQueue< JobStatusItem* > > m_jobQueue;
 69    QHash< QString, int > m_jobTypeCount;
 70};
 71
 72class DLLEXPORT JobStatusSortModel : public QSortFilterProxyModel
 73{
 74    Q_OBJECT
 75
 76public:
 77    JobStatusSortModel( QObject* parent = 0 );
 78    virtual ~JobStatusSortModel();
 79
 80    void setJobModel( JobStatusModel* model );
 81
 82signals:
 83    void checkCount();
 84    void customDelegateJobInserted( int row, JobStatusItem* item );
 85    void customDelegateJobRemoved( int row );
 86    void refreshDelegates();
 87
 88public slots:
 89    void addJob( JobStatusItem* item );
 90    void customDelegateJobInsertedSlot( int row, JobStatusItem* item);
 91    void customDelegateJobRemovedSlot( int row );
 92    void refreshDelegatesSlot();
 93
 94protected:
 95    virtual bool lessThan( const QModelIndex & left, const QModelIndex & right ) const;
 96
 97private:
 98    JobStatusModel* m_sourceModel;
 99};
100
101#endif // JOBSTATUSMODEL_H