[QGIS Commit] r13791 - in branches/threading-branch/src: app core

svn_qgis at osgeo.org svn_qgis at osgeo.org
Wed Jun 23 12:01:32 EDT 2010


Author: wonder
Date: 2010-06-23 16:01:32 +0000 (Wed, 23 Jun 2010)
New Revision: 13791

Modified:
   branches/threading-branch/src/app/qgisapp.cpp
   branches/threading-branch/src/core/qgsmaprenderer.cpp
   branches/threading-branch/src/core/qgsmaprenderer.h
Log:
Revived rendering progress bar, stop rendering button moved to right side of the progress bar and made visible only while rendering.
Removed a bunch of blockers for actions that can be safely triggered also when rendering is active.


Modified: branches/threading-branch/src/app/qgisapp.cpp
===================================================================
--- branches/threading-branch/src/app/qgisapp.cpp	2010-06-23 14:15:07 UTC (rev 13790)
+++ branches/threading-branch/src/app/qgisapp.cpp	2010-06-23 16:01:32 UTC (rev 13791)
@@ -528,6 +528,7 @@
   mLastComposerId = 0;
   mLBL = new QgsPalLabeling();
   mMapCanvas->mapRenderer()->setLabelingEngine( mLBL );
+  QgsDebugMsg("\nInit done\n");
 } // QgisApp ctor
 
 
@@ -1703,6 +1704,17 @@
   mProgressBar->setWhatsThis( tr( "Progress bar that displays the status "
                                   "of rendering layers and other time-intensive operations" ) );
   statusBar()->addPermanentWidget( mProgressBar, 1 );
+
+  //stop rendering status bar widget
+  mStopRenderButton = new QToolButton( statusBar() );
+  mStopRenderButton->setMaximumWidth( 20 );
+  mStopRenderButton->setMaximumHeight( 20 );
+  mStopRenderButton->setIcon( getThemeIcon( "mIconDelete.png" ) );
+  mStopRenderButton->setToolTip( tr( "Stop map rendering" ) );
+  mStopRenderButton->hide();
+  statusBar()->addPermanentWidget( mStopRenderButton, 0 );
+
+
   // Bumped the font up one point size since 8 was too
   // small on some platforms. A point size of 9 still provides
   // plenty of display space on 1024x768 resolutions
@@ -1777,13 +1789,7 @@
   statusBar()->addPermanentWidget( mScaleEdit, 0 );
   connect( mScaleEdit, SIGNAL( editingFinished() ), this, SLOT( userScale() ) );
 
-  //stop rendering status bar widget
-  mStopRenderButton = new QToolButton( statusBar() );
-  mStopRenderButton->setMaximumWidth( 20 );
-  mStopRenderButton->setMaximumHeight( 20 );
-  mStopRenderButton->setIcon( getThemeIcon( "mIconDelete.png" ) );
-  mStopRenderButton->setToolTip( tr( "Stop map rendering" ) );
-  statusBar()->addPermanentWidget( mStopRenderButton, 0 );
+  /* Not necessary anymore! rendering doesn't block GUI.
   // render suppression status bar widget
   mRenderSuppressionCBox = new QCheckBox( tr( "Render" ), statusBar() );
   mRenderSuppressionCBox->setChecked( true );
@@ -1794,6 +1800,8 @@
                                         "to add a large number of layers and symbolize them before rendering." ) );
   mRenderSuppressionCBox->setToolTip( tr( "Toggle map rendering" ) );
   statusBar()->addPermanentWidget( mRenderSuppressionCBox, 0 );
+  */
+
   // On the fly projection status bar icon
   // Changed this to a tool button since a QPushButton is
   // sculpted on OS X and the icon is never displayed [gsherman]
@@ -1962,8 +1970,8 @@
            mActionZoomLast, SLOT( setEnabled( bool ) ) );
   connect( mMapCanvas, SIGNAL( zoomNextStatusChanged( bool ) ),
            mActionZoomNext, SLOT( setEnabled( bool ) ) );
