[QGIS Commit] r8957 - in trunk/qgis/src: app core/raster ui

svn_qgis at osgeo.org svn_qgis at osgeo.org
Fri Aug 1 06:52:51 EDT 2008


Author: timlinux
Date: 2008-08-01 06:52:50 -0400 (Fri, 01 Aug 2008)
New Revision: 8957

Modified:
   trunk/qgis/src/app/qgsrasterlayerproperties.cpp
   trunk/qgis/src/core/raster/qgsrasterlayer.cpp
   trunk/qgis/src/core/raster/qgsrasterlayer.h
   trunk/qgis/src/ui/qgsrasterlayerpropertiesbase.ui
Log:
Added callback functions and hooked it up to the raster properties dialogs so that building pyramids and computing histogram now shows progress bar indication. Also change cursor to hourglass while computing histograms.

Modified: trunk/qgis/src/app/qgsrasterlayerproperties.cpp
===================================================================
--- trunk/qgis/src/app/qgsrasterlayerproperties.cpp	2008-08-01 10:33:01 UTC (rev 8956)
+++ trunk/qgis/src/app/qgsrasterlayerproperties.cpp	2008-08-01 10:52:50 UTC (rev 8957)
@@ -1570,6 +1570,7 @@
 void QgsRasterLayerProperties::on_buttonBuildPyramids_clicked()
 {
 
+  connect(mRasterLayer, SIGNAL(progressUpdate(int)), mPyramidProgress, SLOT(setValue(int)));
   //
   // Go through the list marking any files that are selected in the listview
   // as true so that we can generate pyramids for them.
@@ -1592,6 +1593,7 @@
   QApplication::setOverrideCursor(Qt::WaitCursor);
   QString res = mRasterLayer->buildPyramids(myPyramidList,cboResamplingMethod->currentText());
   QApplication::restoreOverrideCursor();
+  disconnect(mRasterLayer, SIGNAL(progressUpdate(int)), mPyramidProgress, SLOT(setValue(int)));
   if (!res.isNull())
   {
     if (res == "ERROR_WRITE_ACCESS")
@@ -1867,6 +1869,8 @@
 
 void QgsRasterLayerProperties::on_pbnHistRefresh_clicked()
 {
+  connect(mRasterLayer, SIGNAL(progressUpdate(int)), mHistogramProgress, SLOT(setValue(int)));
+  QApplication::setOverrideCursor(Qt::WaitCursor);
 #ifdef QGISDEBUG
   std::cout << "QgsRasterLayerProperties::on_pbnHistRefresh_clicked" << std::endl;
 #endif
@@ -1960,6 +1964,7 @@
       myFirstItemFlag=false;
     }
   }
+  disconnect(mRasterLayer, SIGNAL(progressUpdate(int)), mHistogramProgress, SLOT(setValue(int)));
 #ifdef QGISDEBUG
   std::cout << "max " << myYAxisMax << std::endl;
   std::cout << "min " << myYAxisMin << std::endl;
@@ -2289,6 +2294,7 @@
   //
   myPainter.end();
   pixHistogram->setPixmap(myPixmap);
+  QApplication::restoreOverrideCursor();
 }
 
 void QgsRasterLayerProperties::on_pbnImportTransparentPixelValues_clicked()

Modified: trunk/qgis/src/core/raster/qgsrasterlayer.cpp
===================================================================
--- trunk/qgis/src/core/raster/qgsrasterlayer.cpp	2008-08-01 10:33:01 UTC (rev 8956)
+++ trunk/qgis/src/core/raster/qgsrasterlayer.cpp	2008-08-01 10:52:50 UTC (rev 8957)
@@ -3728,18 +3728,18 @@
         if(theResamplingMethod==tr("Average Magphase"))
         {
           myError = GDALBuildOverviews( mGdalDataset, "MODE", 1, myOverviewLevelsArray, 0, NULL,
-              GDALDummyProgress, NULL );
+              progressCallback, this); //this is the arg for the gdal progress callback
         }
         else if(theResamplingMethod==tr("Average"))
 
         {
           myError = GDALBuildOverviews( mGdalDataset, "AVERAGE", 1, myOverviewLevelsArray, 0, NULL,
-              GDALDummyProgress, NULL );
+              progressCallback, this); //this is the arg for the gdal progress callback
         }
         else // fall back to nearest neighbor
         {
           myError = GDALBuildOverviews( mGdalDataset, "NEAREST", 1, myOverviewLevelsArray, 0, NULL,
-              GDALDummyProgress, NULL );
+              progressCallback, this); //this is the arg for the gdal progress callback
         }
         if (myError == CE_Failure || CPLGetLastErrorNo()==CPLE_NotSupported  )
         {
@@ -4749,7 +4749,10 @@
      *          ) 
      */
     double myerval = (myRasterBandStats.maxVal-myRasterBandStats.minVal)/theBinCount;
