changeset 1605:ae2d5f8ff005

When asked to render the whole view width, we need to wait for the layers to be ready before we can determine what the width is
author Chris Cannam
date Thu, 30 Apr 2020 14:47:13 +0100
parents 5feb1a8318df
children d6976d231efb
files view/View.cpp view/View.h
diffstat 2 files changed, 32 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/view/View.cpp	Wed Apr 29 17:47:55 2020 +0100
+++ b/view/View.cpp	Thu Apr 30 14:47:13 2020 +0100
@@ -2992,19 +2992,12 @@
 }
 
 bool
-View::render(QPainter &paint, int xorigin, sv_frame_t f0, sv_frame_t f1)
+View::waitForLayersToBeReady()
 {
-    int x0 = int(round(m_zoomLevel.framesToPixels(double(f0))));
-    int x1 = int(round(m_zoomLevel.framesToPixels(double(f1))));
-
-    int w = x1 - x0;
-
-    sv_frame_t origCentreFrame = m_centreFrame;
-
     bool someLayersIncomplete = false;
 
 #ifdef DEBUG_VIEW
-    SVDEBUG << "View::render: checking completion" << endl;
+    SVDEBUG << "View::waitForLayersToBeReady: checking completion" << endl;
 #endif
     
     for (LayerList::iterator i = m_layerStack.begin();
@@ -3064,8 +3057,31 @@
     }
 
 #ifdef DEBUG_VIEW
-    SVDEBUG << "View::render: ok, we're ready" << endl;
+    SVDEBUG << "View::waitForLayersToBeReady: ok, we're ready" << endl;
 #endif
+
+    return true;
+}
+
+bool
+View::render(QPainter &paint, int xorigin, sv_frame_t f0, sv_frame_t f1)
+{
+    int x0 = int(round(m_zoomLevel.framesToPixels(double(f0))));
+    int x1 = int(round(m_zoomLevel.framesToPixels(double(f1))));
+
+    int w = x1 - x0;
+
+#ifdef DEBUG_VIEW
+    SVDEBUG << "View::render: Render request is for frames " << f0
+            << " to " << f1 << " (pixels " << x0 << " to " << x1
+            << ", width " << w << ")" << endl;
+#endif
+
+    if (!waitForLayersToBeReady()) {
+        return false;
+    }
+
+    sv_frame_t origCentreFrame = m_centreFrame;
     
     QProgressDialog progress(tr("Rendering image..."),
                              tr("Cancel"), 0, w / width(), this);
@@ -3123,6 +3139,10 @@
 QImage *
 View::renderToNewImage()
 {
+    if (!waitForLayersToBeReady()) {
+        return nullptr;
+    }
+    
     sv_frame_t f0 = getModelsStartFrame();
     sv_frame_t f1 = getModelsEndFrame();
 
--- a/view/View.h	Wed Apr 29 17:47:55 2020 +0100
+++ b/view/View.h	Thu Apr 30 14:47:13 2020 +0100
@@ -530,6 +530,8 @@
 
     void checkProgress(ModelId);
     void checkAlignmentProgress(ModelId);
+
+    bool waitForLayersToBeReady(); // returns false if user cancelled waiting
     
     int getProgressBarWidth() const; // if visible