2 * This file Copyright (C) Mnemosyne LLC
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2
6 * as published by the Free Software Foundation.
8 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
10 * $Id: file-tree.h 11092 2010-08-01 20:36:13Z charles $
13 #ifndef QTR_TREE_FILE_MODEL
14 #define QTR_TREE_FILE_MODEL
16 #include <QAbstractItemModel>
18 #include <QItemDelegate>
26 class QSortFilterProxyModel
;
29 #include "torrent.h" // FileList
35 class FileTreeItem
: public QObject
39 enum { LOW
=(1<<0), NORMAL
=(1<<1), HIGH
=(1<<2) };
42 virtual ~FileTreeItem( );
43 FileTreeItem( int fileIndex
, const QString
& name
="" ):
44 myIndex(fileIndex
), myParent(0), myName(name
),
45 myPriority(0), myIsWanted(0),
46 myHaveSize(0), myTotalSize(0) { }
49 void appendChild( FileTreeItem
*child
);
50 FileTreeItem
* child( const QString
& filename
);
51 FileTreeItem
* child( int row
) { return myChildren
.at( row
); }
52 int childCount( ) const { return myChildren
.size( ); }
53 FileTreeItem
* parent( ) { return myParent
; }
54 const FileTreeItem
* parent( ) const { return myParent
; }
56 const QString
& name( ) const { return myName
; }
57 QVariant
data( int column
) const;
58 bool update( int index
, bool want
, int priority
, uint64_t total
, uint64_t have
, bool torrentChanged
);
59 void twiddleWanted( QSet
<int>& fileIds
, bool& );
60 void twiddlePriority( QSet
<int>& fileIds
, int& );
63 void setSubtreePriority( int priority
, QSet
<int>& fileIds
);
64 void setSubtreeWanted( bool, QSet
<int>& fileIds
);
65 QString
priorityString( ) const;
66 void getSubtreeSize( uint64_t& have
, uint64_t& total
) const;
67 QString
fileSizeName( ) const;
68 double progress( ) const;
69 int priority( ) const;
70 int isSubtreeWanted( ) const;
73 FileTreeItem
* myParent
;
74 QList
<FileTreeItem
*> myChildren
;
82 class FileTreeModel
: public QAbstractItemModel
87 FileTreeModel( QObject
*parent
= 0);
91 QVariant
data( const QModelIndex
&index
, int role
= Qt::DisplayRole
) const;
92 Qt::ItemFlags
flags( const QModelIndex
& index
) const;
93 QVariant
headerData( int section
, Qt::Orientation orientation
, int role
= Qt::DisplayRole
) const;
94 QModelIndex
index( int row
, int column
, const QModelIndex
& parent
= QModelIndex() ) const;
95 QModelIndex
parent( const QModelIndex
& child
) const;
96 QModelIndex
parent( const QModelIndex
& child
, int column
) const;
97 int rowCount( const QModelIndex
& parent
= QModelIndex( ) ) const;
98 int columnCount( const QModelIndex
&parent
= QModelIndex( ) ) const;
101 void priorityChanged( const QSet
<int>& fileIndices
, int );
102 void wantedChanged( const QSet
<int>& fileIndices
, bool );
106 void addFile( int index
, const QString
& filename
,
107 bool wanted
, int priority
,
108 uint64_t size
, uint64_t have
,
109 QList
<QModelIndex
>& rowsAdded
,
110 bool torrentChanged
);
113 void clearSubtree( const QModelIndex
& );
114 QModelIndex
indexOf( FileTreeItem
*, int column
) const;
115 void parentsChanged( const QModelIndex
&, int column
);
116 void subtreeChanged( const QModelIndex
&, int column
);
119 FileTreeItem
* rootItem
;
122 void clicked ( const QModelIndex
& index
);
125 class FileTreeDelegate
: public QItemDelegate
130 FileTreeDelegate( QObject
* parent
=0 ): QItemDelegate( parent
) { }
131 virtual ~FileTreeDelegate( ) { }
134 virtual QSize
sizeHint(const QStyleOptionViewItem
&, const QModelIndex
&) const;
135 virtual void paint(QPainter
*, const QStyleOptionViewItem
&, const QModelIndex
&) const;
138 class FileTreeView
: public QTreeView
143 FileTreeView( QWidget
* parent
=0 );
144 virtual ~FileTreeView( );
146 void update( const FileList
& files
);
147 void update( const FileList
& files
, bool torrentChanged
);
150 void priorityChanged( const QSet
<int>& fileIndices
, int );
151 void wantedChanged( const QSet
<int>& fileIndices
, bool );
154 bool eventFilter( QObject
*, QEvent
* );
157 FileTreeModel myModel
;
158 QSortFilterProxyModel
* myProxy
;
159 FileTreeDelegate myDelegate
;
162 void onClicked ( const QModelIndex
& index
);