-  connect( mRenderSuppressionCBox, SIGNAL( toggled( bool ) ),
-           mMapCanvas, SLOT( setRenderFlag( bool ) ) );
+  //connect( mRenderSuppressionCBox, SIGNAL( toggled( bool ) ),
+  //         mMapCanvas, SLOT( setRenderFlag( bool ) ) );
 
   // connect renderer
   connect( mMapCanvas->mapRenderer(), SIGNAL( drawingProgress( int, int ) ),
@@ -2526,10 +2534,6 @@
   */
 void QgisApp::addVectorLayer()
 {
-  if ( mMapCanvas && mMapCanvas->isDrawing() )
-  {
-    return;
-  }
   mMapCanvas->freeze();
   QgsOpenVectorLayerDialog *ovl = new QgsOpenVectorLayerDialog( this );
 
@@ -2546,8 +2550,7 @@
   mMapCanvas->freeze( false );
 
   delete ovl;
-  // update UI
-  qApp->processEvents();
+
 }
 
 
@@ -2633,9 +2636,6 @@
 
   }
 
-  // update UI
-  qApp->processEvents();
-
   // draw the map
   mMapCanvas->freeze( false );
   mMapCanvas->refresh();
@@ -2718,10 +2718,6 @@
 #else
 void QgisApp::addDatabaseLayer()
 {
-  if ( mMapCanvas && mMapCanvas->isDrawing() )
-  {
-    return;
-  }
 
   // only supports postgis layers at present
   // show the postgis dialog
@@ -2776,9 +2772,6 @@
 
   delete dbs;
 
-  // update UI
-  qApp->processEvents();
-
   // draw the map
   mMapCanvas->freeze( false );
   mMapCanvas->refresh();
@@ -2795,11 +2788,6 @@
 #else
 void QgisApp::addSpatiaLiteLayer()
 {
-  if ( mMapCanvas && mMapCanvas->isDrawing() )
-  {
-    return;
-  }
-
   // show the SpatiaLite dialog
 
   QgsSpatiaLiteSourceSelect *dbs = new QgsSpatiaLiteSourceSelect( this );
@@ -2854,9 +2842,6 @@
   }
   delete dbs;
 
-  // update UI
-  qApp->processEvents();
-
   // draw the map
   mMapCanvas->freeze( false );
   mMapCanvas->refresh();
@@ -2869,10 +2854,6 @@
 
 void QgisApp::addWmsLayer()
 {
-  if ( mMapCanvas && mMapCanvas->isDrawing() )
-  {
-    return;
-  }
   // Fudge for now
   QgsDebugMsg( "about to addRasterLayer" );
 
@@ -2906,10 +2887,8 @@
 //as file new but accepts flags to indicate whether we should prompt to save
 void QgisApp::fileNew( bool thePromptToSaveFlag )
 {
-  if ( mMapCanvas && mMapCanvas->isDrawing() )
-  {
-    return;
-  }
+  // make sure no rendering is going on
+  mMapCanvas->cancelRendering();
 
   if ( thePromptToSaveFlag )
   {
@@ -2924,7 +2903,6 @@
 
   mMapCanvas->freeze( true );
   removeAllLayers();
-  mMapCanvas->clear();
 
   QgsProject* prj = QgsProject::instance();
   prj->title( QString::null );
@@ -2978,11 +2956,6 @@
 
 void QgisApp::newVectorLayer()
 {
-  if ( mMapCanvas && mMapCanvas->isDrawing() )
-  {
-    return;
-  }
-
   QgsNewVectorLayerDialog geomDialog( this );
   if ( geomDialog.exec() == QDialog::Rejected )
   {
@@ -3078,10 +3051,6 @@
 #ifdef HAVE_SPATIALITE
 void QgisApp::newSpatialiteLayer()
 {
-  if ( mMapCanvas && mMapCanvas->isDrawing() )
-  {
-    return;
-  }
   QgsNewSpatialiteLayerDialog spatialiteDialog( this );
   spatialiteDialog.exec();
 }
@@ -3089,10 +3058,8 @@
 
 void QgisApp::fileOpen()
 {
-  if ( mMapCanvas && mMapCanvas->isDrawing() )
-  {
-    return;
-  }
+  // make sure no rendering is going on
+  mMapCanvas->cancelRendering();
 
   // possibly save any pending work before opening a new project
   if ( saveDirty() )
@@ -3206,11 +3173,6 @@
 
 bool QgisApp::fileSave()
 {
-  if ( mMapCanvas && mMapCanvas->isDrawing() )
-  {
-    return false;
-  }
-
   // if we don't have a file name, then obviously we need to get one; note
   // that the project file name is reset to null in fileNew()
   QFileInfo fullPath;
@@ -3284,11 +3246,6 @@
 
 void QgisApp::fileSaveAs()
 {
-  if ( mMapCanvas && mMapCanvas->isDrawing() )
-  {
-    return;
-  }
-
   // Retrieve last used project dir from persistent settings
   QSettings settings;
   QString lastUsedDir = settings.value( "/UI/lastProjectDir", "." ).toString();
@@ -3400,11 +3357,6 @@
 
 void QgisApp::newPrintComposer()
 {
-  if ( mMapCanvas && mMapCanvas->isDrawing() )
-  {
-    return;
-  }
-
   createNewComposer();
 }
 
@@ -4321,15 +4273,6 @@
 
 void QgisApp::deselectAll()
 {
-  if ( !mMapCanvas || mMapCanvas->isDrawing() )
-  {
-    return;
-  }
-
-  // Turn off rendering to improve speed.
-  bool renderFlagState = mMapCanvas->renderFlag();
-  mMapCanvas->setRenderFlag( false );
-
   QMap<QString, QgsMapLayer*> layers = QgsMapLayerRegistry::instance()->mapLayers();
   for ( QMap<QString, QgsMapLayer*>::iterator it = layers.begin(); it != layers.end(); it++ )
   {
@@ -4340,8 +4283,7 @@
     vl->removeSelection();
   }
 
-  // Turn on rendering (if it was on previously)
-  mMapCanvas->setRenderFlag( renderFlagState );
+  mMapCanvas->refresh();
 }
 
 void QgisApp::addVertex()
@@ -4543,9 +4485,6 @@
 
 void QgisApp::layerSubsetString()
 {
-  if ( mMapCanvas && mMapCanvas->isDrawing() )
-    return;
-
   QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( activeLayer() );
   if ( !vlayer )
     return;
@@ -4768,11 +4707,6 @@
 
 void QgisApp::removeLayer()
 {
-  if ( mMapCanvas && mMapCanvas->isDrawing() )
-  {
-    return;
-  }
-
   QgsMapLayer *layer = activeLayer();
 
   if ( !layer )
@@ -5148,11 +5082,6 @@
   */
 QgsVectorLayer* QgisApp::addVectorLayer( QString vectorLayerPath, QString baseName, QString providerKey )
 {
-  if ( mMapCanvas && mMapCanvas->isDrawing() )
-  {
-    return NULL;
-  }
-
   mMapCanvas->freeze();
 
 // Let render() do its own cursor management
@@ -5186,9 +5115,6 @@
     return NULL;
   }
 
-  // update UI
-  qApp->processEvents();
-
   // draw the map
   mMapCanvas->freeze( false );
   mMapCanvas->refresh();
@@ -5224,9 +5150,6 @@
                            tr( "The layer is not a valid layer and can not be added to the map" ) );
   }
 
-  // update UI
-  qApp->processEvents();
-
   // draw the map
   mMapCanvas->freeze( false );
   mMapCanvas->refresh();
@@ -5444,6 +5367,7 @@
   {
     mProgressBar->reset();
     mProgressBar->hide();
+    mStopRenderButton->hide();
   }
   else
   {
@@ -5451,6 +5375,8 @@
     if ( !mProgressBar->isVisible() )
     {
       mProgressBar->show();
+      if (mMapCanvas->mapRenderer()->isDrawing())
+        mStopRenderButton->show();
     }
     mProgressBar->setMaximum( theTotalSteps );
     mProgressBar->setValue( theProgress );
@@ -6035,11 +5961,6 @@
 // this is a slot for action from GUI to add raster layer
 void QgisApp::addRasterLayer()
 {
-  if ( mMapCanvas && mMapCanvas->isDrawing() )
-  {
-    return;
-  }
-
   QString fileFilters;
 
   QStringList selectedFiles;
@@ -6066,11 +5987,6 @@
 //
 bool QgisApp::addRasterLayer( QgsRasterLayer *theRasterLayer )
 {
-  if ( mMapCanvas && mMapCanvas->isDrawing() )
-  {
-    return false;
-  }
-
   Q_CHECK_PTR( theRasterLayer );
 
   if ( ! theRasterLayer )
@@ -6105,11 +6021,6 @@
 
 QgsRasterLayer* QgisApp::addRasterLayer( QString const & rasterFile, QString const & baseName, bool guiWarning )
 {
-  if ( mMapCanvas && mMapCanvas->isDrawing() )
-  {
-    return NULL;
-  }
-
   // let the user know we're going to possibly be taking a while
   QApplication::setOverrideCursor( Qt::WaitCursor );
 
@@ -6175,11 +6086,6 @@
 {
   QgsDebugMsg( "about to get library for " + providerKey );
 
-  if ( mMapCanvas && mMapCanvas->isDrawing() )
-  {
-    return 0;
-  }
-
   mMapCanvas->freeze();
 
 // Let render() do its own cursor management
@@ -6217,8 +6123,6 @@
                            tr( "The layer is not a valid layer and can not be added to the map" ) );
   }
 
-  // update UI
-  qApp->processEvents();
   // draw the map
   mMapCanvas->freeze( false );
   mMapCanvas->refresh();
@@ -6234,11 +6138,6 @@
 //create a raster layer object and delegate to addRasterLayer(QgsRasterLayer *)
 bool QgisApp::addRasterLayers( QStringList const &theFileNameQStringList, bool guiWarning )
 {
-  if ( mMapCanvas && mMapCanvas->isDrawing() )
-  {
-    return false;
-  }
-
   if ( theFileNameQStringList.empty() )
   {
     // no files selected so bail out, but
@@ -6363,11 +6262,6 @@
 */
 void QgisApp::customProjection()
 {
-  if ( mMapCanvas && mMapCanvas->isDrawing() )
-  {
-    return;
-  }
-
   // Create an instance of the Custom Projection Designer modeless dialog.
   // Autodelete the dialog when closing since a pointer is not retained.
   QgsCustomProjectionDialog * myDialog = new QgsCustomProjectionDialog( this );

Modified: branches/threading-branch/src/core/qgsmaprenderer.cpp
===================================================================
--- branches/threading-branch/src/core/qgsmaprenderer.cpp	2010-06-23 14:15:07 UTC (rev 13790)
+++ branches/threading-branch/src/core/qgsmaprenderer.cpp	2010-06-23 16:01:32 UTC (rev 13791)
@@ -68,6 +68,8 @@
 
   mLabelingEngine = NULL;
 
+  connect(QgsMapLayerRegistry::instance(), SIGNAL(layerWillBeRemoved(QString)), this, SLOT(handleLayerRemoval(QString)));
+
   //connect(&mFW, SIGNAL(finished()), SLOT(futureFinished()));
 }
 
@@ -415,24 +417,27 @@
     // Now do the call to the layer that actually does
     // the rendering work!
     //
-    connect( ml, SIGNAL( drawingProgress( int, int ) ), this, SLOT( onDrawingProgress( int, int ) ) );
 
+    // onDrawingProgress() does nothing
+    //connect( ml, SIGNAL( drawingProgress( int, int ) ), this, SLOT( onDrawingProgress( int, int ) ) );
+
     if ( !mThreadingEnabled )
       renderLayerNoThreading( ml );
     else
       renderLayerThreading( ml );
 
-    disconnect( ml, SIGNAL( drawingProgress( int, int ) ), this, SLOT( onDrawingProgress( int, int ) ) );
+    //disconnect( ml, SIGNAL( drawingProgress( int, int ) ), this, SLOT( onDrawingProgress( int, int ) ) );
   }
 
   if ( mThreadingEnabled )
   {
     QgsDebugMsg("STARTING THREADED RENDERING!");
 
-    //QtConcurrent::blockingMap(layers, _renderLayerThreading);
-
     connect(&mFW, SIGNAL(finished()), SLOT(futureFinished()));
+    connect(&mFW, SIGNAL(progressValueChanged(int)), this, SLOT(futureProgress(int)));
 
+    emit drawingProgress(0, mThreadedJobs.count());
+
     mFuture = QtConcurrent::map(mThreadedJobs, _renderLayerThreading);
     mFW.setFuture(mFuture);
   }
@@ -455,6 +460,12 @@
   return i;
 }
 
+void QgsMapRenderer::futureProgress(int value)
+{
+  QgsDebugMsg(QString("future progress: %1/%2").arg(value).arg(mFW.progressMaximum()));
+  emit drawingProgress(value, mThreadedJobs.count());
+}
+
 void QgsMapRenderer::futureFinished()
 {
   QgsDebugMsg("THREADED RENDERING FINISHED!");
@@ -473,7 +484,10 @@
   QgsDebugMsg("THREADED RENDERING DONE!");
 
   disconnect(&mFW, SIGNAL(finished()), this, SLOT(futureFinished()));
+  disconnect(&mFW, SIGNAL(progressValueChanged(int)), this, SLOT(futureProgress(int)));
 
+  emit drawingProgress(1,1);
+
   QPainter painter;
   painter.begin(&i);
   mRenderContext.setPainter(&painter);
@@ -785,7 +799,7 @@
 {
   // TODO: emit signal with progress
 // QgsDebugMsg(QString("onDrawingProgress: %1 / %2").arg(current).arg(total));
-  emit updateMap();
+  //emit updateMap();
 }
 
 
@@ -1396,6 +1410,18 @@
   }
 }
 
+
+void QgsMapRenderer::handleLayerRemoval(QString layerId)
+{
+  if (mLayerSet.contains(layerId))
+  {
+    // make sure that the layer won't be used in further rendering
+    if (isDrawing())
+      cancelThreadedRendering();
+    mLayerSet.removeAll(layerId);
+  }
+}
+
 // ------------------------
 
 QgsMapRendererCache::QgsMapRendererCache()

Modified: branches/threading-branch/src/core/qgsmaprenderer.h
===================================================================
--- branches/threading-branch/src/core/qgsmaprenderer.h	2010-06-23 14:15:07 UTC (rev 13790)
+++ branches/threading-branch/src/core/qgsmaprenderer.h	2010-06-23 16:01:32 UTC (rev 13791)
@@ -288,6 +288,7 @@
 
     void destinationSrsChanged();
 
+    //! @note not used anymore
     void updateMap();
 
     void mapUnitsChanged();
@@ -298,12 +299,18 @@
   public slots:
 
     //! called by signal from layer current being drawn
+    //! @note currently does nothing
     void onDrawingProgress( int current, int total );
 
     void futureFinished();
 
+    void futureProgress(int value);
+
     void clearLayerCache();
 
+    //! called to map layer registry
+    void handleLayerRemoval(QString layerId);
+
   protected:
 
     //! adjust extent to fit the pixmap size



More information about the QGIS-commit mailing list