05fc3aef53
Replace the current license disclaimer in files by a SPDX-License-Identifier. Files that have to be modified by hand are modified. License files are organized under LICENSES directory. Task-number: QTBUG-67283 Change-Id: Id880c92784c40f3bbde861c0d93f58151c18b9f1 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
61 lines
1.3 KiB
C++
61 lines
1.3 KiB
C++
// Copyright (C) 2017 The Qt Company Ltd.
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
|
|
|
#include "textprogressbar.h"
|
|
|
|
#include <QByteArray>
|
|
|
|
#include <cstdio>
|
|
|
|
using namespace std;
|
|
|
|
void TextProgressBar::clear()
|
|
{
|
|
printf("\n");
|
|
fflush(stdout);
|
|
|
|
value = 0;
|
|
maximum = -1;
|
|
iteration = 0;
|
|
}
|
|
|
|
void TextProgressBar::update()
|
|
{
|
|
++iteration;
|
|
|
|
if (maximum > 0) {
|
|
// we know the maximum
|
|
// draw a progress bar
|
|
int percent = value * 100 / maximum;
|
|
int hashes = percent / 2;
|
|
|
|
QByteArray progressbar(hashes, '#');
|
|
if (percent % 2)
|
|
progressbar += '>';
|
|
|
|
printf("\r[%-50s] %3d%% %s ",
|
|
progressbar.constData(),
|
|
percent,
|
|
qPrintable(message));
|
|
} else {
|
|
// we don't know the maximum, so we can't draw a progress bar
|
|
int center = (iteration % 48) + 1; // 50 spaces, minus 2
|
|
QByteArray before(qMax(center - 2, 0), ' ');
|
|
QByteArray after(qMin(center + 2, 50), ' ');
|
|
|
|
printf("\r[%s###%s] %s ",
|
|
before.constData(), after.constData(), qPrintable(message));
|
|
}
|
|
}
|
|
|
|
void TextProgressBar::setMessage(const QString &m)
|
|
{
|
|
message = m;
|
|
}
|
|
|
|
void TextProgressBar::setStatus(qint64 val, qint64 max)
|
|
{
|
|
value = val;
|
|
maximum = max;
|
|
}
|