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

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sun Aug 15 22:37:35 EDT 2010


Author: ersts
Date: 2010-08-16 02:37:35 +0000 (Mon, 16 Aug 2010)
New Revision: 14085

Modified:
   trunk/qgis/src/app/qgisapp.cpp
   trunk/qgis/src/app/qgsrasterlayerproperties.cpp
   trunk/qgis/src/app/qgsrasterlayerproperties.h
   trunk/qgis/src/core/raster/qgscolorrampshader.cpp
   trunk/qgis/src/core/raster/qgscolorrampshader.h
   trunk/qgis/src/core/raster/qgsrasterlayer.h
   trunk/qgis/src/ui/qgsrasterlayerpropertiesbase.ui
Log:
-Added ability to interactively select pixels from the canvas to populate the transparency table in the raster layer properties dialog
-Closes ticket #2259
-Updated the color ramp shader to empty the color cache when a new color ramp is set

Modified: trunk/qgis/src/app/qgisapp.cpp
===================================================================
--- trunk/qgis/src/app/qgisapp.cpp	2010-08-14 23:12:30 UTC (rev 14084)
+++ trunk/qgis/src/app/qgisapp.cpp	2010-08-16 02:37:35 UTC (rev 14085)
@@ -6815,7 +6815,7 @@
     }
     else
     {
-      rlp = new QgsRasterLayerProperties( ml );
+      rlp = new QgsRasterLayerProperties( ml, mMapCanvas );
       connect( rlp, SIGNAL( refreshLegend( QString, bool ) ), mMapLegend, SLOT( refreshLayerSymbology( QString, bool ) ) );
     }
     rlp->exec();

Modified: trunk/qgis/src/app/qgsrasterlayerproperties.cpp
===================================================================
--- trunk/qgis/src/app/qgsrasterlayerproperties.cpp	2010-08-14 23:12:30 UTC (rev 14084)
+++ trunk/qgis/src/app/qgsrasterlayerproperties.cpp	2010-08-16 02:37:35 UTC (rev 14085)
@@ -17,6 +17,8 @@
 
 #include <limits>
 
+#include "qgsmaptopixel.h"
+#include "qgsmapcanvas.h"
 #include "qgslogger.h"
 #include "qgsapplication.h"
 #include "qgisapp.h"
@@ -46,19 +48,19 @@
 #include <QColorDialog>
 #include <QList>
 #include <QSettings>
+#include <QMouseEvent>
 #include "qgslogger.h"
 
 
 const char * const ident =
   "$Id$";
 
-QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer *lyr, QWidget *parent, Qt::WFlags fl )
+QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanvas* theCanvas, QWidget *parent, Qt::WFlags fl )
     : QDialog( parent, fl ),
     // Constant that signals property not used.
     TRSTRING_NOT_SET( tr( "Not Set" ) ),
     mRasterLayer( qobject_cast<QgsRasterLayer *>( lyr ) )
 {
-
   ignoreSpinBoxEvent = false; //Short circuit signal loop between min max field and stdDev spin box
   mGrayMinimumMaximumEstimated = true;
   mRGBMinimumMaximumEstimated = true;
@@ -271,6 +273,19 @@
   pbtnExportColorMapToFile->setIcon( QgisApp::getThemeIcon( "/mActionFileSave.png" ) );
   pbtnLoadColorMapFromFile->setIcon( QgisApp::getThemeIcon( "/mActionFileOpen.png" ) );
 
+  mMapCanvas = theCanvas;
+  mPixelSelectorTool = 0;
+  if( mMapCanvas )
+  {
+    mPixelSelectorTool = new QgsPixelSelectorTool( theCanvas );
+    connect( mPixelSelectorTool, SIGNAL( pixelSelected( int, int ) ), this, SLOT( pixelSelected( int, int ) ) );
+  }
+  else
+  {
+    pbnAddValuesFromDisplay->setEnabled( false );
+  }
+
+
   // Only do pyramids if dealing directly with GDAL.
   if ( mRasterLayerIsGdal )
   {
@@ -335,6 +350,10 @@
   QSettings settings;
   settings.setValue( "/Windows/RasterLayerProperties/geometry", saveGeometry() );
   settings.setValue( "/Windows/RasterLayerProperties/row", listWidget->currentRow() );
+  if( mPixelSelectorTool )
+  {
+    delete mPixelSelectorTool;
+  }
 }
 
 /*
@@ -1700,7 +1719,13 @@
 
 void QgsRasterLayerProperties::on_pbnAddValuesFromDisplay_clicked()
 {
-  QMessageBox::warning( this, "Function Not Available", "This functionality will be added soon" );
+  if( mMapCanvas && mPixelSelectorTool )
+  {
+    mMapCanvas->setMapTool( mPixelSelectorTool );
+    //Need to work around the modality of the dialog but can not just hide() it.
+    setModal( false );
+    lower();
+  }
 }
 
 void QgsRasterLayerProperties::on_pbnAddValuesManually_clicked()
@@ -2559,6 +2584,45 @@
   sboxThreeBandStdDev->setEnabled( theState );
 }
 
+void QgsRasterLayerProperties::pixelSelected( int x, int y )
+{
+  //PixelSelectorTool has registered a mouse click on the canvas, so bring the dialog back to the front
+  raise();
+  setModal( true );
+  activateWindow();
+
+  //Get the pixel values and add a new entry to the transparency table
+  if( mMapCanvas && mPixelSelectorTool )
+  {
+    QMap< QString, QString > myPixelMap;
+    mMapCanvas->unsetMapTool( mPixelSelectorTool );
+    mRasterLayer->identify( mMapCanvas->getCoordinateTransform( )->toMapCoordinates( x, y ), myPixelMap );
+    if( tableTransparency->columnCount() == 2 )
+    {
+      QString myValue = myPixelMap[ mRasterLayer->grayBandName() ];
+      if( myValue != tr( "out of extent" ) )
+      {
+        tableTransparency->insertRow( tableTransparency->rowCount() );
+        tableTransparency->setItem( tableTransparency->rowCount() - 1, tableTransparency->columnCount() - 1, new QTableWidgetItem( "100.0" ) );
+        tableTransparency->setItem( tableTransparency->rowCount() - 1, 0, new QTableWidgetItem( myValue ) );
+      }
+    }
+    else
+    {
+      QString myValue = myPixelMap[ mRasterLayer->redBandName() ];
+      if( myValue != tr( "out of extent" ) )
+      {
+        tableTransparency->insertRow( tableTransparency->rowCount() );
+        tableTransparency->setItem( tableTransparency->rowCount() - 1, tableTransparency->columnCount() - 1, new QTableWidgetItem( "100.0" ) );
+        tableTransparency->setItem( tableTransparency->rowCount() - 1, 0, new QTableWidgetItem( myValue ) );
+        tableTransparency->setItem( tableTransparency->rowCount() - 1, 1, new QTableWidgetItem( myPixelMap[ mRasterLayer->greenBandName() ] ) );
+        tableTransparency->setItem( tableTransparency->rowCount() - 1, 2, new QTableWidgetItem( myPixelMap[ mRasterLayer->blueBandName() ] ) );
+      }
+    }
+  }
+
+}
+
 void QgsRasterLayerProperties::sboxSingleBandStdDev_valueChanged( double theValue )
 {
   if ( !ignoreSpinBoxEvent )
@@ -3289,3 +3353,17 @@
     myQSettings.setValue( "style/lastStyleDir", myFileDialog->directory().absolutePath() );
   }
 }
+
+QgsPixelSelectorTool::QgsPixelSelectorTool( QgsMapCanvas* theCanvas ) : QgsMapTool( theCanvas )
+{
+  mMapCanvas = theCanvas;
+}
+
+QgsPixelSelectorTool::~QgsPixelSelectorTool()
+{
+}
+
+void QgsPixelSelectorTool::canvasReleaseEvent( QMouseEvent* theMouseEvent )
+{
+  emit pixelSelected( theMouseEvent->x( ), theMouseEvent->y( ) );
+}

Modified: trunk/qgis/src/app/qgsrasterlayerproperties.h
===================================================================
--- trunk/qgis/src/app/qgsrasterlayerproperties.h	2010-08-14 23:12:30 UTC (rev 14084)
+++ trunk/qgis/src/app/qgsrasterlayerproperties.h	2010-08-16 02:37:35 UTC (rev 14085)
@@ -22,11 +22,15 @@
 
 #include "ui_qgsrasterlayerpropertiesbase.h"
 #include "qgisgui.h"
+#include "qgsmaptool.h"
 #include "qgscolorrampshader.h"
 #include "qgscontexthelp.h"
 
+
 class QgsMapLayer;
+class QgsMapCanvas;
 class QgsRasterLayer;
+class QgsPixelSelectorTool;
 
 
 /**Property sheet for a raster map layer
@@ -41,7 +45,7 @@
     /** \brief Constructor
      * @param ml Map layer for which properties will be displayed
      */
-    QgsRasterLayerProperties( QgsMapLayer *lyr, QWidget *parent = 0, Qt::WFlags = QgisGui::ModalDialogFlags );
+    QgsRasterLayerProperties( QgsMapLayer *lyr, QgsMapCanvas* theCanvas, QWidget *parent = 0, Qt::WFlags = QgisGui::ModalDialogFlags );
     /** \brief Destructor */
     ~QgsRasterLayerProperties();
 
@@ -82,6 +86,8 @@
     void on_rbtnThreeBandMinMax_toggled( bool );
     /** \brief slot executed when the three band standard deviation radio button is pressed. */
     void on_rbtnThreeBandStdDev_toggled( bool );
+
+    void pixelSelected( int x, int y);
     /** \brief this slot clears min max values from gui */
     void sboxSingleBandStdDev_valueChanged( double );
     /** \brief this slot clears min max values from gui */
@@ -208,6 +214,31 @@
     QLinearGradient highlightGradient();
     qreal mGradientHeight;
     qreal mGradientWidth;
+
+    QgsMapCanvas* mMapCanvas;
+    QgsPixelSelectorTool* mPixelSelectorTool;
 };
 
