diff --git a/src/GUI/PreviewImageItem.cxx b/src/GUI/PreviewImageItem.cxx index 1480993ca..f9c4d4a70 100644 --- a/src/GUI/PreviewImageItem.cxx +++ b/src/GUI/PreviewImageItem.cxx @@ -78,6 +78,17 @@ float PreviewImageItem::aspectRatio() const return static_cast(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) { if (m_imageUrl == url) @@ -117,6 +128,11 @@ void PreviewImageItem::setImage(QImage image) void PreviewImageItem::onFinished() { QNetworkReply* reply = qobject_cast(sender()); + if (reply->url() != m_imageUrl) { + // if replies arrive out of order, don't trample the correct one + return; + } + QImage img; if (!img.load(reply, nullptr)) { 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() << reply->errorString(); + qWarning() << Q_FUNC_INFO << "failed to download:" << reply->url(); + qWarning() << "\t" << reply->errorString(); m_requestActive = false; emit isLoadingChanged(); } diff --git a/src/GUI/PreviewImageItem.hxx b/src/GUI/PreviewImageItem.hxx index 3d8970450..19b048298 100644 --- a/src/GUI/PreviewImageItem.hxx +++ b/src/GUI/PreviewImageItem.hxx @@ -37,6 +37,11 @@ public: 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: void imageUrlChanged(); void sourceSizeChanged(); diff --git a/src/GUI/qml/AircraftPreviewPanel.qml b/src/GUI/qml/AircraftPreviewPanel.qml index 969e66185..ef9608262 100644 --- a/src/GUI/qml/AircraftPreviewPanel.qml +++ b/src/GUI/qml/AircraftPreviewPanel.qml @@ -9,6 +9,7 @@ Rectangle { readonly property bool __havePreviews: (previews.length > 0) onPreviewsChanged: { activePreview = 0 + preview.clear() } height: width / preview.aspectRatio @@ -25,7 +26,15 @@ Rectangle { id: preview width: parent.width 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 { anchors.fill: parent diff --git a/src/GUI/qml/Summary.qml b/src/GUI/qml/Summary.qml index 116a843c5..1ad2b98f4 100644 --- a/src/GUI/qml/Summary.qml +++ b/src/GUI/qml/Summary.qml @@ -29,9 +29,14 @@ Item { width: height * aspectRatio height: scale * sourceSize.height - property var urlsList: [] + property var urlsList: _launcher.defaultSplashUrls() property int __currentUrl: 0 + Binding on urlsList { + when: _launcher.selectedAircraftInfo.previews.length > 0 + value: _launcher.selectedAircraftInfo.previews + } + onUrlsListChanged: { __currentUrl = 0; } @@ -46,29 +51,14 @@ Item { } } - function currentPreviewUrl() + function currentUrl() { - if (__currentUrl >= urlsList.length) return ""; + if (urlsList.length <= __currentUrl) return ""; return urlsList[__currentUrl]; } visible: imageUrl != "" - imageUrl: currentPreviewUrl() - -// 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() - } + imageUrl: currentUrl() } Text {