mirror of
https://github.com/transmission/transmission
synced 2024-12-28 10:38:45 +00:00
f6f0db75e1
* fix: use-init-statement Xref: https://sonarcloud.io/project/issues\?id\=transmission_transmission\&issues\=AX1f6EvHJiycnfA7gfrG\&open\=AX1f6EvHJiycnfA7gfrG * fix replace-use-of-new warning Xref: https://sonarcloud.io/project/issues\?id\=transmission_transmission\&issues\=AX1ZNs41ZmlvCveKTzon\&open\=AX1ZNs41ZmlvCveKTzon * fix has-virtual-functions-but-non-virtual-destructor warning Xref: https://sonarcloud.io/project/issues\?id\=transmission_transmission\&issues\=AX1ZNs72ZmlvCveKTzo6\&open\=AX1ZNs72ZmlvCveKTzo6 * fix make-variable-const warning Xref: https://sonarcloud.io/project/issues\?id\=transmission_transmission\&issues\=AX0_a_OVNJn7rAzml_7B\&open\=AX0_a_OVNJn7rAzml_7B * fix remove-redundant-static-specifiers Xref: https://sonarcloud.io/project/issues\?id\=transmission_transmission\&issues\=AX06St-81usi2gyYkPTb\&open\=AX06St-81usi2gyYkPTb * fix function-should-be-declared-const Xref: https://sonarcloud.io/project/issues\?id\=transmission_transmission\&issues\=AX06St-81usi2gyYkPTd\&open\=AX06St-81usi2gyYkPTd * fix use-init-statement warning Xref: https://sonarcloud.io/project/issues\?id\=transmission_transmission\&issues\=AX06St-81usi2gyYkPTc\&open\=AX06St-81usi2gyYkPTc * fix class-has-virtual-functions-but-non-virtual-destructor warning Xref: https://sonarcloud.io/project/issues\?id\=transmission_transmission\&issues\=AX06Stz41usi2gyYkPTS\&open\=AX06Stz41usi2gyYkPTS * fix remove-commented-out-code warning Xref: https://sonarcloud.io/project/issues\?id\=transmission_transmission\&issues\=AX06St241usi2gyYkPTT\&open\=AX06St241usi2gyYkPTT * fix remove-commented-out-code warning Xref: https://sonarcloud.io/project/issues\?id\=transmission_transmission\&issues\=AX06St241usi2gyYkPTV\&open\=AX06St241usi2gyYkPTV * fix has-virtual-functions-but-non-virtual-destructor warning https://sonarcloud.io/project/issues\?id\=transmission_transmission\&issues\=AX06St241usi2gyYkPTW\&open\=AX06St241usi2gyYkPTW * fix remove-commented-out-code warning Xref: https://sonarcloud.io/project/issues\?id\=transmission_transmission\&issues\=AX06SuCA1usi2gyYkPTh\&open\=AX06SuCA1usi2gyYkPTh * fix use-init-statement warning Xref: https://sonarcloud.io/project/issues\?id\=transmission_transmission\&issues\=AX0rAQvnfJ-O-YIDS9xF\&open\=AX0rAQvnfJ-O-YIDS9xF * fix use-init-statement warning Xref: https://sonarcloud.io/project/issues\?id\=transmission_transmission\&issues\=AX0rAQvnfJ-O-YIDS9xG\&open\=AX0rAQvnfJ-O-YIDS9xG * fix remove-redundant-access-specifier warning Xref: https://sonarcloud.io/project/issues\?id\=transmission_transmission\&issues\=AX1ZNs5tZmlvCveKTzor\&open\=AX1ZNs5tZmlvCveKTzor * fix use-init-statement warning Xref: https://sonarcloud.io/project/issues\?id\=transmission_transmission\&issues\=AX01Itl7f_SST5i7BN1l\&open\=AX01Itl7f_SST5i7BN1l * fix use-init-statement warning Xref: https://sonarcloud.io/project/issues\?id\=transmission_transmission\&issues\=AX0wDijI2l89lDvp1C9P\&open\=AX0wDijI2l89lDvp1C9P * fix use-automatically-managed-memory-instead-of-new warning Xref: https://sonarcloud.io/project/issues\?id\=transmission_transmission\&issues\=AX1f6E6HJiycnfA7gfrI\&open\=AX1f6E6HJiycnfA7gfrI * fix use-init-statement warning Xref: https://sonarcloud.io/project/issues\?id\=transmission_transmission\&issues\=AX0l8vknEafnvRiIHUEv\&open\=AX0l8vknEafnvRiIHUEv * fixup! fix has-virtual-functions-but-non-virtual-destructor warning
104 lines
3 KiB
C++
104 lines
3 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 <memory>
|
|
|
|
#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
|
|
};
|
|
|
|
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;
|
|
|
|
QMap<int, FileTreeItem*> index_cache_;
|
|
std::unique_ptr<FileTreeItem> root_item_;
|
|
bool is_editable_ = {};
|
|
};
|