refactor: show 1.0 progress for zero-byte files (#6307)

This commit is contained in:
Charles Kerr 2023-12-06 11:23:47 -06:00 committed by GitHub
parent 48f9a2376a
commit 15af2ff5be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 28 deletions

View File

@ -188,34 +188,26 @@ QVariant FileTreeItem::data(int column, int role) const
return value; return value;
} }
void FileTreeItem::getSubtreeWantedSize(uint64_t& have, uint64_t& total) const std::pair<uint64_t, uint64_t> FileTreeItem::get_subtree_wanted_size() const
{ {
if (is_wanted_) auto have = uint64_t{ is_wanted_ ? have_size_ : 0U };
auto total = uint64_t{ is_wanted_ ? total_size_ : 0U };
for (auto const* const child : children_)
{ {
have += have_size_; auto const [child_have, child_total] = child->get_subtree_wanted_size();
total += total_size_; have += child_have;
total += child_total;
} }
for (FileTreeItem const* const i : children_) return { have, total };
{
i->getSubtreeWantedSize(have, total);
}
} }
double FileTreeItem::progress() const double FileTreeItem::progress() const
{ {
double d(0); auto const [have, total] = get_subtree_wanted_size();
uint64_t have(0);
uint64_t total(0);
getSubtreeWantedSize(have, total); return have >= total ? 1.0 : static_cast<double>(have) / static_cast<double>(total);
if (total != 0)
{
d = static_cast<double>(have) / static_cast<double>(total);
}
return d;
} }
QString FileTreeItem::sizeString() const QString FileTreeItem::sizeString() const
@ -225,14 +217,7 @@ QString FileTreeItem::sizeString() const
uint64_t FileTreeItem::size() const uint64_t FileTreeItem::size() const
{ {
if (std::empty(children_)) auto const [have, total] = get_subtree_wanted_size();
{
return total_size_;
}
uint64_t have = 0;
uint64_t total = 0;
getSubtreeWantedSize(have, total);
return total; return total;
} }

View File

@ -7,6 +7,7 @@
#include <cstdint> #include <cstdint>
#include <unordered_map> #include <unordered_map>
#include <utility>
#include <vector> #include <vector>
#include <QCoreApplication> #include <QCoreApplication>
@ -94,7 +95,7 @@ public:
private: private:
QString priorityString() const; QString priorityString() const;
QString sizeString() const; QString sizeString() const;
void getSubtreeWantedSize(uint64_t& have, uint64_t& total) const; std::pair<uint64_t, uint64_t> get_subtree_wanted_size() const;
double progress() const; double progress() const;
uint64_t size() const; uint64_t size() const;
std::unordered_map<QString, int> const& getMyChildRows() const; std::unordered_map<QString, int> const& getMyChildRows() const;