mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
display the downloaded size in QgsFileDownloaderDialog
This commit is contained in:
parent
ded892eaee
commit
88054a3744
@ -313,6 +313,7 @@
|
||||
%Include qgsfieldmodel.sip
|
||||
%Include qgsfieldproxymodel.sip
|
||||
%Include qgsfiledownloader.sip
|
||||
%Include qgsfileutils.sip
|
||||
%Include qgsfeaturefiltermodel.sip
|
||||
%Include qgsgeometryvalidator.sip
|
||||
%Include qgsgml.sip
|
||||
|
38
python/core/qgsfileutils.sip
Normal file
38
python/core/qgsfileutils.sip
Normal file
@ -0,0 +1,38 @@
|
||||
/************************************************************************
|
||||
* This file has been generated automatically from *
|
||||
* *
|
||||
* src/core/qgsfileutils.h *
|
||||
* *
|
||||
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
|
||||
************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
class QgsFileUtils
|
||||
{
|
||||
%Docstring
|
||||
Class for file utilities.
|
||||
.. versionadded:: 3.0
|
||||
%End
|
||||
|
||||
%TypeHeaderCode
|
||||
#include "qgsfileutils.h"
|
||||
%End
|
||||
public:
|
||||
|
||||
static QString representFileSize( qint64 bytes );
|
||||
%Docstring
|
||||
Return the human size from bytes
|
||||
:rtype: str
|
||||
%End
|
||||
|
||||
};
|
||||
|
||||
/************************************************************************
|
||||
* This file has been generated automatically from *
|
||||
* *
|
||||
* src/core/qgsfileutils.h *
|
||||
* *
|
||||
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
|
||||
************************************************************************/
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include "qgsalgorithmfiledownloader.h"
|
||||
#include "qgsfiledownloader.h"
|
||||
#include "qgsfileutils.h"
|
||||
#include <QEventLoop>
|
||||
#include <QFileInfo>
|
||||
#include <QTimer>
|
||||
@ -110,30 +111,14 @@ void QgsFileDownloaderAlgorithm::sendProgressFeedback()
|
||||
|
||||
void QgsFileDownloaderAlgorithm::receiveProgressFromDownloader( qint64 bytesReceived, qint64 bytesTotal )
|
||||
{
|
||||
mReceived = humanSize( bytesReceived );
|
||||
mReceived = QgsFileUtils::representFileSize( bytesReceived );
|
||||
if ( bytesTotal > 0 )
|
||||
{
|
||||
if ( mTotal.isEmpty() )
|
||||
mTotal = humanSize( bytesTotal );
|
||||
mTotal = QgsFileUtils::representFileSize( bytesTotal );
|
||||
|
||||
mFeedback->setProgress( ( bytesReceived * 100 ) / bytesTotal );
|
||||
}
|
||||
}
|
||||
|
||||
QString QgsFileDownloaderAlgorithm::humanSize( qint64 bytes )
|
||||
{
|
||||
QStringList list;
|
||||
list << "KB" << "MB" << "GB" << "TB";
|
||||
|
||||
QStringListIterator i( list );
|
||||
QString unit( "bytes" );
|
||||
|
||||
while ( bytes >= 1024.0 && i.hasNext() )
|
||||
{
|
||||
unit = i.next();
|
||||
bytes /= 1024.0;
|
||||
}
|
||||
return QString( "%1 %2" ).arg( QString::number( bytes ) ).arg( unit );
|
||||
}
|
||||
|
||||
///@endcond
|
||||
|
@ -54,7 +54,6 @@ class QgsFileDownloaderAlgorithm : public QgsProcessingAlgorithm, public QObject
|
||||
QString mLastReport;
|
||||
void reportErrors( QStringList errors );
|
||||
void receiveProgressFromDownloader( qint64 bytesReceived, qint64 bytesTotal );
|
||||
static QString humanSize( qint64 bytes );
|
||||
void sendProgressFeedback();
|
||||
};
|
||||
|
||||
|
@ -186,6 +186,7 @@ SET(QGIS_CORE_SRCS
|
||||
qgsfieldproxymodel.cpp
|
||||
qgsfields.cpp
|
||||
qgsfiledownloader.cpp
|
||||
qgsfileutils.cpp
|
||||
qgsfontutils.cpp
|
||||
qgsgeometrysimplifier.cpp
|
||||
qgsgeometryvalidator.cpp
|
||||
@ -601,6 +602,7 @@ SET(QGIS_CORE_MOC_HDRS
|
||||
qgsfieldmodel.h
|
||||
qgsfieldproxymodel.h
|
||||
qgsfiledownloader.h
|
||||
qgsfileutils.h
|
||||
qgsfeaturefiltermodel.h
|
||||
qgsfeaturefiltermodel_p.h
|
||||
qgsgeometryvalidator.h
|
||||
|
18
src/core/qgsfileutils.cpp
Normal file
18
src/core/qgsfileutils.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
#include "qgsfileutils.h"
|
||||
#include <QObject>
|
||||
|
||||
QString QgsFileUtils::representFileSize( qint64 bytes )
|
||||
{
|
||||
QStringList list;
|
||||
list << QObject::tr( "KB" ) << QObject::tr( "MB" ) << QObject::tr( "GB" ) << QObject::tr( "TB" );
|
||||
|
||||
QStringListIterator i( list );
|
||||
QString unit = QObject::tr( "bytes" );
|
||||
|
||||
while ( bytes >= 1024.0 && i.hasNext() )
|
||||
{
|
||||
unit = i.next();
|
||||
bytes /= 1024.0;
|
||||
}
|
||||
return QString( "%1 %2" ).arg( QString::number( bytes ), unit );
|
||||
}
|
40
src/core/qgsfileutils.h
Normal file
40
src/core/qgsfileutils.h
Normal file
@ -0,0 +1,40 @@
|
||||
/***************************************************************************
|
||||
qgsfileutils.h
|
||||
---------------------------
|
||||
begin : November 2017
|
||||
copyright : (C) 2017 by Etienne Trimaille
|
||||
email : etienne dot trimaille at gmail dot com
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef QGSFILEUTILS_H
|
||||
#define QGSFILEUTILS_H
|
||||
|
||||
#include "qgis.h"
|
||||
|
||||
/**
|
||||
* \ingroup core
|
||||
* \class QgsFileUtils
|
||||
* \brief Class for file utilities.
|
||||
* \since QGIS 3.0
|
||||
*/
|
||||
class CORE_EXPORT QgsFileUtils
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Return the human size from bytes
|
||||
*/
|
||||
static QString representFileSize( qint64 bytes );
|
||||
|
||||
};
|
||||
|
||||
#endif // QGSFILEUTILS_H
|
@ -15,10 +15,12 @@
|
||||
|
||||
#include "qgsfiledownloaderdialog.h"
|
||||
#include "qgsfiledownloader.h"
|
||||
#include "qgsfileutils.h"
|
||||
#include <QMessageBox>
|
||||
|
||||
QgsFileDownloaderDialog::QgsFileDownloaderDialog( const QUrl &url, const QString &outputFileName, const QString &authcfg )
|
||||
: mDownloader( new QgsFileDownloader( url, outputFileName, authcfg, true ) )
|
||||
: mOutputFileName( outputFileName ),
|
||||
mDownloader( new QgsFileDownloader( url, outputFileName, authcfg, true ) )
|
||||
{
|
||||
setWindowTitle( tr( "Download" ) );
|
||||
setLabelText( tr( "Downloading %1." ).arg( outputFileName ) );
|
||||
@ -46,5 +48,6 @@ void QgsFileDownloaderDialog::onDownloadProgress( qint64 bytesReceived, qint64 b
|
||||
{
|
||||
setMaximum( bytesTotal );
|
||||
setValue( bytesReceived );
|
||||
setLabelText( tr( "Downloading %1 of %2 %3." ).arg( QgsFileUtils::representFileSize( bytesReceived ), QgsFileUtils::representFileSize( bytesTotal ), mOutputFileName ) );
|
||||
}
|
||||
|
||||
|
@ -66,6 +66,7 @@ class GUI_EXPORT QgsFileDownloaderDialog : public QProgressDialog
|
||||
|
||||
private:
|
||||
|
||||
QString mOutputFileName;
|
||||
QgsFileDownloader *mDownloader = nullptr;
|
||||
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user