[QGIS Commit] r9170 - in trunk/qgis/src: app core/raster ui
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Mon Aug 25 19:47:19 EDT 2008
Author: ersts
Date: 2008-08-25 19:47:18 -0400 (Mon, 25 Aug 2008)
New Revision: 9170
Modified:
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.cpp
trunk/qgis/src/ui/qgsrasterlayerpropertiesbase.ui
Log:
-Added ability to export and load color map to/from a simple text file
-Closes ticket #805
-Updaded color interpretation option Linearly to Linear
-Fix problem displaying (pseudo and color map) paletted images
Modified: trunk/qgis/src/app/qgsrasterlayerproperties.cpp
===================================================================
--- trunk/qgis/src/app/qgsrasterlayerproperties.cpp 2008-08-25 20:48:48 UTC (rev 9169)
+++ trunk/qgis/src/app/qgsrasterlayerproperties.cpp 2008-08-25 23:47:18 UTC (rev 9170)
@@ -134,9 +134,10 @@
//setup custom colormap tab
cboxColorInterpolation->addItem( tr( "Discrete" ) );
- cboxColorInterpolation->addItem( tr( "Linearly" ) );
+ cboxColorInterpolation->addItem( tr( "Linear" ) );
+ cboxColorInterpolation->addItem( tr( "Exact") );
cboxClassificationMode->addItem( tr( "Equal interval" ) );
- cboxClassificationMode->addItem( tr( "Quantiles" ) );
+ //cboxClassificationMode->addItem( tr( "Quantiles" ) );
QStringList headerLabels;
headerLabels << "Value";
@@ -291,6 +292,9 @@
pbtnMakeBandCombinationDefault->setIcon( QgisApp::getThemeIcon( "/mActionFileSave.png" ) );
pbtnMakeContrastEnhancementAlgorithmDefault->setIcon( QgisApp::getThemeIcon( "/mActionFileSave.png" ) );
+ pbtnExportColorMapToFile->setIcon( QgisApp::getThemeIcon( "/mActionFileSave.png" ) );
+ pbtnLoadColorMapFromFile->setIcon( QgisApp::getThemeIcon( "/mActionFileOpen.png" ) );
+
// Only do pyramids if dealing directly with GDAL.
if ( mRasterLayerIsGdal )
{
@@ -886,13 +890,17 @@
sboxNumberOfEntries->setValue( myColorRampList.size() );
//restor state of 'color interpolation' combo box
- if ( QgsColorRampShader::DISCRETE == myRasterShaderFunction->getColorRampType() )
+ if ( QgsColorRampShader::INTERPOLATED == myRasterShaderFunction->getColorRampType() )
{
+ cboxColorInterpolation->setCurrentIndex( cboxColorInterpolation->findText( tr( "Linear" ) ) );
+ }
+ else if ( QgsColorRampShader::DISCRETE == myRasterShaderFunction->getColorRampType() )
+ {
cboxColorInterpolation->setCurrentIndex( cboxColorInterpolation->findText( tr( "Discrete" ) ) );
}
else
{
- cboxColorInterpolation->setCurrentIndex( cboxColorInterpolation->findText( tr( "Linearly" ) ) );
+ cboxColorInterpolation->setCurrentIndex( cboxColorInterpolation->findText( tr( "Exact" ) ) );
}
}
@@ -1397,13 +1405,17 @@
}
myRasterShaderFunction->setColorRampItemList( mColorRampItems );
- if ( cboxColorInterpolation->currentText() == tr( "Discrete" ) )
+ if ( cboxColorInterpolation->currentText() == tr( "Linear" ) )
{
+ myRasterShaderFunction->setColorRampType( QgsColorRampShader::INTERPOLATED );
+ }
+ else if ( cboxColorInterpolation->currentText() == tr( "Discrete" ) )
+ {
myRasterShaderFunction->setColorRampType( QgsColorRampShader::DISCRETE );
}
else
{
- myRasterShaderFunction->setColorRampType( QgsColorRampShader::INTERPOLATED );
+ myRasterShaderFunction->setColorRampType( QgsColorRampShader::EXACT );
}
}
else
@@ -2575,10 +2587,10 @@
currentValue += intervalDiff;
}
}
- else if ( cboxClassificationMode->currentText() == tr( "Quantiles" ) )
- {
+ //else if ( cboxClassificationMode->currentText() == tr( "Quantiles" ) )
+ //{
//todo
- }
+ //}
//hard code color range from blue -> red for now. Allow choice of ramps in future
int colorDiff = 0;
@@ -2637,6 +2649,149 @@
}
}
+void QgsRasterLayerProperties::on_pbtnExportColorMapToFile_clicked()
+{
+ QString myFileName = QFileDialog::getSaveFileName( this, tr( "Save file" ), "/", tr( "Textfile (*.txt)" ) );
+ if ( !myFileName.isEmpty() )
+ {
+ if ( !myFileName.endsWith( ".txt", Qt::CaseInsensitive ) )
+ {
+ myFileName = myFileName + ".txt";
+ }
+
+ QFile myOutputFile( myFileName );
+ if ( myOutputFile.open( QFile::WriteOnly ) )
+ {
+ QTextStream myOutputStream( &myOutputFile );
+ myOutputStream << "# " << tr( "QGIS Generated Color Map Export File" ) << "\n";
+ myOutputStream << "INTERPOLATION:";
+ if ( cboxColorInterpolation->currentText() == tr( "Linear" ) )
+ {
+ myOutputStream << "INTERPOLATED\n";
+ }
+ else if ( cboxColorInterpolation->currentText() == tr( "Discrete" ) )
+ {
+ myOutputStream << "DISCRETE\n";
+ }
+ else
+ {
+ myOutputStream << "EXACT\n";
+ }
+
+ int myTopLevelItemCount = mColormapTreeWidget->topLevelItemCount();
+ QTreeWidgetItem* myCurrentItem;
+ QColor myColor;
+ for ( int i = 0; i < myTopLevelItemCount; ++i )
+ {
+ myCurrentItem = mColormapTreeWidget->topLevelItem( i );
+ if ( !myCurrentItem )
+ {
+ continue;
+ }
+ myColor = myCurrentItem->background( 1 ).color();
+ myOutputStream << myCurrentItem->text( 0 ).toDouble() << ",";
+ myOutputStream << myColor.red() << "," << myColor.green() << "," << myColor.blue() << "," << myColor.alpha() << ",";
+ if(myCurrentItem->text(2) == "")
+ {
+ myOutputStream << "Color entry " << i+1 << "\n";
+ }
+ else
+ {
+ myOutputStream << myCurrentItem->text( 2 ) << "\n";
+ }
+ }
+ myOutputStream.flush();
+ myOutputFile.close();
+ }
+ else
+ {
+ QMessageBox::warning( this, tr( "Write access denied" ), tr( "Write access denied. Adjust the file permissions and try again.\n\n" ) );
+ }
+ }
+}
+
+void QgsRasterLayerProperties::on_pbtnLoadColorMapFromFile_clicked()
+{
+ int myLineCounter = 0;
+ bool myImportError = false;
+ QString myBadLines;
+ QString myFileName = QFileDialog::getOpenFileName( this, tr( "Open file" ), "/", tr( "Textfile (*.txt)" ) );
+ QFile myInputFile( myFileName );
+ if ( myInputFile.open( QFile::ReadOnly ) )
+ {
+ //clear the current tree
+ mColormapTreeWidget->clear();
+
+ QTextStream myInputStream( &myInputFile );
+ QString myInputLine;
+ QStringList myInputStringComponents;
+
+ //read through the input looking for valid data
+ while ( !myInputStream.atEnd() )
+ {
+ myLineCounter++;
+ myInputLine = myInputStream.readLine();
+ if ( !myInputLine.isEmpty() )
+ {
+ if ( !myInputLine.simplified().startsWith( "#" ) )
+ {
+ if(myInputLine.contains("INTERPOLATION", Qt::CaseInsensitive))
+ {
+ myInputStringComponents = myInputLine.split(":");
+ if(myInputStringComponents.size() == 2)
+ {
+ if(myInputStringComponents[1].trimmed().toUpper().compare ("INTERPOLATED", Qt::CaseInsensitive) == 0)
+ {
+ cboxColorInterpolation->setCurrentIndex( cboxColorInterpolation->findText( tr( "Linear" ) ) );
+ }
+ else if(myInputStringComponents[1].trimmed().toUpper().compare ("DISCRETE", Qt::CaseInsensitive) == 0)
+ {
+ cboxColorInterpolation->setCurrentIndex( cboxColorInterpolation->findText( tr( "Discrete" ) ) );
+ }
+ else
+ {
+ cboxColorInterpolation->setCurrentIndex( cboxColorInterpolation->findText( tr( "Exact" ) ) );
+ }
+ }
+ else
+ {
+ myImportError = true;
+ myBadLines = myBadLines + QString::number( myLineCounter ) + ":\t[" + myInputLine + "]\n";
+ }
+ }
+ else
+ {
+ myInputStringComponents = myInputLine.split(",");
+ if(myInputStringComponents.size() == 6)
+ {
+ QTreeWidgetItem* newItem = new QTreeWidgetItem( mColormapTreeWidget );
+ newItem->setText( 0, myInputStringComponents[0] );
+ newItem->setBackground( 1, QBrush( QColor::fromRgb(myInputStringComponents[1].toInt(), myInputStringComponents[2].toInt(), myInputStringComponents[3].toInt(), myInputStringComponents[4].toInt()) ) );
+ newItem->setText( 2, myInputStringComponents[5] );
+ }
+ else
+ {
+ myImportError = true;
+ myBadLines = myBadLines + QString::number( myLineCounter ) + ":\t[" + myInputLine + "]\n";
+ }
+ }
+ }
+ }
+ myLineCounter++;
+ }
+
+
+ if ( myImportError )
+ {
+ QMessageBox::warning( this, tr( "Import Error" ), tr( "The following lines contained errors\n\n" ) + myBadLines );
+ }
+ }
+ else if ( !myFileName.isEmpty() )
+ {
+ QMessageBox::warning( this, tr( "Read access denied" ), tr( "Read access denied. Adjust the file permissions and try again.\n\n" ) );
+ }
+}
+
void QgsRasterLayerProperties::on_pbtnLoadMinMax_clicked()
{
if ( mRasterLayerIsGdal && ( mRasterLayer->getDrawingStyle() == QgsRasterLayer::SINGLE_BAND_GRAY || mRasterLayer->getDrawingStyle() == QgsRasterLayer::MULTI_BAND_SINGLE_BAND_GRAY || mRasterLayer->getDrawingStyle() == QgsRasterLayer::MULTI_BAND_COLOR ) )
Modified: trunk/qgis/src/app/qgsrasterlayerproperties.h
===================================================================
--- trunk/qgis/src/app/qgsrasterlayerproperties.h 2008-08-25 20:48:48 UTC (rev 9169)
+++ trunk/qgis/src/app/qgsrasterlayerproperties.h 2008-08-25 23:47:18 UTC (rev 9170)
@@ -106,6 +106,10 @@
void on_mDeleteEntryButton_clicked();
/**Callback for double clicks on the colormap entry widget*/
void handleColormapTreeWidgetDoubleClick( QTreeWidgetItem* item, int column );
+ /**This slots saves the current color map to a file */
+ void on_pbtnExportColorMapToFile_clicked();
+ /**This slots saves the current color map to a file */
+ void on_pbtnLoadColorMapFromFile_clicked();
/**This slot loads the minimum and maximum values from the raster band and updates the gui*/
void on_pbtnLoadMinMax_clicked();
/**This slot sets the default band combination varaible to current band combination */
Modified: trunk/qgis/src/core/raster/qgscolorrampshader.cpp
===================================================================
--- trunk/qgis/src/core/raster/qgscolorrampshader.cpp 2008-08-25 20:48:48 UTC (rev 9169)
+++ trunk/qgis/src/core/raster/qgscolorrampshader.cpp 2008-08-25 23:47:18 UTC (rev 9170)
@@ -29,12 +29,16 @@
bool QgsColorRampShader::generateShadedValue( double theValue, int* theReturnRedValue, int* theReturnGreenValue, int* theReturnBlueValue )
{
- if ( QgsColorRampShader::DISCRETE == mColorRampType )
+ if ( QgsColorRampShader::INTERPOLATED == mColorRampType )
{
+ return getInterpolatedColor( theValue, theReturnRedValue, theReturnGreenValue, theReturnBlueValue );
+ }
+ else if ( QgsColorRampShader::DISCRETE == mColorRampType )
+ {
return getDiscreteColor( theValue, theReturnRedValue, theReturnGreenValue, theReturnBlueValue );
}
- return getInterpolatedColor( theValue, theReturnRedValue, theReturnGreenValue, theReturnBlueValue );
+ return getExactColor( theValue, theReturnRedValue, theReturnGreenValue, theReturnBlueValue );
}
bool QgsColorRampShader::generateShadedValue( double theRedValue, double theGreenValue, double theBlueValue, int* theReturnRedValue, int* theReturnGreenValue, int* theReturnBlueValue )
@@ -91,6 +95,27 @@
return false; // value not found
}
+bool QgsColorRampShader::getExactColor( double theValue, int* theReturnRedValue, int* theReturnGreenValue, int* theReturnBlueValue )
+{
+ if ( mColorRampItemList.count() <= 0 )
+ {
+ return false;
+ }
+ QList<QgsColorRampShader::ColorRampItem>::const_iterator it;
+ for ( it = mColorRampItemList.begin(); it != mColorRampItemList.end(); ++it )
+ {
+ if ( theValue == it->value )
+ {
+ *theReturnRedValue = it->color.red();
+ *theReturnGreenValue = it->color.green();
+ *theReturnBlueValue = it->color.blue();
+ return true;
+ }
+ }
+
+ return false; // value not found
+}
+
bool QgsColorRampShader::getInterpolatedColor( double theValue, int* theReturnRedValue, int* theReturnGreenValue, int* theReturnBlueValue )
{
if ( mColorRampItemList.count() <= 0 )
Modified: trunk/qgis/src/core/raster/qgscolorrampshader.h
===================================================================
--- trunk/qgis/src/core/raster/qgscolorrampshader.h 2008-08-25 20:48:48 UTC (rev 9169)
+++ trunk/qgis/src/core/raster/qgscolorrampshader.h 2008-08-25 23:47:18 UTC (rev 9170)
@@ -73,6 +73,8 @@
private:
/**Gets the color for a pixel value from the classification vector mValueClassification. Assigns the color of the lower class for every pixel between two class breaks.*/
bool getDiscreteColor( double, int*, int*, int* );
+ /**Gets the color for a pixel value from the classification vector mValueClassification. Assigns the color of the exact matching value in the color ramp item list */
+ bool getExactColor( double, int*, int*, int* );
/**Gets the color for a pixel value from the classification vector mValueClassification. Interpolates the color between two class breaks linearly.*/
bool getInterpolatedColor( double, int*, int*, int* );
Modified: trunk/qgis/src/core/raster/qgsrasterlayer.cpp
===================================================================
--- trunk/qgis/src/core/raster/qgsrasterlayer.cpp 2008-08-25 20:48:48 UTC (rev 9169)
+++ trunk/qgis/src/core/raster/qgsrasterlayer.cpp 2008-08-25 23:47:18 UTC (rev 9170)
@@ -1746,32 +1746,12 @@
mRasterShader->setMinimumValue( myMinimumValue );
mRasterShader->setMaximumValue( myMaximumValue );
- QgsColorTable *myColorTable = &( myRasterBandStats.colorTable );
- int myRedLUTValue = 0;
- int myGreenLUTValue = 0;
- int myBlueLUTValue;
-
double myPixelValue = 0.0;
int myRedValue = 0;
int myGreenValue = 0;
int myBlueValue = 0;
int myAlphaValue = 0;
- //Set a pointer to the LUT color channel
- int* myGrayValue;
- if ( theColorQString == mRedBandName )
- {
- myGrayValue = &myRedLUTValue;
- }
- else if ( theColorQString == mGreenBandName )
- {
- myGrayValue = &myGreenLUTValue;
- }
- else
- {
- myGrayValue = &myBlueLUTValue;
- }
-
for ( int myColumn = 0; myColumn < theRasterViewPort->drawableAreaYDim; ++myColumn )
{
for ( int myRow = 0; myRow < theRasterViewPort->drawableAreaXDim; ++myRow )
@@ -1793,11 +1773,7 @@
continue;
}
- bool found = myColorTable->color( myPixelValue, &myRedLUTValue, &myGreenLUTValue, &myBlueLUTValue );
- if ( !found ) continue;
-
-
- if ( !mRasterShader->generateShadedValue(( double )*myGrayValue, &myRedValue, &myGreenValue, &myBlueValue ) )
+ if ( !mRasterShader->generateShadedValue(myPixelValue, &myRedValue, &myGreenValue, &myBlueValue ) )
{
continue;
}
Modified: trunk/qgis/src/ui/qgsrasterlayerpropertiesbase.ui
===================================================================
--- trunk/qgis/src/ui/qgsrasterlayerpropertiesbase.ui 2008-08-25 20:48:48 UTC (rev 9169)
+++ trunk/qgis/src/ui/qgsrasterlayerpropertiesbase.ui 2008-08-25 23:47:18 UTC (rev 9170)
@@ -1199,44 +1199,6 @@
<string>Colormap</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="2" >
- <spacer>
- <property name="orientation" >
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeHint" >
- <size>
- <width>71</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </item>
- <item row="1" column="0" colspan="3" >
- <spacer>
- <property name="orientation" >
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeHint" >
- <size>
- <width>61</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </item>
<item row="0" column="0" colspan="2" >
<layout class="QHBoxLayout" >
<property name="leftMargin" >
@@ -1270,56 +1232,20 @@
</item>
</layout>
</item>
- <item row="2" column="2" colspan="2" >
+ <item row="0" column="2" >
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
- <width>341</width>
+ <width>71</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
- <item row="2" column="1" >
- <widget class="QPushButton" name="mDeleteEntryButton" >
- <property name="text" >
- <string>Delete entry</string>
- </property>
- </widget>
- </item>
- <item row="2" column="0" >
- <widget class="QPushButton" name="mClassifyButton" >
- <property name="text" >
- <string>Classify</string>
- </property>
- </widget>
- </item>
- <item row="3" column="0" colspan="4" >
- <widget class="QTreeWidget" name="mColormapTreeWidget" >
- <property name="columnCount" >
- <number>3</number>
- </property>
- <column>
- <property name="text" >
- <string>1</string>
- </property>
- </column>
- <column>
- <property name="text" >
- <string>1</string>
- </property>
- </column>
- <column>
- <property name="text" >
- <string>2</string>
- </property>
- </column>
- </widget>
- </item>
- <item row="0" column="3" >
+ <item row="0" column="3" colspan="3" >
<layout class="QHBoxLayout" >
<property name="leftMargin" >
<number>11</number>
@@ -1345,7 +1271,20 @@
</item>
</layout>
</item>
- <item row="1" column="3" >
+ <item row="1" column="0" colspan="3" >
+ <spacer>
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" >
+ <size>
+ <width>61</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="1" column="3" colspan="3" >
<layout class="QHBoxLayout" >
<property name="leftMargin" >
<number>11</number>
@@ -1371,6 +1310,81 @@
</item>
</layout>
</item>
+ <item row="2" column="0" >
+ <widget class="QPushButton" name="mClassifyButton" >
+ <property name="text" >
+ <string>Classify</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1" >
+ <widget class="QPushButton" name="mDeleteEntryButton" >
+ <property name="text" >
+ <string>Delete entry</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="2" colspan="2" >
+ <spacer>
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" >
+ <size>
+ <width>281</width>
+ <height>27</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="2" column="4" >
+ <widget class="QToolButton" name="pbtnLoadColorMapFromFile" >
+ <property name="toolTip" >
+ <string>Load color map from file</string>
+ </property>
+ <property name="text" >
+ <string>...</string>
+ </property>
+ <property name="icon" >
+ <iconset>../../images/themes/default/mActionFolder.png</iconset>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="5" >
+ <widget class="QToolButton" name="pbtnExportColorMapToFile" >
+ <property name="toolTip" >
+ <string>Export color map to file</string>
+ </property>
+ <property name="text" >
+ <string>...</string>
+ </property>
+ <property name="icon" >
+ <iconset>../../images/themes/default/mActionFileSave.png</iconset>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="0" colspan="6" >
+ <widget class="QTreeWidget" name="mColormapTreeWidget" >
+ <property name="columnCount" >
+ <number>3</number>
+ </property>
+ <column>
+ <property name="text" >
+ <string>1</string>
+ </property>
+ </column>
+ <column>
+ <property name="text" >
+ <string>1</string>
+ </property>
+ </column>
+ <column>
+ <property name="text" >
+ <string>2</string>
+ </property>
+ </column>
+ </widget>
+ </item>
</layout>
</widget>
<widget class="QWidget" name="tabPageGeneral" >
@@ -1798,8 +1812,8 @@
<property name="html" >
<string><html><head><meta name="qrichtext" content="1" /><style type="text/css">
p, li { white-space: pre-wrap; }
-</style></head><body style=" font-family:'DejaVu Sans'; font-size:10pt; font-weight:400; font-style:normal;">
-<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></body></html></string>
+</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;">
+<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></body></html></string>
</property>
</widget>
</item>
More information about the QGIS-commit
mailing list