mirror of
https://github.com/transmission/transmission
synced 2024-12-31 20:16:57 +00:00
c2fb393390
* refactor: mark subclass' destructors as override. * refactor: use QUrl to parse announce URL strings. The prompt for this was to work around a clang-tidy issue where "char* host = nullptr;" triggers a "don't use varargs" warning, but on the other hand it's also terser / cleaner. * refactor: make the TorrentDelegate brushes const. * refactor: s/auto/auto const*/ where appropriate * chore: add some nonconst global warning exemptions * chore: turn off warnings in GTest * refactor: just disable the clang-tidy warning. Apparently a std::array<T>::iterator is a T* on clang, since clang-tidy's readability warning says we should use 'auto*' instead of 'auto'. However adding that annotation fails on MSVC, where the is apparently _not_ a raw pointer. Since there's not a way to satisfy both of them at the same time, disable the warning.
96 lines
2.9 KiB
C++
96 lines
2.9 KiB
C++
/*
|
|
* 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.
|
|
*
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <cstdint> // uint64_t
|
|
|
|
#include <QAbstractItemModel>
|
|
#include <QMap>
|
|
#include <QSet>
|
|
|
|
#include "Macros.h"
|
|
|
|
class FileTreeItem;
|
|
|
|
class FileTreeModel final : public QAbstractItemModel
|
|
{
|
|
Q_OBJECT
|
|
TR_DISABLE_COPY_MOVE(FileTreeModel)
|
|
|
|
public:
|
|
enum
|
|
{
|
|
COL_NAME,
|
|
COL_SIZE,
|
|
COL_PROGRESS,
|
|
COL_WANTED,
|
|
COL_PRIORITY,
|
|
//
|
|
NUM_COLUMNS
|
|
};
|
|
|
|
enum Role
|
|
{
|
|
SortRole = Qt::UserRole,
|
|
FileIndexRole,
|
|
WantedRole,
|
|
CompleteRole
|
|
};
|
|
|
|
public:
|
|
FileTreeModel(QObject* parent = nullptr, bool is_editable = true);
|
|
~FileTreeModel() override;
|
|
|
|
void setEditable(bool editable);
|
|
|
|
void clear();
|
|
void addFile(int index, QString const& filename, bool wanted, int priority, uint64_t size, uint64_t have,
|
|
bool torrent_changed);
|
|
|
|
bool openFile(QModelIndex const& index);
|
|
|
|
void twiddleWanted(QModelIndexList const& indices);
|
|
void twiddlePriority(QModelIndexList const& indices);
|
|
|
|
void setWanted(QModelIndexList const& indices, bool wanted);
|
|
void setPriority(QModelIndexList const& indices, int priority);
|
|
|
|
QModelIndex parent(QModelIndex const& child, int column) const;
|
|
|
|
// QAbstractItemModel
|
|
QVariant data(QModelIndex const& index, int role = Qt::DisplayRole) const override;
|
|
Qt::ItemFlags flags(QModelIndex const& index) const override;
|
|
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
|
QModelIndex index(int row, int column, QModelIndex const& parent = {}) const override;
|
|
QModelIndex parent(QModelIndex const& child) const override;
|
|
int rowCount(QModelIndex const& parent = {}) const override;
|
|
int columnCount(QModelIndex const& parent = {}) const override;
|
|
bool setData(QModelIndex const& index, QVariant const& value, int role = Qt::EditRole) override;
|
|
|
|
signals:
|
|
void priorityChanged(QSet<int> const& file_indices, int);
|
|
void wantedChanged(QSet<int> const& file_indices, bool);
|
|
void pathEdited(QString const& oldpath, QString const& new_name);
|
|
void openRequested(QString const& path);
|
|
|
|
private:
|
|
void clearSubtree(QModelIndex const&);
|
|
QModelIndex indexOf(FileTreeItem*, int column) const;
|
|
void emitParentsChanged(QModelIndex const&, int first_column, int last_column,
|
|
QSet<QModelIndex>* visited_parent_indices = nullptr);
|
|
void emitSubtreeChanged(QModelIndex const&, int first_column, int last_column);
|
|
FileTreeItem* findItemForFileIndex(int file_index) const;
|
|
FileTreeItem* itemFromIndex(QModelIndex const&) const;
|
|
QModelIndexList getOrphanIndices(QModelIndexList const& indices) const;
|
|
|
|
private:
|
|
QMap<int, FileTreeItem*> index_cache_;
|
|
FileTreeItem* root_item_ = {};
|
|
bool is_editable_ = {};
|
|
};
|