@@ -134,9 +134,10 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer *lyr, QWidget *p
134
134
135
135
// setup custom colormap tab
136
136
cboxColorInterpolation->addItem ( tr ( " Discrete" ) );
137
- cboxColorInterpolation->addItem ( tr ( " Linearly" ) );
137
+ cboxColorInterpolation->addItem ( tr ( " Linear" ) );
138
+ cboxColorInterpolation->addItem ( tr ( " Exact" ) );
138
139
cboxClassificationMode->addItem ( tr ( " Equal interval" ) );
139
- cboxClassificationMode->addItem ( tr ( " Quantiles" ) );
140
+ // cboxClassificationMode->addItem( tr( "Quantiles" ) );
140
141
141
142
QStringList headerLabels;
142
143
headerLabels << " Value" ;
@@ -291,6 +292,9 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer *lyr, QWidget *p
291
292
pbtnMakeBandCombinationDefault->setIcon ( QgisApp::getThemeIcon ( " /mActionFileSave.png" ) );
292
293
pbtnMakeContrastEnhancementAlgorithmDefault->setIcon ( QgisApp::getThemeIcon ( " /mActionFileSave.png" ) );
293
294
295
+ pbtnExportColorMapToFile->setIcon ( QgisApp::getThemeIcon ( " /mActionFileSave.png" ) );
296
+ pbtnLoadColorMapFromFile->setIcon ( QgisApp::getThemeIcon ( " /mActionFileOpen.png" ) );
297
+
294
298
// Only do pyramids if dealing directly with GDAL.
295
299
if ( mRasterLayerIsGdal )
296
300
{
@@ -886,13 +890,17 @@ void QgsRasterLayerProperties::syncColormapTab()
886
890
sboxNumberOfEntries->setValue ( myColorRampList.size () );
887
891
888
892
// restor state of 'color interpolation' combo box
889
- if ( QgsColorRampShader::DISCRETE == myRasterShaderFunction->getColorRampType () )
893
+ if ( QgsColorRampShader::INTERPOLATED == myRasterShaderFunction->getColorRampType () )
894
+ {
895
+ cboxColorInterpolation->setCurrentIndex ( cboxColorInterpolation->findText ( tr ( " Linear" ) ) );
896
+ }
897
+ else if ( QgsColorRampShader::DISCRETE == myRasterShaderFunction->getColorRampType () )
890
898
{
891
899
cboxColorInterpolation->setCurrentIndex ( cboxColorInterpolation->findText ( tr ( " Discrete" ) ) );
892
900
}
893
901
else
894
902
{
895
- cboxColorInterpolation->setCurrentIndex ( cboxColorInterpolation->findText ( tr ( " Linearly " ) ) );
903
+ cboxColorInterpolation->setCurrentIndex ( cboxColorInterpolation->findText ( tr ( " Exact " ) ) );
896
904
}
897
905
898
906
}
@@ -1397,13 +1405,17 @@ void QgsRasterLayerProperties::apply()
1397
1405
}
1398
1406
myRasterShaderFunction->setColorRampItemList ( mColorRampItems );
1399
1407
1400
- if ( cboxColorInterpolation->currentText () == tr ( " Discrete" ) )
1408
+ if ( cboxColorInterpolation->currentText () == tr ( " Linear" ) )
1409
+ {
1410
+ myRasterShaderFunction->setColorRampType ( QgsColorRampShader::INTERPOLATED );
1411
+ }
1412
+ else if ( cboxColorInterpolation->currentText () == tr ( " Discrete" ) )
1401
1413
{
1402
1414
myRasterShaderFunction->setColorRampType ( QgsColorRampShader::DISCRETE );
1403
1415
}
1404
1416
else
1405
1417
{
1406
- myRasterShaderFunction->setColorRampType ( QgsColorRampShader::INTERPOLATED );
1418
+ myRasterShaderFunction->setColorRampType ( QgsColorRampShader::EXACT );
1407
1419
}
1408
1420
}
1409
1421
else
@@ -2575,10 +2587,10 @@ void QgsRasterLayerProperties::on_mClassifyButton_clicked()
2575
2587
currentValue += intervalDiff;
2576
2588
}
2577
2589
}
2578
- else if ( cboxClassificationMode->currentText () == tr ( " Quantiles" ) )
2579
- {
2590
+ // else if ( cboxClassificationMode->currentText() == tr( "Quantiles" ) )
2591
+ // {
2580
2592
// todo
2581
- }
2593
+ // }
2582
2594
2583
2595
// hard code color range from blue -> red for now. Allow choice of ramps in future
2584
2596
int colorDiff = 0 ;
@@ -2637,6 +2649,149 @@ void QgsRasterLayerProperties::handleColormapTreeWidgetDoubleClick( QTreeWidgetI
2637
2649
}
2638
2650
}
2639
2651
2652
+ void QgsRasterLayerProperties::on_pbtnExportColorMapToFile_clicked ()
2653
+ {
2654
+ QString myFileName = QFileDialog::getSaveFileName ( this , tr ( " Save file" ), " /" , tr ( " Textfile (*.txt)" ) );
2655
+ if ( !myFileName.isEmpty () )
2656
+ {
2657
+ if ( !myFileName.endsWith ( " .txt" , Qt::CaseInsensitive ) )
2658
+ {
2659
+ myFileName = myFileName + " .txt" ;
2660
+ }
2661
+
2662
+ QFile myOutputFile ( myFileName );
2663
+ if ( myOutputFile.open ( QFile::WriteOnly ) )
2664
+ {
2665
+ QTextStream myOutputStream ( &myOutputFile );
2666
+ myOutputStream << " # " << tr ( " QGIS Generated Color Map Export File" ) << " \n " ;
2667
+ myOutputStream << " INTERPOLATION:" ;
2668
+ if ( cboxColorInterpolation->currentText () == tr ( " Linear" ) )
2669
+ {
2670
+ myOutputStream << " INTERPOLATED\n " ;
2671
+ }
2672
+ else if ( cboxColorInterpolation->currentText () == tr ( " Discrete" ) )
2673
+ {
2674
+ myOutputStream << " DISCRETE\n " ;
2675
+ }
2676
+ else
2677
+ {
2678
+ myOutputStream << " EXACT\n " ;
2679
+ }
2680
+
2681
+ int myTopLevelItemCount = mColormapTreeWidget ->topLevelItemCount ();
2682
+ QTreeWidgetItem* myCurrentItem;
2683
+ QColor myColor;
2684
+ for ( int i = 0 ; i < myTopLevelItemCount; ++i )
2685
+ {
2686
+ myCurrentItem = mColormapTreeWidget ->topLevelItem ( i );
2687
+ if ( !myCurrentItem )
2688
+ {
2689
+ continue ;
2690
+ }
2691
+ myColor = myCurrentItem->background ( 1 ).color ();
2692
+ myOutputStream << myCurrentItem->text ( 0 ).toDouble () << " ," ;
2693
+ myOutputStream << myColor.red () << " ," << myColor.green () << " ," << myColor.blue () << " ," << myColor.alpha () << " ," ;
2694
+ if (myCurrentItem->text (2 ) == " " )
2695
+ {
2696
+ myOutputStream << " Color entry " << i+1 << " \n " ;
2697
+ }
2698
+ else
2699
+ {
2700
+ myOutputStream << myCurrentItem->text ( 2 ) << " \n " ;
2701
+ }
2702
+ }
2703
+ myOutputStream.flush ();
2704
+ myOutputFile.close ();
2705
+ }
2706
+ else
2707
+ {
2708
+ QMessageBox::warning ( this , tr ( " Write access denied" ), tr ( " Write access denied. Adjust the file permissions and try again.\n\n " ) );
2709
+ }
2710
+ }
2711
+ }
2712
+
2713
+ void QgsRasterLayerProperties::on_pbtnLoadColorMapFromFile_clicked ()
2714
+ {
2715
+ int myLineCounter = 0 ;
2716
+ bool myImportError = false ;
2717
+ QString myBadLines;
2718
+ QString myFileName = QFileDialog::getOpenFileName ( this , tr ( " Open file" ), " /" , tr ( " Textfile (*.txt)" ) );
2719
+ QFile myInputFile ( myFileName );
2720
+ if ( myInputFile.open ( QFile::ReadOnly ) )
2721
+ {
2722
+ // clear the current tree
2723
+ mColormapTreeWidget ->clear ();
2724
+
2725
+ QTextStream myInputStream ( &myInputFile );
2726
+ QString myInputLine;
2727
+ QStringList myInputStringComponents;
2728
+
2729
+ // read through the input looking for valid data
2730
+ while ( !myInputStream.atEnd () )
2731
+ {
2732
+ myLineCounter++;
2733
+ myInputLine = myInputStream.readLine ();
2734
+ if ( !myInputLine.isEmpty () )
2735
+ {
2736
+ if ( !myInputLine.simplified ().startsWith ( " #" ) )
2737
+ {
2738
+ if (myInputLine.contains (" INTERPOLATION" , Qt::CaseInsensitive))
2739
+ {
2740
+ myInputStringComponents = myInputLine.split (" :" );
2741
+ if (myInputStringComponents.size () == 2 )
2742
+ {
2743
+ if (myInputStringComponents[1 ].trimmed ().toUpper ().compare (" INTERPOLATED" , Qt::CaseInsensitive) == 0 )
2744
+ {
2745
+ cboxColorInterpolation->setCurrentIndex ( cboxColorInterpolation->findText ( tr ( " Linear" ) ) );
2746
+ }
2747
+ else if (myInputStringComponents[1 ].trimmed ().toUpper ().compare (" DISCRETE" , Qt::CaseInsensitive) == 0 )
2748
+ {
2749
+ cboxColorInterpolation->setCurrentIndex ( cboxColorInterpolation->findText ( tr ( " Discrete" ) ) );
2750
+ }
2751
+ else
2752
+ {
2753
+ cboxColorInterpolation->setCurrentIndex ( cboxColorInterpolation->findText ( tr ( " Exact" ) ) );
2754
+ }
2755
+ }
2756
+ else
2757
+ {
2758
+ myImportError = true ;
2759
+ myBadLines = myBadLines + QString::number ( myLineCounter ) + " :\t [" + myInputLine + " ]\n " ;
2760
+ }
2761
+ }
2762
+ else
2763
+ {
2764
+ myInputStringComponents = myInputLine.split (" ," );
2765
+ if (myInputStringComponents.size () == 6 )
2766
+ {
2767
+ QTreeWidgetItem* newItem = new QTreeWidgetItem ( mColormapTreeWidget );
2768
+ newItem->setText ( 0 , myInputStringComponents[0 ] );
2769
+ newItem->setBackground ( 1 , QBrush ( QColor::fromRgb (myInputStringComponents[1 ].toInt (), myInputStringComponents[2 ].toInt (), myInputStringComponents[3 ].toInt (), myInputStringComponents[4 ].toInt ()) ) );
2770
+ newItem->setText ( 2 , myInputStringComponents[5 ] );
2771
+ }
2772
+ else
2773
+ {
2774
+ myImportError = true ;
2775
+ myBadLines = myBadLines + QString::number ( myLineCounter ) + " :\t [" + myInputLine + " ]\n " ;
2776
+ }
2777
+ }
2778
+ }
2779
+ }
2780
+ myLineCounter++;
2781
+ }
2782
+
2783
+
2784
+ if ( myImportError )
2785
+ {
2786
+ QMessageBox::warning ( this , tr ( " Import Error" ), tr ( " The following lines contained errors\n\n " ) + myBadLines );
2787
+ }
2788
+ }
2789
+ else if ( !myFileName.isEmpty () )
2790
+ {
2791
+ QMessageBox::warning ( this , tr ( " Read access denied" ), tr ( " Read access denied. Adjust the file permissions and try again.\n\n " ) );
2792
+ }
2793
+ }
2794
+
2640
2795
void QgsRasterLayerProperties::on_pbtnLoadMinMax_clicked ()
2641
2796
{
2642
2797
if ( mRasterLayerIsGdal && ( mRasterLayer ->getDrawingStyle () == QgsRasterLayer::SINGLE_BAND_GRAY || mRasterLayer ->getDrawingStyle () == QgsRasterLayer::MULTI_BAND_SINGLE_BAND_GRAY || mRasterLayer ->getDrawingStyle () == QgsRasterLayer::MULTI_BAND_COLOR ) )
0 commit comments