[QGIS Commit] r15538 - in trunk/qgis/src: core core/raster providers/gdal

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sat Mar 19 13:40:19 EDT 2011


Author: rblazek
Date: 2011-03-19 10:40:19 -0700 (Sat, 19 Mar 2011)
New Revision: 15538

Modified:
   trunk/qgis/src/core/qgsrasterdataprovider.h
   trunk/qgis/src/core/raster/qgsrasterlayer.cpp
   trunk/qgis/src/core/raster/qgsrasterlayer.h
   trunk/qgis/src/providers/gdal/qgsgdalprovider.cpp
   trunk/qgis/src/providers/gdal/qgsgdalprovider.h
Log:
progress signals

Modified: trunk/qgis/src/core/qgsrasterdataprovider.h
===================================================================
--- trunk/qgis/src/core/qgsrasterdataprovider.h	2011-03-19 13:26:00 UTC (rev 15537)
+++ trunk/qgis/src/core/qgsrasterdataprovider.h	2011-03-19 17:40:19 UTC (rev 15538)
@@ -107,6 +107,13 @@
       /*! Max current value */                              ColorInterpretationMax = 16
     };
 
+    // Progress types
+    enum Progress
+    {
+      ProgressHistogram = 0,
+      ProgressPyramids  = 1
+    };
+
     QgsRasterDataProvider();
 
     QgsRasterDataProvider( QString const & uri );
@@ -460,6 +467,11 @@
     /** \brief Set null value in char */
     QByteArray noValueBytes( int theBandNo );
 
+  signals:
+    /** Emit a signal to notify of the progress event.
+      * Emited theProgress is in percents (0.0-100.0) */
+    void progress( int theType, double theProgress, QString theMessage );
+
   protected:
     /**Dots per intch. Extended WMS (e.g. QGIS mapserver) support DPI dependent output and therefore
     are suited for printing. A value of -1 means it has not been set

Modified: trunk/qgis/src/core/raster/qgsrasterlayer.cpp
===================================================================
--- trunk/qgis/src/core/raster/qgsrasterlayer.cpp	2011-03-19 13:26:00 UTC (rev 15537)
+++ trunk/qgis/src/core/raster/qgsrasterlayer.cpp	2011-03-19 17:40:19 UTC (rev 15538)
@@ -2483,6 +2483,12 @@
     mRasterTransparency.initializeTransparentPixelList( mNoDataValue );
   }
 
+  // Connect provider signals
+  connect(
+    mDataProvider, SIGNAL( progress( int, double, QString ) ),
+    this,          SLOT( onProgress( int, double, QString ) )
+  );
+
   //mark the layer as valid
   mValid = true;
 
@@ -2945,6 +2951,12 @@
   emit drawingProgress( theProgress, theMax );
 }
 
+void QgsRasterLayer::onProgress( int theType, double theProgress, QString theMesssage )
+{
+  QgsDebugMsg( QString( "theProgress = %1" ).arg( theProgress ) );
+  emit progressUpdate(( int )theProgress );
+}
+
 //////////////////////////////////////////////////////////
 //
 // Protected methods

Modified: trunk/qgis/src/core/raster/qgsrasterlayer.h
===================================================================
--- trunk/qgis/src/core/raster/qgsrasterlayer.h	2011-03-19 13:26:00 UTC (rev 15537)
+++ trunk/qgis/src/core/raster/qgsrasterlayer.h	2011-03-19 17:40:19 UTC (rev 15538)
@@ -674,6 +674,9 @@
     /** \brief Propagate progress updates from GDAL up to the parent app */
     void updateProgress( int, int );
 
+    /** \brief recieve progress signal from provider */
+    void onProgress( int, double, QString );
+
   signals:
     /** \brief Signal for notifying listeners of long running processes */
     void progressUpdate( int theValue );

Modified: trunk/qgis/src/providers/gdal/qgsgdalprovider.cpp
===================================================================
--- trunk/qgis/src/providers/gdal/qgsgdalprovider.cpp	2011-03-19 13:26:00 UTC (rev 15537)
+++ trunk/qgis/src/providers/gdal/qgsgdalprovider.cpp	2011-03-19 17:40:19 UTC (rev 15538)
@@ -55,6 +55,11 @@
 static QString PROVIDER_KEY = "gdal";
 static QString PROVIDER_DESCRIPTION = "GDAL provider";
 
+struct QgsGdalProgress
+{
+  int type;
+  QgsGdalProvider *provider;
+};
 //
 // global callback function
 //
