##// END OF EJS Templates
Changed QCustomPlot data from QMap to QVector....
Changed QCustomPlot data from QMap to QVector. Improves read and plot speed.

File last commit:

r0:b2e86551a87b default
r3:d10d160ab523 default
Show More
filedownloader.cpp
100 lines | 3.3 KiB | text/x-c | CppLexer
/ src / filedownloader.cpp
/*------------------------------------------------------------------------------
-- This file is a part of the QLop Software
-- Copyright (C) 2015, Plasma Physics Laboratory - CNRS
--
-- 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.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-------------------------------------------------------------------------------*/
/*-- Author : Alexis Jeandet
-- Mail : alexis.jeandet@member.fsf.org
----------------------------------------------------------------------------*/
#include "filedownloader.h"
#include <QNetworkProxy>
FileDownloader::FileDownloader(QUrl fileUrl, const QString &name, QObject *parent) : QObject(parent)
{
connect(&m_WebCtrl, SIGNAL(finished(QNetworkReply*)),
SLOT(fileDownloaded(QNetworkReply*)));
QNetworkProxyQuery q(QUrl("http://www.google.com"));
q.setQueryType(QNetworkProxyQuery::UrlRequest);
q.setProtocolTag("http");
QList<QNetworkProxy> proxies = QNetworkProxyFactory::systemProxyForQuery(q);
if( proxies.size() > 0 && proxies[0].type() != QNetworkProxy::NoProxy )
QNetworkProxy::setApplicationProxy(proxies[0]);
else
qDebug("No proxy server selected");
this->m_downloadComplete = false;
this->m_fileName = name;
QNetworkRequest request(fileUrl);
m_Reply = m_WebCtrl.get(request);
connect(this->m_Reply,SIGNAL(downloadProgress(qint64,qint64)),this,SLOT(downloadProgress(qint64,qint64)));
connect(&m_WebCtrl,SIGNAL(finished(QNetworkReply*)),this,SLOT(fileDownloaded(QNetworkReply*)));
this->m_progressBar.setMinimum(0);
this->m_progressBar.show();
this->m_widget.setLayout(&this->m_layout);
this->m_layout.addWidget(&this->m_label);
this->m_layout.addWidget(&this->m_progressBar);
this->m_label.setText(name);
}
FileDownloader::~FileDownloader()
{
}
void FileDownloader::fileDownloaded(QNetworkReply* pReply)
{
m_DownloadedData = pReply->readAll();
this->m_downloadComplete = true;
pReply->deleteLater();
emit downloaded();
this->m_progressBar.hide();
}
void FileDownloader::downloadProgress(qint64 bytesSent, qint64 bytesTotal)
{
if(Q_UNLIKELY(this->m_progressBar.maximum()!=bytesTotal))
{
this->m_progressBar.setMaximum(bytesTotal);
}
this->m_progressBar.setValue(bytesSent);
}
bool FileDownloader::downloadComplete(){return m_downloadComplete;}
QByteArray FileDownloader::downloadedData() const
{
return m_DownloadedData;
}
void FileDownloader::clearData()
{
this->m_DownloadedData.clear();
}
int FileDownloader::donloadedDataSize()
{
return m_DownloadedData.size();
}
QWidget *FileDownloader::getProgressBar()
{
return &this->m_widget;
}
QString FileDownloader::fileName(){return m_fileName;}