mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 17:00:13 +02:00
Switch ImageOverlay to NetworkAccessManager
This commit is contained in:
parent
36fb530594
commit
6489151578
2 changed files with 8 additions and 13 deletions
|
@ -19,7 +19,6 @@
|
||||||
#include "ImageOverlay.h"
|
#include "ImageOverlay.h"
|
||||||
|
|
||||||
ImageOverlay::ImageOverlay() :
|
ImageOverlay::ImageOverlay() :
|
||||||
_manager(NULL),
|
|
||||||
_textureID(0),
|
_textureID(0),
|
||||||
_renderImage(false),
|
_renderImage(false),
|
||||||
_textureBound(false),
|
_textureBound(false),
|
||||||
|
@ -36,21 +35,18 @@ ImageOverlay::~ImageOverlay() {
|
||||||
|
|
||||||
// TODO: handle setting image multiple times, how do we manage releasing the bound texture?
|
// TODO: handle setting image multiple times, how do we manage releasing the bound texture?
|
||||||
void ImageOverlay::setImageURL(const QUrl& url) {
|
void ImageOverlay::setImageURL(const QUrl& url) {
|
||||||
// TODO: are we creating too many QNetworkAccessManager() when multiple calls to setImageURL are made?
|
NetworkAccessManager& networkAccessManager = NetworkAccessManager::getInstance();
|
||||||
_manager->deleteLater();
|
QNetworkReply* reply = networkAccessManager.get(QNetworkRequest(url));
|
||||||
_manager = new QNetworkAccessManager();
|
connect(reply, &QNetworkReply::finished, this, &ImageOverlay::replyFinished);
|
||||||
connect(_manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*)));
|
|
||||||
_manager->get(QNetworkRequest(url));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImageOverlay::replyFinished(QNetworkReply* reply) {
|
void ImageOverlay::replyFinished() {
|
||||||
|
QNetworkReply* reply = static_cast<QNetworkReply*>(sender());
|
||||||
|
|
||||||
// replace our byte array with the downloaded data
|
// replace our byte array with the downloaded data
|
||||||
QByteArray rawData = reply->readAll();
|
QByteArray rawData = reply->readAll();
|
||||||
_textureImage.loadFromData(rawData);
|
_textureImage.loadFromData(rawData);
|
||||||
_renderImage = true;
|
_renderImage = true;
|
||||||
_manager->deleteLater();
|
|
||||||
_manager = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImageOverlay::render() {
|
void ImageOverlay::render() {
|
||||||
|
|
|
@ -16,13 +16,13 @@
|
||||||
|
|
||||||
#include <QGLWidget>
|
#include <QGLWidget>
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
#include <QNetworkAccessManager>
|
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
#include <QRect>
|
#include <QRect>
|
||||||
#include <QScriptValue>
|
#include <QScriptValue>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
|
||||||
|
#include <NetworkAccessManager.h>
|
||||||
#include <SharedUtil.h>
|
#include <SharedUtil.h>
|
||||||
|
|
||||||
#include "Overlay.h"
|
#include "Overlay.h"
|
||||||
|
@ -46,13 +46,12 @@ public:
|
||||||
virtual void setProperties(const QScriptValue& properties);
|
virtual void setProperties(const QScriptValue& properties);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void replyFinished(QNetworkReply* reply); // we actually want to hide this...
|
void replyFinished(); // we actually want to hide this...
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
QUrl _imageURL;
|
QUrl _imageURL;
|
||||||
QImage _textureImage;
|
QImage _textureImage;
|
||||||
QNetworkAccessManager* _manager;
|
|
||||||
|
|
||||||
GLuint _textureID;
|
GLuint _textureID;
|
||||||
QRect _fromImage; // where from in the image to sample
|
QRect _fromImage; // where from in the image to sample
|
||||||
|
|
Loading…
Reference in a new issue