-
Notifications
You must be signed in to change notification settings - Fork 0
/
table.h
80 lines (65 loc) · 2.13 KB
/
table.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#ifndef TABLE2_H
#define TABLE2_H
#include <QVariant>
#include <memory>
#include <QItemDelegate>
#include <QTreeView>
#include "tablesortmodel.h"
#include "tablemodel.h"
class TableCell : public QItemDelegate {
private:
TableSortModel &sortModel;
private:
static inline QString printRate(long int r, QLocale l = QLocale()){
return QString("%1/s").arg(printSize(r, l));
}
static inline QString printSize(long int s, QLocale l = QLocale()){
return l.formattedDataSize(s, 2, QLocale::DataSizeSIFormat);
}
public:
TableCell(TableSortModel &m, QObject *parent = 0);
~TableCell(){}
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
const QModelIndex &index) const;
void paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const;
};
class Table : public QTreeView {
Q_OBJECT
private:
TableModel model;
TableSortModel sortModel;
TableCell delegate;
private:
std::vector<std::string> selectedHashes();
QModelIndex mapToSource(const QModelIndex &index) const;
QModelIndex mapFromSource(const QModelIndex &index) const;
private slots:
void startTorrents();
void stopTorrents();
void aboutToRemoveTorrents();
void show_details(const QModelIndex&);
void show_move_dialog();
public:
Table(QWidget *parent);
~Table(){}
public slots:
inline void changeTorrent(int i, std::shared_ptr<Torrent> t){
model.changeTorrent(i, t);
}
inline void insertTorrents(int i, std::vector<std::shared_ptr<Torrent> > ts){
model.insertTorrents(i, ts);
}
inline void removeTorrents(int from, int to){
model.removeTorrents(from, to);
}
void showMenu(QPoint);
void apply_name_filter(const QString& name);
signals:
void torrentsStarted(std::vector<std::string> hashs);
void torrentsStopped(std::vector<std::string> hashs);
void torrentsRemoved(std::vector<std::string> hs, bool deleteData);
void details_requested(QString hash);
void move_downloads(std::vector<std::string> hashes, std::string dest, bool move_data);
};
#endif // TABLE2_H