1 /*************************************************************************** 2 * * 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 3 of the License, or * 6 * (at your option) any later version. * 7 * * 8 ***************************************************************************/ 9 10 #pragma once 11 12 #include <QAbstractItemModel> 13 #include <QSortFilterProxyModel> 14 #include <QHash> 15 #include <QMap> 16 17 #define COLUMN_FINISHED_NAME 0 18 #define COLUMN_FINISHED_PATH 1 19 #define COLUMN_FINISHED_TIME 2 20 #define COLUMN_FINISHED_USER 3 21 #define COLUMN_FINISHED_TR 4 22 #define COLUMN_FINISHED_SPEED 5 23 #define COLUMN_FINISHED_CRC32 6 24 #define COLUMN_FINISHED_TARGET 7 25 #define COLUMN_FINISHED_ELAPS 8 26 #define COLUMN_FINISHED_FULL 9 27 28 class FinishedTransfersItem 29 { 30 31 public: 32 FinishedTransfersItem(const QList<QVariant> &data, FinishedTransfersItem *parent = 0); 33 ~FinishedTransfersItem(); 34 35 void appendChild(FinishedTransfersItem *child); 36 37 FinishedTransfersItem *child(int row); 38 int childCount() const; 39 int columnCount() const; 40 QVariant data(int column) const; 41 int row() const; 42 FinishedTransfersItem *parent() const; 43 void updateColumn(int column, QVariant var); 44 45 QList<FinishedTransfersItem*> childItems; 46 47 private: 48 QList<QVariant> itemData; 49 FinishedTransfersItem *parentItem; 50 }; 51 52 class FinishedTransferProxyModel: public QSortFilterProxyModel { 53 Q_OBJECT 54 55 public: sort(int column,Qt::SortOrder order)56 virtual void sort(int column, Qt::SortOrder order) { 57 if (sourceModel()) 58 sourceModel()->sort(column, order); 59 } 60 }; 61 62 class FinishedTransfersModel : public QAbstractItemModel 63 { 64 Q_OBJECT 65 typedef QMap<QString, QVariant> VarMap; 66 67 public: 68 69 enum ViewType{ 70 FileView=0, 71 UserView 72 }; 73 74 FinishedTransfersModel(QObject *parent = 0); 75 virtual ~FinishedTransfersModel(); 76 77 /** */ 78 QVariant data(const QModelIndex &, int) const; 79 /** */ 80 Qt::ItemFlags flags(const QModelIndex &) const; 81 /** */ 82 QVariant headerData(int section, Qt::Orientation, int role = Qt::DisplayRole) const; 83 /** */ 84 QModelIndex index(int, int, const QModelIndex &parent = QModelIndex()) const; 85 /** */ 86 QModelIndex parent(const QModelIndex &index) const; 87 /** */ 88 int rowCount(const QModelIndex &parent = QModelIndex()) const; 89 /** */ 90 int columnCount(const QModelIndex &parent = QModelIndex()) const; 91 /** sort list */ 92 virtual void sort(int column, Qt::SortOrder order = Qt::AscendingOrder); sort()93 virtual void sort() { sort(sortColumn, sortOrder); } 94 95 /** Clear model and redraw view*/ 96 void clearModel(); 97 98 /** */ 99 void repaint(); 100 101 /** */ 102 void switchViewType(ViewType); 103 104 public Q_SLOTS: 105 /** */ 106 void addFile(const VarMap ¶ms); 107 /** */ 108 void addUser(const VarMap ¶ms); 109 /** */ 110 void remFile(const QString &file); 111 /** */ 112 void remUser(const QString &cid); 113 114 private: 115 /** */ 116 FinishedTransfersItem *findFile(const QString &fname); 117 /** */ 118 FinishedTransfersItem *findUser(const QString &cid); 119 120 FinishedTransfersItem *rootItem; 121 FinishedTransfersItem *fileItem; 122 FinishedTransfersItem *userItem; 123 124 int sortColumn; 125 Qt::SortOrder sortOrder; 126 127 QHash<QString, FinishedTransfersItem* > file_hash; 128 QHash<QString, FinishedTransfersItem* > user_hash; 129 QMap<int, QString> file_header_table; 130 QMap<int, QString> user_header_table; 131 }; 132