2
* This file Copyright (C) 2009 Charles Kerr <charles@transmissionbt.com>
4
* This file is licensed by the GPL version 2. Works owned by the
5
* Transmission project are granted a special exemption to clause 2(b)
6
* so that the bulk of its code can remain under the MIT license.
7
* This exemption does not extend to derived works not owned by
8
* the Transmission project.
13
#ifndef QTR_TREE_FILE_MODEL
14
#define QTR_TREE_FILE_MODEL
16
#include <QAbstractItemModel>
23
#include <QItemDelegate>
25
#include "torrent.h" // FileList
31
class FileTreeItem: public QObject
35
enum { LOW=(1<<0), NORMAL=(1<<1), HIGH=(1<<2) };
38
virtual ~FileTreeItem( );
39
FileTreeItem( int fileIndex, const QString& name="" ):
40
myIndex(fileIndex), myParent(0), myName(name),
41
myPriority(0), myIsWanted(0),
42
myHaveSize(0), myTotalSize(0) { }
45
void appendChild( FileTreeItem *child );
46
FileTreeItem * child( const QString& filename );
47
FileTreeItem * child( int row ) { return myChildren.at( row ); }
48
int childCount( ) const { return myChildren.size( ); }
49
FileTreeItem * parent( ) { return myParent; }
50
const FileTreeItem * parent( ) const { return myParent; }
52
const QString& name( ) const { return myName; }
53
QVariant data( int column ) const;
54
bool update( int index, bool want, int priority, uint64_t total, uint64_t have );
55
void twiddleWanted( QSet<int>& fileIds, bool& );
56
void twiddlePriority( QSet<int>& fileIds, int& );
59
void setSubtreePriority( int priority, QSet<int>& fileIds );
60
void setSubtreeWanted( bool, QSet<int>& fileIds );
61
QString priorityString( ) const;
62
void getSubtreeSize( uint64_t& have, uint64_t& total ) const;
63
double progress( ) const;
64
int priority( ) const;
65
int isSubtreeWanted( ) const;
68
FileTreeItem * myParent;
69
QList<FileTreeItem*> myChildren;
77
class FileTreeModel: public QAbstractItemModel
82
FileTreeModel( QObject *parent = 0);
86
QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const;
87
Qt::ItemFlags flags( const QModelIndex& index ) const;
88
QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
89
QModelIndex index( int row, int column, const QModelIndex& parent = QModelIndex() ) const;
90
QModelIndex parent( const QModelIndex& child ) const;
91
QModelIndex parent( const QModelIndex& child, int column ) const;
92
int rowCount( const QModelIndex& parent = QModelIndex( ) ) const;
93
int columnCount( const QModelIndex &parent = QModelIndex( ) ) const;
96
void priorityChanged( const QSet<int>& fileIndices, int );
97
void wantedChanged( const QSet<int>& fileIndices, bool );
101
void addFile( int index, const QString& filename,
102
bool wanted, int priority,
103
uint64_t size, uint64_t have,
104
QList<QModelIndex>& rowsAdded );
107
void clearSubtree( const QModelIndex & );
108
QModelIndex indexOf( FileTreeItem *, int column ) const;
109
void parentsChanged( const QModelIndex &, int column );
110
void subtreeChanged( const QModelIndex &, int column );
113
FileTreeItem * rootItem;
116
void clicked ( const QModelIndex & index );
119
class FileTreeDelegate: public QItemDelegate
125
FileTreeDelegate( QObject * parent=0 ): QItemDelegate( parent ) { }
126
virtual ~FileTreeDelegate( ) { }
128
void paint( QPainter * painter,
129
const QStyleOptionViewItem & option,
130
const QModelIndex & index ) const;
133
class FileTreeView: public QTreeView
138
FileTreeView( QWidget * parent=0 );
139
virtual ~FileTreeView( ) { }
141
void update( const FileList& files );
144
void priorityChanged( const QSet<int>& fileIndices, int );
145
void wantedChanged( const QSet<int>& fileIndices, bool );
148
bool eventFilter( QObject *, QEvent * );
151
FileTreeModel myModel;
152
FileTreeDelegate myDelegate;