-    GDALGetRasterHistogram( myGdalBand, myRasterBandStats.minVal-0.1*myerval, myRasterBandStats.maxVal+0.1*myerval, theBinCount, myHistogramArray ,theIgnoreOutOfRangeFlag ,theHistogramEstimatedFlag , GDALDummyProgress, NULL );
+    GDALGetRasterHistogram( myGdalBand, myRasterBandStats.minVal-0.1*myerval,
+        myRasterBandStats.maxVal+0.1*myerval, theBinCount, myHistogramArray
+        ,theIgnoreOutOfRangeFlag ,theHistogramEstimatedFlag , progressCallback,
+        this ); //this is the arg for our custome gdal progress callback
 
     for (int myBin = 0; myBin <theBinCount; myBin++)
     {
@@ -5219,3 +5222,53 @@
     setContrastEnhancementAlgorithm(QgsContrastEnhancement::NO_STRETCH, theGenerateLookupTableFlag);
   }
 }
+
+void QgsRasterLayer::showProgress(int theValue)
+{
+  emit progressUpdate(theValue);
+}
+//
+// global callback function
+//
+int CPL_STDCALL progressCallback( double dfComplete, 
+    const char * pszMessage,
+    void * pProgressArg)
+{
+  static double dfLastComplete = -1.0;
+
+  QgsRasterLayer * mypLayer = (QgsRasterLayer *) pProgressArg;
+
+  if( dfLastComplete > dfComplete )
+  {
+    if( dfLastComplete >= 1.0 )
+      dfLastComplete = -1.0;
+    else
+      dfLastComplete = dfComplete;
+  }
+
+  if( floor(dfLastComplete*10) != floor(dfComplete*10) )
+  {
+    int    nPercent = (int) floor(dfComplete*100);
+
+    if( nPercent == 0 && pszMessage != NULL )
+    {
+      //fprintf( stdout, "%s:", pszMessage );
+    }
+
+    if( nPercent == 100 )
+    {
+      //fprintf( stdout, "%d - done.\n", (int) floor(dfComplete*100) );
+      mypLayer->showProgress(100);
+    }
+    else
+    {
+      int myProgress = (int) floor(dfComplete*100);
+      //fprintf( stdout, "%d.", myProgress);
+      mypLayer->showProgress(myProgress);
+      //fflush( stdout );
+    }
+  }
+  dfLastComplete = dfComplete;
+
+  return TRUE;
+}

Modified: trunk/qgis/src/core/raster/qgsrasterlayer.h
===================================================================
--- trunk/qgis/src/core/raster/qgsrasterlayer.h	2008-08-01 10:33:01 UTC (rev 8956)
+++ trunk/qgis/src/core/raster/qgsrasterlayer.h	2008-08-01 10:52:50 UTC (rev 8957)
@@ -137,24 +137,17 @@
 #include "qgsrastertransparency.h"
 #include "qgsrastershader.h"
 #include "qgsrastershaderfunction.h"
-
-/*
- * 
- * New includes that will convert this class to a data provider interface
- * (B Morley)
- *
- */ 
- 
 #include "qgsrasterdataprovider.h"
 
-/*
- * END
- */
 
 #define CPL_SUPRESS_CPLUSPLUS
-
 #include <gdal.h>
 
+int CPL_STDCALL progressCallback( double dfComplete, 
+    const char *pszMessage,
+    void * pProgressArg );
+
+
 //
 // Forward declarations
 //
@@ -1113,11 +1106,20 @@
   //! Which provider is being used for this Raster Layer?
   QString providerKey();
 
+  /** A wrapper function to emit a progress update signal.
+   * For example used by gdal callback to show pyramid building progress.
+   */
+  void showProgress(int theValue);
+  
 public slots:
 
   void showStatusMessage(const QString & theMessage);
 
+signals:
+  //for notifying listeners of long running processes
+  void progressUpdate(int theValue);
 
+
 private:
   
   //! Data provider key