@@ -62,9 +67,11 @@
                                   const char * pszMessage,
                                   void * pProgressArg )
 {
-  // TODO: add signals to providers
   static double dfLastComplete = -1.0;
 
+  QgsGdalProgress *prog = static_cast<QgsGdalProgress *>( pProgressArg );
+  QgsGdalProvider *mypProvider = prog->provider;
+
   if ( dfLastComplete > dfComplete )
   {
     if ( dfLastComplete >= 1.0 )
@@ -84,16 +91,18 @@
 
     if ( nPercent == 100 )
     {
-      fprintf( stdout, "%d - done.\n", ( int ) floor( dfComplete*100 ) );
+      //fprintf( stdout, "%d - done.\n", ( int ) floor( dfComplete*100 ) );
       //mypLayer->showProgress( 100 );
     }
     else
     {
       int myProgress = ( int ) floor( dfComplete * 100 );
-      fprintf( stdout, "%d.", myProgress );
+      //fprintf( stdout, "%d.", myProgress );
       //mypLayer->showProgress( myProgress );
-      fflush( stdout );
+      //fflush( stdout );
     }
+
+    mypProvider->emitProgress( prog->type, dfComplete * 100, QString( pszMessage ) );
   }
   dfLastComplete = dfComplete;
 
@@ -547,9 +556,9 @@
   // TODO!!!: Check data alignment!!! May it happen that nearest value which
   // is not nearest is assigned to an output cell???
 
-  QgsDebugMsg( "Entered" );
+  //QgsDebugMsg( "Entered" );
 
-  QgsDebugMsg( "yBlock = "  + QString::number( yBlock ) );
+  //QgsDebugMsg( "yBlock = "  + QString::number( yBlock ) );
 
   GDALRasterBandH myGdalBand = GDALGetRasterBand( mGdalDataset, theBandNo );
   //GDALReadBlock( myGdalBand, xBlock, yBlock, block );
@@ -1312,11 +1321,15 @@
      *          void *      pProgressData
      *          )
      */
+
+    QgsGdalProgress myProg;
+    myProg.type = ProgressHistogram;
+    myProg.provider = this;
     double myerval = ( theBandStats.maximumValue - theBandStats.minimumValue ) / theBinCount;
     GDALGetRasterHistogram( myGdalBand, theBandStats.minimumValue - 0.1*myerval,
                             theBandStats.maximumValue + 0.1*myerval, theBinCount, myHistogramArray,
                             theIgnoreOutOfRangeFlag, theHistogramEstimatedFlag, progressCallback,
-                            this ); //this is the arg for our custome gdal progress callback
+                            &myProg ); //this is the arg for our custome gdal progress callback
 
     for ( int myBin = 0; myBin < theBinCount; myBin++ )
     {
@@ -1443,21 +1456,24 @@
         //to create corrupted images. The images can be repaired
         //by running one of the other resampling strategies below.
         //see ticket #284
+        QgsGdalProgress myProg;
+        myProg.type = ProgressPyramids;
+        myProg.provider = this;
         if ( theResamplingMethod == tr( "Average Magphase" ) )
         {
           myError = GDALBuildOverviews( mGdalBaseDataset, "MODE", 1, myOverviewLevelsArray, 0, NULL,
-                                        progressCallback, this ); //this is the arg for the gdal progress callback
+                                        progressCallback, &myProg ); //this is the arg for the gdal progress callback
         }
         else if ( theResamplingMethod == tr( "Average" ) )
 
         {
           myError = GDALBuildOverviews( mGdalBaseDataset, "AVERAGE", 1, myOverviewLevelsArray, 0, NULL,
-                                        progressCallback, this ); //this is the arg for the gdal progress callback
+                                        progressCallback, &myProg ); //this is the arg for the gdal progress callback
         }
         else // fall back to nearest neighbor
         {
           myError = GDALBuildOverviews( mGdalBaseDataset, "NEAREST", 1, myOverviewLevelsArray, 0, NULL,
-                                        progressCallback, this ); //this is the arg for the gdal progress callback
+                                        progressCallback, &myProg ); //this is the arg for the gdal progress callback
         }
 
         if ( myError == CE_Failure || CPLGetLastErrorNo() == CPLE_NotSupported )
@@ -1587,6 +1603,10 @@
   return subLayers_( mGdalDataset );
 }
 
+void QgsGdalProvider::emitProgress( int theType, double theProgress, QString theMessage )
+{
+  emit progress( theType, theProgress, theMessage );
+}
 
 /**
  * Class factory to return a pointer to a newly created

Modified: trunk/qgis/src/providers/gdal/qgsgdalprovider.h
===================================================================
--- trunk/qgis/src/providers/gdal/qgsgdalprovider.h	2011-03-19 13:26:00 UTC (rev 15537)
+++ trunk/qgis/src/providers/gdal/qgsgdalprovider.h	2011-03-19 17:40:19 UTC (rev 15538)
@@ -247,6 +247,8 @@
     /** \brief Close data set and release related data */
     void closeDataset();
 
+    /** Emit a signal to notify of the progress event. */
+    void emitProgress( int theType, double theProgress, QString theMessage );
 
   private:
     // initialize CRS from wkt



More information about the QGIS-commit mailing list