1
0
Fork 0

Launcher: fixes for lingering previews

Also better fix for some ‘assign Qurl from undefined’ warnings
This commit is contained in:
James Turner 2018-05-09 20:11:58 +01:00
parent 8738e18921
commit 1555e1d6cb
4 changed files with 42 additions and 22 deletions

View file

@ -78,6 +78,17 @@ float PreviewImageItem::aspectRatio() const
return static_cast<float>(m_image.width()) / m_image.height(); return static_cast<float>(m_image.width()) / m_image.height();
} }
void PreviewImageItem::clear()
{
m_imageUrl.clear();
m_image = QImage{};
m_imageDirty = true;
m_requestActive = false;
update();
emit imageUrlChanged();
emit isLoadingChanged();
}
void PreviewImageItem::setImageUrl( QUrl url) void PreviewImageItem::setImageUrl( QUrl url)
{ {
if (m_imageUrl == url) if (m_imageUrl == url)
@ -117,6 +128,11 @@ void PreviewImageItem::setImage(QImage image)
void PreviewImageItem::onFinished() void PreviewImageItem::onFinished()
{ {
QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender()); QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
if (reply->url() != m_imageUrl) {
// if replies arrive out of order, don't trample the correct one
return;
}
QImage img; QImage img;
if (!img.load(reply, nullptr)) { if (!img.load(reply, nullptr)) {
qWarning() << Q_FUNC_INFO << "failed to read image data from" << reply->url(); qWarning() << Q_FUNC_INFO << "failed to read image data from" << reply->url();
@ -137,8 +153,8 @@ void PreviewImageItem::onDownloadError(QNetworkReply::NetworkError errorCode)
} }
} }
qWarning() << "failed to download:" << reply->url(); qWarning() << Q_FUNC_INFO << "failed to download:" << reply->url();
qWarning() << reply->errorString(); qWarning() << "\t" << reply->errorString();
m_requestActive = false; m_requestActive = false;
emit isLoadingChanged(); emit isLoadingChanged();
} }

View file

@ -37,6 +37,11 @@ public:
float aspectRatio() const; float aspectRatio() const;
/**
@brief clear the image immediately, so we don't see a stale / expired
one while attemtping to load the next one
*/
Q_INVOKABLE void clear();
signals: signals:
void imageUrlChanged(); void imageUrlChanged();
void sourceSizeChanged(); void sourceSizeChanged();

View file

@ -9,6 +9,7 @@ Rectangle {
readonly property bool __havePreviews: (previews.length > 0) readonly property bool __havePreviews: (previews.length > 0)
onPreviewsChanged: { onPreviewsChanged: {
activePreview = 0 activePreview = 0
preview.clear()
} }
height: width / preview.aspectRatio height: width / preview.aspectRatio
@ -25,7 +26,15 @@ Rectangle {
id: preview id: preview
width: parent.width width: parent.width
height: parent.height height: parent.height
imageUrl: __havePreviews ? root.previews[root.activePreview] : ""
function activePreviewUrl()
{
if (!__havePreviews) return "";
if (root.previews.length <= root.activePreview) return "";
return root.previews[root.activePreview];
}
imageUrl: activePreviewUrl();
Rectangle { Rectangle {
anchors.fill: parent anchors.fill: parent

View file

@ -29,9 +29,14 @@ Item {
width: height * aspectRatio width: height * aspectRatio
height: scale * sourceSize.height height: scale * sourceSize.height
property var urlsList: [] property var urlsList: _launcher.defaultSplashUrls()
property int __currentUrl: 0 property int __currentUrl: 0
Binding on urlsList {
when: _launcher.selectedAircraftInfo.previews.length > 0
value: _launcher.selectedAircraftInfo.previews
}
onUrlsListChanged: { onUrlsListChanged: {
__currentUrl = 0; __currentUrl = 0;
} }
@ -46,29 +51,14 @@ Item {
} }
} }
function currentPreviewUrl() function currentUrl()
{ {
if (__currentUrl >= urlsList.length) return ""; if (urlsList.length <= __currentUrl) return "";
return urlsList[__currentUrl]; return urlsList[__currentUrl];
} }
visible: imageUrl != "" visible: imageUrl != ""
imageUrl: currentPreviewUrl() imageUrl: currentUrl()
// conditional binding when we have valid previews
Binding {
when: (_launcher.selectedAircraftInfo.previews.length > 0)
target: preview
property: "urlsList"
value: _launcher.selectedAircraftInfo.previews
}
Binding {
when: _launcher.selectedAircraftInfo.previews.length === 0
target: preview
property: "urlsList"
value: _launcher.defaultSplashUrls()
}
} }
Text { Text {