transmission/qt/FileTreeItem.h

107 lines
2.6 KiB
C
Raw Normal View History

// This file Copyright © 2009-2022 Mnemosyne LLC.
2022-08-08 18:05:39 +00:00
// It may be used under GPLv2 (SPDX: GPL-2.0-only), GPLv3 (SPDX: GPL-3.0-only),
// or any future license endorsed by Mnemosyne LLC.
// License text can be found in the licenses/ folder.
#pragma once
#include <cstdint>
fix: sonarcloud (#2865) * refactor: implement FileTreeItem::children_ with a std::vector * fix: std::move should not be called on forwarding reference * fix: uninitialized scalar variable * fix: unchecked return value from library * fix: dereference before null check * fix: unchecked return value from library * fix: unchecked return value from library * fixup! refactor: implement FileTreeItem::children_ with a std::vector * fix: signed-unsigned comparison in libtransmission tests * fix: avoid unnecessary copy by using const reference * fix: function should be declared const * refactor: use fmt::format to build log timestamps * fix: use init-statement to reduce variable scope * fixup! refactor: use fmt::format to build log timestamps * fix: remove tau_tracker destructor for rule-of-zero * fix: remove tr_peerIo destructor for rule-of-zero * Revert "fix: dereference before null check" This reverts commit cd789678156bb987a8dc6b2eb49cb1db4195d441. * fix: signed-unsigned comparison in libtransmission tests * fix: use init-statement to reduce variable scope * fix: extract nested code block into separate method * fix: extract nested code block into separate method * fix: extract nested code block into separate method * fix: use init-statement to reduce variable scope * fix: extract nested code block into separate method * fix: signed-unsigned comparison in libtransmission tests * fixup! fix: extract nested code block into separate method * fix: mark possibly-unused as [[maybe_unused]] * fix: invalid stack memory reference in tr_found_file_t * fix: signed-unsigned comparison in libtransmission tests
2022-04-02 14:06:02 +00:00
#include <vector>
2015-06-12 22:12:12 +00:00
#include <QCoreApplication>
#include <QHash>
#include <QSet>
#include <QString>
#include <QVariant>
#include <libtransmission/tr-macros.h>
2015-06-12 22:12:12 +00:00
class FileTreeItem
{
Q_DECLARE_TR_FUNCTIONS(FileTreeItem)
TR_DISABLE_COPY_MOVE(FileTreeItem)
public:
static auto constexpr Low = int{ 1 << 0 };
static auto constexpr Normal = int{ 1 << 1 };
static auto constexpr High = int{ 1 << 2 };
FileTreeItem(QString const& name = QString(), int file_index = -1, uint64_t size = 0)
: name_(name)
, total_size_(size)
, file_index_(file_index)
{
}
2015-06-12 22:12:12 +00:00
~FileTreeItem();
void appendChild(FileTreeItem* child);
FileTreeItem* child(QString const& filename);
FileTreeItem* child(int row)
{
return children_.at(row);
}
[[nodiscard]] int childCount() const noexcept
{
return std::size(children_);
}
[[nodiscard]] auto* parent() noexcept
{
return parent_;
}
[[nodiscard]] auto const* parent() const noexcept
{
return parent_;
}
int row() const;
[[nodiscard]] constexpr auto const& name() const noexcept
{
return name_;
}
QVariant data(int column, int role) const;
std::pair<int, int> update(QString const& name, bool want, int priority, uint64_t have, bool update_fields);
void setSubtreeWanted(bool, QSet<int>& file_ids);
void setSubtreePriority(int priority, QSet<int>& file_ids);
[[nodiscard]] constexpr auto fileIndex() const noexcept
{
return file_index_;
}
[[nodiscard]] constexpr auto totalSize() const noexcept
{
return total_size_;
}
QString path() const;
bool isComplete() const;
int priority() const;
int isSubtreeWanted() const;
private:
QString priorityString() const;
QString sizeString() const;
void getSubtreeWantedSize(uint64_t& have, uint64_t& total) const;
double progress() const;
uint64_t size() const;
QHash<QString, int> const& getMyChildRows();
FileTreeItem* parent_ = {};
QHash<QString, int> child_rows_;
fix: sonarcloud (#2865) * refactor: implement FileTreeItem::children_ with a std::vector * fix: std::move should not be called on forwarding reference * fix: uninitialized scalar variable * fix: unchecked return value from library * fix: dereference before null check * fix: unchecked return value from library * fix: unchecked return value from library * fixup! refactor: implement FileTreeItem::children_ with a std::vector * fix: signed-unsigned comparison in libtransmission tests * fix: avoid unnecessary copy by using const reference * fix: function should be declared const * refactor: use fmt::format to build log timestamps * fix: use init-statement to reduce variable scope * fixup! refactor: use fmt::format to build log timestamps * fix: remove tau_tracker destructor for rule-of-zero * fix: remove tr_peerIo destructor for rule-of-zero * Revert "fix: dereference before null check" This reverts commit cd789678156bb987a8dc6b2eb49cb1db4195d441. * fix: signed-unsigned comparison in libtransmission tests * fix: use init-statement to reduce variable scope * fix: extract nested code block into separate method * fix: extract nested code block into separate method * fix: extract nested code block into separate method * fix: use init-statement to reduce variable scope * fix: extract nested code block into separate method * fix: signed-unsigned comparison in libtransmission tests * fixup! fix: extract nested code block into separate method * fix: mark possibly-unused as [[maybe_unused]] * fix: invalid stack memory reference in tr_found_file_t * fix: signed-unsigned comparison in libtransmission tests
2022-04-02 14:06:02 +00:00
std::vector<FileTreeItem*> children_;
QString name_;
uint64_t const total_size_ = {};
uint64_t have_size_ = {};
int first_unhashed_row_ = {};
int const file_index_ = {};
int priority_ = {};
bool is_wanted_ = {};
};