1 | /* |
---|
2 | * This file Copyright (C) 2009-2015 Mnemosyne LLC |
---|
3 | * |
---|
4 | * It may be used under the GNU GPL versions 2 or 3 |
---|
5 | * or any future license endorsed by Mnemosyne LLC. |
---|
6 | * |
---|
7 | * $Id: FileTreeModel.h 14539 2015-06-12 22:12:12Z mikedld $ |
---|
8 | */ |
---|
9 | |
---|
10 | #ifndef QTR_FILE_TREE_MODEL_H |
---|
11 | #define QTR_FILE_TREE_MODEL_H |
---|
12 | |
---|
13 | #include <stdint.h> |
---|
14 | |
---|
15 | #include <QAbstractItemModel> |
---|
16 | #include <QList> |
---|
17 | #include <QMap> |
---|
18 | #include <QSet> |
---|
19 | |
---|
20 | class FileTreeItem; |
---|
21 | |
---|
22 | class FileTreeModel: public QAbstractItemModel |
---|
23 | { |
---|
24 | Q_OBJECT |
---|
25 | |
---|
26 | public: |
---|
27 | enum |
---|
28 | { |
---|
29 | COL_NAME, |
---|
30 | FIRST_VISIBLE_COLUMN = COL_NAME, |
---|
31 | COL_SIZE, |
---|
32 | COL_PROGRESS, |
---|
33 | COL_WANTED, |
---|
34 | COL_PRIORITY, |
---|
35 | LAST_VISIBLE_COLUMN = COL_PRIORITY, |
---|
36 | |
---|
37 | COL_FILE_INDEX, |
---|
38 | NUM_COLUMNS |
---|
39 | }; |
---|
40 | |
---|
41 | public: |
---|
42 | FileTreeModel (QObject * parent = nullptr, bool isEditable = true); |
---|
43 | virtual ~FileTreeModel (); |
---|
44 | |
---|
45 | void setEditable (bool editable); |
---|
46 | |
---|
47 | void clear (); |
---|
48 | void addFile (int index, const QString& filename, |
---|
49 | bool wanted, int priority, |
---|
50 | uint64_t size, uint64_t have, |
---|
51 | QList<QModelIndex>& rowsAdded, |
---|
52 | bool torrentChanged); |
---|
53 | |
---|
54 | QModelIndex parent (const QModelIndex& child, int column) const; |
---|
55 | |
---|
56 | // QAbstractItemModel |
---|
57 | virtual QVariant data (const QModelIndex& index, int role = Qt::DisplayRole) const; |
---|
58 | virtual Qt::ItemFlags flags (const QModelIndex& index) const; |
---|
59 | virtual QVariant headerData (int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; |
---|
60 | virtual QModelIndex index (int row, int column, const QModelIndex& parent = QModelIndex ()) const; |
---|
61 | virtual QModelIndex parent (const QModelIndex& child) const; |
---|
62 | virtual int rowCount (const QModelIndex& parent = QModelIndex ()) const; |
---|
63 | virtual int columnCount (const QModelIndex& parent = QModelIndex ()) const; |
---|
64 | virtual bool setData (const QModelIndex& index, const QVariant& value, int role = Qt::EditRole); |
---|
65 | |
---|
66 | public slots: |
---|
67 | void clicked (const QModelIndex& index); |
---|
68 | void doubleClicked (const QModelIndex& index); |
---|
69 | |
---|
70 | signals: |
---|
71 | void priorityChanged (const QSet<int>& fileIndices, int); |
---|
72 | void wantedChanged (const QSet<int>& fileIndices, bool); |
---|
73 | void pathEdited (const QString& oldpath, const QString& newname); |
---|
74 | void openRequested (const QString& path); |
---|
75 | |
---|
76 | private: |
---|
77 | void clearSubtree (const QModelIndex&); |
---|
78 | QModelIndex indexOf (FileTreeItem *, int column) const; |
---|
79 | void parentsChanged (const QModelIndex&, int firstColumn, int lastColumn); |
---|
80 | void subtreeChanged (const QModelIndex&, int firstColumn, int lastColumn); |
---|
81 | FileTreeItem * findItemForFileIndex (int fileIndex) const; |
---|
82 | FileTreeItem * itemFromIndex (const QModelIndex&) const; |
---|
83 | |
---|
84 | private: |
---|
85 | bool myIsEditable; |
---|
86 | |
---|
87 | FileTreeItem * myRootItem; |
---|
88 | QMap<int, FileTreeItem *> myIndexCache; |
---|
89 | }; |
---|
90 | |
---|
91 | #endif // QTR_FILE_TREE_MODEL_H |
---|