+/**
+  *Simple map tool for selecting pixels, specific to QgsRasterLayerProperties
+  */
+class QgsPixelSelectorTool: public QgsMapTool
+{
+  Q_OBJECT
+
+  public:
+    QgsPixelSelectorTool( QgsMapCanvas* );
+    ~QgsPixelSelectorTool( );
+
+    /** \brief Method to handle mouse release, i.e., select, event */
+    void canvasReleaseEvent( QMouseEvent* theMouseEvent );
+
+  signals:
+    /** \brief Alter the listener ( raster properties dialog ) that a mouse click was registered */
+    void pixelSelected( int x, int y);
+
+  private:
+    QgsMapCanvas * mMapCanvas;
+};
+
 #endif

Modified: trunk/qgis/src/core/raster/qgscolorrampshader.cpp
===================================================================
--- trunk/qgis/src/core/raster/qgscolorrampshader.cpp	2010-08-14 23:12:30 UTC (rev 14084)
+++ trunk/qgis/src/core/raster/qgscolorrampshader.cpp	2010-08-16 02:37:35 UTC (rev 14085)
@@ -206,6 +206,13 @@
   return false;
 }
 
+void QgsColorRampShader::setColorRampItemList( const QList<QgsColorRampShader::ColorRampItem>& theList )
+{
+  mColorRampItemList = theList;
+  //Clear the cache
+  mColorCache.clear();
+}
+
 void QgsColorRampShader::setColorRampType( QgsColorRampShader::ColorRamp_TYPE theColorRampType )
 {
   //When the ramp type changes we need to clear out the cache

Modified: trunk/qgis/src/core/raster/qgscolorrampshader.h
===================================================================
--- trunk/qgis/src/core/raster/qgscolorrampshader.h	2010-08-14 23:12:30 UTC (rev 14084)
+++ trunk/qgis/src/core/raster/qgscolorrampshader.h	2010-08-16 02:37:35 UTC (rev 14085)
@@ -74,7 +74,7 @@
     int maximumColorCacheSize() { return mMaximumColorCacheSize; }
 
     /** \brief Set custom colormap */
-    void setColorRampItemList( const QList<QgsColorRampShader::ColorRampItem>& theList ) { mColorRampItemList = theList; } //TODO: sort on set
+    void setColorRampItemList( const QList<QgsColorRampShader::ColorRampItem>& theList ); //TODO: sort on set
 
     /** \brief Set the color ramp type*/
     void setColorRampType( QgsColorRampShader::ColorRamp_TYPE theColorRampType );

Modified: trunk/qgis/src/core/raster/qgsrasterlayer.h
===================================================================
--- trunk/qgis/src/core/raster/qgsrasterlayer.h	2010-08-14 23:12:30 UTC (rev 14084)
+++ trunk/qgis/src/core/raster/qgsrasterlayer.h	2010-08-16 02:37:35 UTC (rev 14085)
@@ -59,7 +59,6 @@
 class QgsRectangle;
 class QgsRasterBandStats;
 class QgsRasterPyramid;
-class QgsRasterLayerProperties;
 class QImage;
 class QPixmap;
 class QSlider;

Modified: trunk/qgis/src/ui/qgsrasterlayerpropertiesbase.ui
===================================================================
--- trunk/qgis/src/ui/qgsrasterlayerpropertiesbase.ui	2010-08-14 23:12:30 UTC (rev 14084)
+++ trunk/qgis/src/ui/qgsrasterlayerpropertiesbase.ui	2010-08-16 02:37:35 UTC (rev 14085)
@@ -1270,7 +1270,7 @@
             <item>
              <widget class="QToolButton" name="pbnAddValuesFromDisplay">
               <property name="enabled">
-               <bool>false</bool>
+               <bool>true</bool>
               </property>
               <property name="toolTip">
                <string>Add Values from display</string>
@@ -1888,9 +1888,10 @@
 &lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
 p, li { white-space: pre-wrap; }
 &lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans'; font-size:10pt; font-weight:400; font-style:normal;&quot;&gt;
-&lt;table style=&quot;-qt-table-type: root; margin-top:4px; margin-bottom:4px; margin-left:4px; margin-right:4px;&quot;&gt;
+&lt;table border=&quot;0&quot; style=&quot;-qt-table-type: root; margin-top:4px; margin-bottom:4px; margin-left:4px; margin-right:4px;&quot;&gt;
 &lt;tr&gt;
 &lt;td style=&quot;border: none;&quot;&gt;
+&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;/p&gt;
 &lt;p style=&quot;-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;&quot;&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/body&gt;&lt;/html&gt;</string>
          </property>
         </widget>



More information about the QGIS-commit mailing list