Skip to content
Permalink
Browse files
-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 95a039211cf942daa3f571be33a85700e3a23c30
@@ -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();
@@ -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 @@ 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( ) );
}
@@ -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
@@ -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
@@ -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 );
@@ -59,7 +59,6 @@ class QgsMapToPixel;
class QgsRectangle;
class QgsRasterBandStats;
class QgsRasterPyramid;
class QgsRasterLayerProperties;
class QImage;
class QPixmap;
class QSlider;
@@ -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>

0 comments on commit 95a0392

Please sign in to comment.