2015-06-10 21:27:11 +00:00
|
|
|
/*
|
|
|
|
* This file Copyright (C) 2009-2015 Mnemosyne LLC
|
|
|
|
*
|
|
|
|
* It may be used under the GNU GPL versions 2 or 3
|
|
|
|
* or any future license endorsed by Mnemosyne LLC.
|
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef QTR_FILE_TREE_MODEL_H
|
|
|
|
#define QTR_FILE_TREE_MODEL_H
|
|
|
|
|
2015-06-12 22:41:36 +00:00
|
|
|
#include <cstdint>
|
2015-06-10 21:27:11 +00:00
|
|
|
|
|
|
|
#include <QAbstractItemModel>
|
|
|
|
#include <QList>
|
|
|
|
#include <QMap>
|
|
|
|
#include <QSet>
|
|
|
|
|
|
|
|
class FileTreeItem;
|
|
|
|
|
|
|
|
class FileTreeModel: public QAbstractItemModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
COL_NAME,
|
|
|
|
COL_SIZE,
|
|
|
|
COL_PROGRESS,
|
|
|
|
COL_WANTED,
|
|
|
|
COL_PRIORITY,
|
|
|
|
|
|
|
|
NUM_COLUMNS
|
|
|
|
};
|
|
|
|
|
2015-06-15 21:07:46 +00:00
|
|
|
enum Role
|
|
|
|
{
|
2015-08-16 22:07:09 +00:00
|
|
|
SortRole = Qt::UserRole,
|
|
|
|
FileIndexRole,
|
|
|
|
WantedRole,
|
|
|
|
CompleteRole
|
2015-06-15 21:07:46 +00:00
|
|
|
};
|
|
|
|
|
2015-06-10 21:27:11 +00:00
|
|
|
public:
|
2015-06-12 22:12:12 +00:00
|
|
|
FileTreeModel (QObject * parent = nullptr, bool isEditable = true);
|
|
|
|
virtual ~FileTreeModel ();
|
2015-06-10 21:27:11 +00:00
|
|
|
|
|
|
|
void setEditable (bool editable);
|
|
|
|
|
2015-06-12 22:12:12 +00:00
|
|
|
void clear ();
|
|
|
|
void addFile (int index, const QString& filename,
|
|
|
|
bool wanted, int priority,
|
|
|
|
uint64_t size, uint64_t have,
|
|
|
|
bool torrentChanged);
|
|
|
|
|
2015-08-10 19:40:58 +00:00
|
|
|
bool openFile (const QModelIndex& index);
|
|
|
|
|
|
|
|
void twiddleWanted (const QModelIndexList& indices);
|
|
|
|
void twiddlePriority (const QModelIndexList& indices);
|
|
|
|
|
|
|
|
void setWanted (const QModelIndexList& indices, bool wanted);
|
|
|
|
void setPriority (const QModelIndexList& indices, int priority);
|
|
|
|
|
2015-06-10 21:27:11 +00:00
|
|
|
QModelIndex parent (const QModelIndex& child, int column) const;
|
2015-06-12 22:12:12 +00:00
|
|
|
|
|
|
|
// QAbstractItemModel
|
|
|
|
virtual QVariant data (const QModelIndex& index, int role = Qt::DisplayRole) const;
|
|
|
|
virtual Qt::ItemFlags flags (const QModelIndex& index) const;
|
|
|
|
virtual QVariant headerData (int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
|
|
|
virtual QModelIndex index (int row, int column, const QModelIndex& parent = QModelIndex ()) const;
|
|
|
|
virtual QModelIndex parent (const QModelIndex& child) const;
|
|
|
|
virtual int rowCount (const QModelIndex& parent = QModelIndex ()) const;
|
|
|
|
virtual int columnCount (const QModelIndex& parent = QModelIndex ()) const;
|
|
|
|
virtual bool setData (const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
|
|
|
|
|
2015-06-10 21:27:11 +00:00
|
|
|
signals:
|
|
|
|
void priorityChanged (const QSet<int>& fileIndices, int);
|
|
|
|
void wantedChanged (const QSet<int>& fileIndices, bool);
|
|
|
|
void pathEdited (const QString& oldpath, const QString& newname);
|
|
|
|
void openRequested (const QString& path);
|
|
|
|
|
|
|
|
private:
|
2015-06-12 22:12:12 +00:00
|
|
|
void clearSubtree (const QModelIndex&);
|
2015-06-10 21:27:11 +00:00
|
|
|
QModelIndex indexOf (FileTreeItem *, int column) const;
|
2015-08-10 19:40:58 +00:00
|
|
|
void emitParentsChanged (const QModelIndex&, int firstColumn, int lastColumn, QSet<QModelIndex> * visitedParentIndices = nullptr);
|
|
|
|
void emitSubtreeChanged (const QModelIndex&, int firstColumn, int lastColumn);
|
2015-06-10 21:27:11 +00:00
|
|
|
FileTreeItem * findItemForFileIndex (int fileIndex) const;
|
|
|
|
FileTreeItem * itemFromIndex (const QModelIndex&) const;
|
2015-08-10 19:40:58 +00:00
|
|
|
QModelIndexList getOrphanIndices (const QModelIndexList& indices) const;
|
2015-06-10 21:27:11 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool myIsEditable;
|
|
|
|
|
2015-06-12 22:12:12 +00:00
|
|
|
FileTreeItem * myRootItem;
|
|
|
|
QMap<int, FileTreeItem *> myIndexCache;
|
2015-06-10 21:27:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // QTR_FILE_TREE_MODEL_H
|