diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index 9cf65dd40240..88bd1e0fc07a 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -6815,7 +6815,7 @@ void QgisApp::showLayerProperties( QgsMapLayer *ml ) } else { - rlp = new QgsRasterLayerProperties( ml ); + rlp = new QgsRasterLayerProperties( ml, mMapCanvas ); connect( rlp, SIGNAL( refreshLegend( QString, bool ) ), mMapLegend, SLOT( refreshLayerSymbology( QString, bool ) ) ); } rlp->exec(); diff --git a/src/app/qgsrasterlayerproperties.cpp b/src/app/qgsrasterlayerproperties.cpp index c8ca04b51659..87c70633f40d 100644 --- a/src/app/qgsrasterlayerproperties.cpp +++ b/src/app/qgsrasterlayerproperties.cpp @@ -17,6 +17,8 @@ #include +#include "qgsmaptopixel.h" +#include "qgsmapcanvas.h" #include "qgslogger.h" #include "qgsapplication.h" #include "qgisapp.h" @@ -46,19 +48,19 @@ #include #include #include +#include #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( lyr ) ) { - ignoreSpinBoxEvent = false; //Short circuit signal loop between min max field and stdDev spin box mGrayMinimumMaximumEstimated = true; mRGBMinimumMaximumEstimated = true; @@ -271,6 +273,19 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer *lyr, QWidget *p 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 @@ QgsRasterLayerProperties::~QgsRasterLayerProperties() 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_cboRed_currentIndexChanged( const QString& the 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 @@ void QgsRasterLayerProperties::on_rbtnThreeBandStdDev_toggled( bool theState ) 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 @@ void QgsRasterLayerProperties::on_pbnSaveStyleAs_clicked() 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( ) ); +} diff --git a/src/app/qgsrasterlayerproperties.h b/src/app/qgsrasterlayerproperties.h index 21381d927f8f..c74253513fb7 100644 --- a/src/app/qgsrasterlayerproperties.h +++ b/src/app/qgsrasterlayerproperties.h @@ -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 @@ class QgsRasterLayerProperties : public QDialog, private Ui::QgsRasterLayerPrope /** \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 @@ class QgsRasterLayerProperties : public QDialog, private Ui::QgsRasterLayerPrope 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 @@ class QgsRasterLayerProperties : public QDialog, private Ui::QgsRasterLayerPrope 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 diff --git a/src/core/raster/qgscolorrampshader.cpp b/src/core/raster/qgscolorrampshader.cpp index 918905b93480..04bee28a05d1 100644 --- a/src/core/raster/qgscolorrampshader.cpp +++ b/src/core/raster/qgscolorrampshader.cpp @@ -206,6 +206,13 @@ bool QgsColorRampShader::interpolatedColor( double theValue, int* theReturnRedVa return false; } +void QgsColorRampShader::setColorRampItemList( const QList& 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 diff --git a/src/core/raster/qgscolorrampshader.h b/src/core/raster/qgscolorrampshader.h index 5c63f7090e54..8eda7715c599 100644 --- a/src/core/raster/qgscolorrampshader.h +++ b/src/core/raster/qgscolorrampshader.h @@ -74,7 +74,7 @@ class CORE_EXPORT QgsColorRampShader : public QgsRasterShaderFunction int maximumColorCacheSize() { return mMaximumColorCacheSize; } /** \brief Set custom colormap */ - void setColorRampItemList( const QList& theList ) { mColorRampItemList = theList; } //TODO: sort on set + void setColorRampItemList( const QList& theList ); //TODO: sort on set /** \brief Set the color ramp type*/ void setColorRampType( QgsColorRampShader::ColorRamp_TYPE theColorRampType ); diff --git a/src/core/raster/qgsrasterlayer.h b/src/core/raster/qgsrasterlayer.h index c56f8aa1cdb8..df7a28c73e3d 100644 --- a/src/core/raster/qgsrasterlayer.h +++ b/src/core/raster/qgsrasterlayer.h @@ -59,7 +59,6 @@ class QgsMapToPixel; class QgsRectangle; class QgsRasterBandStats; class QgsRasterPyramid; -class QgsRasterLayerProperties; class QImage; class QPixmap; class QSlider; diff --git a/src/ui/qgsrasterlayerpropertiesbase.ui b/src/ui/qgsrasterlayerpropertiesbase.ui index 00d8bde10f74..c5502e9ce546 100644 --- a/src/ui/qgsrasterlayerpropertiesbase.ui +++ b/src/ui/qgsrasterlayerpropertiesbase.ui @@ -1270,7 +1270,7 @@ - false + true Add Values from display @@ -1888,9 +1888,10 @@ <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } </style></head><body style=" font-family:'Sans'; font-size:10pt; font-weight:400; font-style:normal;"> -<table style="-qt-table-type: root; margin-top:4px; margin-bottom:4px; margin-left:4px; margin-right:4px;"> +<table border="0" style="-qt-table-type: root; margin-top:4px; margin-bottom:4px; margin-left:4px; margin-right:4px;"> <tr> <td style="border: none;"> +<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;"></p> <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;"></p></td></tr></table></body></html>