Modified: trunk/qgis/src/ui/qgsrasterlayerpropertiesbase.ui
===================================================================
--- trunk/qgis/src/ui/qgsrasterlayerpropertiesbase.ui	2008-08-01 10:33:01 UTC (rev 8956)
+++ trunk/qgis/src/ui/qgsrasterlayerpropertiesbase.ui	2008-08-01 10:52:50 UTC (rev 8957)
@@ -812,10 +812,10 @@
          </property>
          <layout class="QGridLayout" >
           <property name="horizontalSpacing" >
-           <number>-1</number>
+           <number>6</number>
           </property>
           <property name="verticalSpacing" >
-           <number>-1</number>
+           <number>6</number>
           </property>
           <item row="0" column="0" >
            <widget class="QLabel" name="labelContrastEnhancement" >
@@ -1786,7 +1786,7 @@
        <string>Pyramids</string>
       </attribute>
       <layout class="QGridLayout" >
-       <item rowspan="2" row="0" column="0" >
+       <item rowspan="2" row="0" column="0" colspan="3" >
         <widget class="QTextEdit" name="tePyramidDescription" >
          <property name="sizePolicy" >
           <sizepolicy vsizetype="Expanding" hsizetype="Expanding" >
@@ -1797,19 +1797,19 @@
          <property name="html" >
           <string>&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;style type="text/css">
 p, li { white-space: pre-wrap; }
-&lt;/style>&lt;/head>&lt;body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;">
-&lt;p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">&lt;/p>&lt;/body>&lt;/html></string>
+&lt;/style>&lt;/head>&lt;body style=" font-family:'Verdana'; font-size:10pt; font-weight:400; font-style:normal;">
+&lt;p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans Serif'; font-size:9pt;">&lt;/p>&lt;/body>&lt;/html></string>
          </property>
         </widget>
        </item>
-       <item row="0" column="1" >
+       <item row="0" column="3" colspan="2" >
         <widget class="QLabel" name="textLabel5" >
          <property name="text" >
           <string>Pyramid resolutions</string>
          </property>
         </widget>
        </item>
-       <item row="1" column="1" >
+       <item row="1" column="3" colspan="2" >
         <widget class="QListWidget" name="lbxPyramidResolutions" >
          <property name="sizePolicy" >
           <sizepolicy vsizetype="Expanding" hsizetype="Preferred" >
@@ -1828,69 +1828,44 @@
          </property>
         </widget>
        </item>
-       <item row="2" column="0" colspan="2" >
-        <layout class="QHBoxLayout" >
-         <property name="leftMargin" >
-          <number>11</number>
+       <item row="2" column="0" >
+        <widget class="QLabel" name="textLabel4_2" >
+         <property name="text" >
+          <string>Resampling method</string>
          </property>
-         <property name="topMargin" >
-          <number>11</number>
+         <property name="buddy" >
+          <cstring>cboResamplingMethod</cstring>
          </property>
-         <property name="rightMargin" >
-          <number>11</number>
-         </property>
-         <property name="bottomMargin" >
-          <number>11</number>
-         </property>
+        </widget>
+       </item>
+       <item row="2" column="1" >
+        <widget class="QComboBox" name="cboResamplingMethod" >
          <item>
-          <spacer>
-           <property name="orientation" >
-            <enum>Qt::Horizontal</enum>
-           </property>
-           <property name="sizeType" >
-            <enum>QSizePolicy::Expanding</enum>
-           </property>
-           <property name="sizeHint" >
-            <size>
-             <width>156</width>
-             <height>20</height>
-            </size>
-           </property>
-          </spacer>
+          <property name="text" >
+           <string>Average</string>
+          </property>
          </item>
          <item>
-          <widget class="QLabel" name="textLabel4_2" >
-           <property name="text" >
-            <string>Resampling method</string>
-           </property>
-           <property name="buddy" >
-            <cstring>cboResamplingMethod</cstring>
-           </property>
-          </widget>
+          <property name="text" >
+           <string>Nearest Neighbour</string>
+          </property>
          </item>
-         <item>
-          <widget class="QComboBox" name="cboResamplingMethod" >
-           <item>
-            <property name="text" >
-             <string>Average</string>
-            </property>
-           </item>
-           <item>
-            <property name="text" >
-             <string>Nearest Neighbour</string>
-            </property>
-           </item>
-          </widget>
-         </item>
-         <item>
-          <widget class="QPushButton" name="buttonBuildPyramids" >
-           <property name="text" >
-            <string>Build pyramids</string>
-           </property>
-          </widget>
-         </item>
-        </layout>
+        </widget>
        </item>
