20 #ifndef _STELTEXTURELOADER_HPP_
21 #define _STELTEXTURELOADER_HPP_
23 #include <QApplication>
26 #include <QNetworkAccessManager>
27 #include <QNetworkReply>
32 #include "StelApp.hpp"
33 #include "StelUtils.hpp"
53 void error(
const QString& errorMsg);
59 , loaderThread(loaderThread)
66 moveToThread(loaderThread);
71 QThread* loaderThread;
93 QTimer::singleShot(delay,
this, SLOT(start()));
98 Q_ASSERT_X(QThread::currentThread() == QApplication::instance()->thread(),
100 "StelTextureLoader::abort must be called from the main thread");
101 if (networkReply != NULL) {networkReply->abort();}
112 QNetworkRequest request = QNetworkRequest(QUrl(url));
114 request.setAttribute(QNetworkRequest::CacheLoadControlAttribute,
115 QNetworkRequest::PreferCache);
118 connect(networkReply, SIGNAL(
finished()),
this, SLOT(onNetworkReply()));
125 void onNetworkReply()
127 if (networkReply->error() != QNetworkReply::NoError)
129 emit
error(networkReply->errorString());
133 QByteArray data = networkReply->readAll();
134 QImage image = QImage::fromData(data);
137 emit
error(
"Unable to parse image data");
143 networkReply->deleteLater();
151 QNetworkReply* networkReply;
171 QTimer::singleShot(delay,
this, SLOT(start()));
183 QTimer::singleShot(0,
this, SLOT(load()));
191 QImage image = QImage(path);
194 emit
error(
"Image " + path +
" failed to load");
204 #endif // _STELTEXTURELOADER_HPP_