mirror of
https://github.com/saitohirga/WSJT-X.git
synced 2025-02-23 05:58:43 -05:00
Fix issue with sample downloader directory progress bars
git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@7217 ab8295b8-cf94-4d9e-aec4-7959e3be5d79
This commit is contained in:
parent
2aa27dbab6
commit
34e35e6e49
@ -247,6 +247,41 @@ void Directory::abort ()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// traverse the passed subtree accumulating the number of items, the
|
||||||
|
// number we have size data for, the bytes downloaded so far and the
|
||||||
|
// maximum bytes to expect
|
||||||
|
//
|
||||||
|
int recurse_children (QTreeWidgetItem const * item, int * counted
|
||||||
|
, qint64 * bytes, qint64 * max)
|
||||||
|
{
|
||||||
|
int items {0};
|
||||||
|
for (int index {0}; index < item->childCount (); ++index)
|
||||||
|
{
|
||||||
|
auto const * child = item->child (index);
|
||||||
|
qDebug () << "Item name:" << child->text (0);
|
||||||
|
if (child->type () == FileNode::Type) // only count files
|
||||||
|
{
|
||||||
|
++items;
|
||||||
|
if (auto size = child->data (1, Qt::UserRole).toLongLong ())
|
||||||
|
{
|
||||||
|
*max += size;
|
||||||
|
++*counted;
|
||||||
|
}
|
||||||
|
*bytes += child->data (1, Qt::DisplayRole).toLongLong ();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// recurse into sub-directory subtrees
|
||||||
|
items += recurse_children (child, counted, bytes, max);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Directory::update (QTreeWidgetItem * item)
|
void Directory::update (QTreeWidgetItem * item)
|
||||||
{
|
{
|
||||||
// iterate the tree under item and accumulate the progress
|
// iterate the tree under item and accumulate the progress
|
||||||
@ -255,34 +290,18 @@ void Directory::update (QTreeWidgetItem * item)
|
|||||||
Q_ASSERT (item->type () == DirectoryNode::Type);
|
Q_ASSERT (item->type () == DirectoryNode::Type);
|
||||||
qint64 max {0};
|
qint64 max {0};
|
||||||
qint64 bytes {0};
|
qint64 bytes {0};
|
||||||
|
|
||||||
// reset progress
|
|
||||||
item->setData (1, Qt::UserRole, max);
|
|
||||||
item->setData (1, Qt::DisplayRole, bytes);
|
|
||||||
int items {0};
|
|
||||||
int counted {0};
|
int counted {0};
|
||||||
QTreeWidgetItemIterator iter {item};
|
|
||||||
// iterate sub tree only
|
// get the count, progress and size of children
|
||||||
while (*iter && (*iter == item || (*iter)->parent () != item->parent ()))
|
int items {recurse_children (item, &counted, &bytes, &max)};
|
||||||
{
|
|
||||||
if ((*iter)->type () == FileNode::Type) // only count files
|
|
||||||
{
|
|
||||||
++items;
|
|
||||||
if (auto size = (*iter)->data (1, Qt::UserRole).toLongLong ())
|
|
||||||
{
|
|
||||||
max += size;
|
|
||||||
++counted;
|
|
||||||
}
|
|
||||||
bytes += (*iter)->data (1, Qt::DisplayRole).toLongLong ();
|
|
||||||
}
|
|
||||||
++iter;
|
|
||||||
}
|
|
||||||
// estimate size of items not yet downloaded as average of
|
// estimate size of items not yet downloaded as average of
|
||||||
// those actually present
|
// those actually present
|
||||||
if (counted)
|
if (counted)
|
||||||
{
|
{
|
||||||
max += (items - counted) * max / counted;
|
max += (items - counted) * max / counted;
|
||||||
}
|
}
|
||||||
|
|
||||||
// save as our progress
|
// save as our progress
|
||||||
item->setData (1, Qt::UserRole, max);
|
item->setData (1, Qt::UserRole, max);
|
||||||
item->setData (1, Qt::DisplayRole, bytes);
|
item->setData (1, Qt::DisplayRole, bytes);
|
||||||
|
Loading…
Reference in New Issue
Block a user