+       <item row="2" column="2" colspan="2" >
+        <widget class="QProgressBar" name="mPyramidProgress" >
+         <property name="value" >
+          <number>0</number>
+         </property>
+        </widget>
+       </item>
+       <item row="2" column="4" >
+        <widget class="QPushButton" name="buttonBuildPyramids" >
+         <property name="text" >
+          <string>Build pyramids</string>
+         </property>
+        </widget>
+       </item>
       </layout>
      </widget>
      <widget class="QWidget" name="tabPageHistogram" >
@@ -1898,18 +1873,6 @@
        <string>Histogram</string>
       </attribute>
       <layout class="QGridLayout" >
-       <property name="leftMargin" >
-        <number>11</number>
-       </property>
-       <property name="topMargin" >
-        <number>11</number>
-       </property>
-       <property name="rightMargin" >
-        <number>11</number>
-       </property>
-       <property name="bottomMargin" >
-        <number>11</number>
-       </property>
        <item row="0" column="0" colspan="2" >
         <widget class="QLabel" name="pixHistogram" >
          <property name="sizePolicy" >
@@ -1979,31 +1942,12 @@
          </layout>
         </widget>
        </item>
-       <item row="3" column="1" >
-        <widget class="QPushButton" name="pbnHistRefresh" >
-         <property name="text" >
-          <string>Refresh</string>
-         </property>
-        </widget>
-       </item>
        <item rowspan="2" row="1" column="1" >
         <widget class="QGroupBox" name="groupBox" >
          <property name="title" >
           <string>Options</string>
          </property>
          <layout class="QGridLayout" >
-          <property name="leftMargin" >
-           <number>11</number>
-          </property>
-          <property name="topMargin" >
-           <number>11</number>
-          </property>
-          <property name="rightMargin" >
-           <number>11</number>
-          </property>
-          <property name="bottomMargin" >
-           <number>11</number>
-          </property>
           <item row="0" column="0" >
            <widget class="QLabel" name="textLabel1_2" >
             <property name="text" >
@@ -2011,6 +1955,22 @@
             </property>
            </widget>
           </item>
+          <item row="0" column="1" >
+           <widget class="QSpinBox" name="spinHistBinCount" >
+            <property name="minimum" >
+             <number>8</number>
+            </property>
+            <property name="maximum" >
+             <number>1024</number>
+            </property>
+            <property name="singleStep" >
+             <number>8</number>
+            </property>
+            <property name="value" >
+             <number>64</number>
+            </property>
+           </widget>
+          </item>
           <item row="1" column="0" colspan="2" >
            <widget class="QCheckBox" name="chkHistIgnoreOutOfRange" >
             <property name="text" >
@@ -2028,26 +1988,10 @@
             </property>
            </widget>
           </item>
-          <item row="0" column="1" >
-           <widget class="QSpinBox" name="spinHistBinCount" >
-            <property name="minimum" >
-             <number>8</number>
-            </property>
-            <property name="maximum" >
-             <number>1024</number>
-            </property>
-            <property name="singleStep" >
-             <number>8</number>
-            </property>
-            <property name="value" >
-             <number>64</number>
-            </property>
-           </widget>
-          </item>
          </layout>
         </widget>
        </item>
-       <item rowspan="2" row="2" column="0" >
+       <item rowspan="4" row="2" column="0" >
         <widget class="QListWidget" name="lstHistogramLabels" >
          <property name="maximumSize" >
           <size>
@@ -2060,6 +2004,33 @@
          </property>
         </widget>
        </item>
+       <item row="3" column="1" >
+        <spacer>
+         <property name="orientation" >
+          <enum>Qt::Vertical</enum>
+         </property>
+         <property name="sizeHint" >
+          <size>
+           <width>20</width>
+           <height>40</height>
+          </size>
+         </property>
+        </spacer>
+       </item>
+       <item row="4" column="1" >
+        <widget class="QProgressBar" name="mHistogramProgress" >
+         <property name="value" >
+          <number>0</number>
+         </property>
+        </widget>
+       </item>
+       <item row="5" column="1" >
+        <widget class="QPushButton" name="pbnHistRefresh" >
+         <property name="text" >
+          <string>Refresh</string>
+         </property>
+        </widget>
+       </item>
       </layout>
      </widget>
     </widget>



More information about the QGIS-commit mailing list