Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
-Added ability to interactively select pixels from the canvas to popu…
…late 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

git-svn-id: http://svn.osgeo.org/qgis/trunk@14085 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
ersts committed Aug 16, 2010
1 parent 0f37200 commit 95a0392
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/app/qgisapp.cpp
Expand Up @@ -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();
Expand Down
84 changes: 81 additions & 3 deletions src/app/qgsrasterlayerproperties.cpp
Expand Up @@ -17,6 +17,8 @@

#include <limits>

#include "qgsmaptopixel.h"
#include "qgsmapcanvas.h"
#include "qgslogger.h"
#include "qgsapplication.h"
#include "qgisapp.h"
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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;
}
}

/*
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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( ) );
}
33 changes: 32 additions & 1 deletion src/app/qgsrasterlayerproperties.h
Expand Up @@ -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
Expand All @@ -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();

Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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
7 changes: 7 additions & 0 deletions src/core/raster/qgscolorrampshader.cpp
Expand Up @@ -206,6 +206,13 @@ bool QgsColorRampShader::interpolatedColor( double theValue, int* theReturnRedVa
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
Expand Down
2 changes: 1 addition & 1 deletion src/core/raster/qgscolorrampshader.h
Expand Up @@ -74,7 +74,7 @@ class CORE_EXPORT QgsColorRampShader : public QgsRasterShaderFunction
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 );
Expand Down
1 change: 0 additions & 1 deletion src/core/raster/qgsrasterlayer.h
Expand Up @@ -59,7 +59,6 @@ class QgsMapToPixel;
class QgsRectangle;
class QgsRasterBandStats;
class QgsRasterPyramid;
class QgsRasterLayerProperties;
class QImage;
class QPixmap;
class QSlider;
Expand Down
5 changes: 3 additions & 2 deletions src/ui/qgsrasterlayerpropertiesbase.ui
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down

0 comments on commit 95a0392

Please sign in to comment.