25
25
#include < QFileInfo>
26
26
#include < QDir>
27
27
#include < QPainter>
28
+ #include < QSettings>
28
29
29
30
// QWT Charting widget
30
31
#include < qwt_global.h>
@@ -55,13 +56,22 @@ QgsRasterHistogramWidget::QgsRasterHistogramWidget( QgsRasterLayer* lyr, QWidget
55
56
mRendererWidget = 0 ;
56
57
mRendererName = " singlebandgray" ;
57
58
59
+ mHistoMin = 0 ;
60
+ mHistoMax = 0 ;
61
+
58
62
mHistoPicker = NULL ;
59
63
mHistoZoomer = NULL ;
60
64
mHistoMarkerMin = NULL ;
61
65
mHistoMarkerMax = NULL ;
62
- mHistoShowMarkers = false ;
63
- mHistoLoadApplyAll = false ;
66
+
67
+ QSettings settings;
68
+ mHistoShowMarkers = settings.value ( " /Raster/histogram/showMarkers" , false ).toBool ();
69
+ // mHistoLoadApplyAll = settings.value( "/Raster/histogram/loadApplyAll", false ).toBool();
70
+ mHistoZoomToMinMax = settings.value ( " /Raster/histogram/zoomToMinMax" , false ).toBool ();
71
+ mHistoUpdateStyleToMinMax = settings.value ( " /Raster/histogram/updateStyleToMinMax" , true ).toBool ();
72
+ // mHistoShowBands = (HistoShowBands) settings.value( "/Raster/histogram/showBands", (int) ShowAll ).toInt();
64
73
mHistoShowBands = ShowAll;
74
+
65
75
if ( true )
66
76
{
67
77
// band selector
@@ -91,18 +101,36 @@ QgsRasterHistogramWidget::QgsRasterHistogramWidget( QgsRasterLayer* lyr, QWidget
91
101
QActionGroup* group;
92
102
QAction* action;
93
103
94
- // various actions / prefs
104
+ // min/max options
95
105
group = new QActionGroup ( this );
96
106
group->setExclusive ( false );
97
107
connect ( group, SIGNAL ( triggered ( QAction* ) ), this , SLOT ( histoActionTriggered ( QAction* ) ) );
98
- action = new QAction ( tr ( " Visibility " ), group );
108
+ action = new QAction ( tr ( " Min/Max options " ), group );
99
109
action->setSeparator ( true );
100
110
menu->addAction ( action );
101
- action = new QAction ( tr ( " Show min/max markers" ), group );
111
+ action = new QAction ( tr ( " Always show min/max markers" ), group );
102
112
action->setData ( QVariant ( " Show markers" ) );
103
113
action->setCheckable ( true );
104
114
action->setChecked ( mHistoShowMarkers );
105
115
menu->addAction ( action );
116
+ action = new QAction ( tr ( " Zoom to min/max" ), group );
117
+ action->setData ( QVariant ( " Zoom min_max" ) );
118
+ action->setCheckable ( true );
119
+ action->setChecked ( mHistoZoomToMinMax );
120
+ menu->addAction ( action );
121
+ action = new QAction ( tr ( " Update style to min/max" ), group );
122
+ action->setData ( QVariant ( " Update min_max" ) );
123
+ action->setCheckable ( true );
124
+ action->setChecked ( mHistoUpdateStyleToMinMax );
125
+ menu->addAction ( action );
126
+
127
+ // visibility options
128
+ group = new QActionGroup ( this );
129
+ group->setExclusive ( false );
130
+ connect ( group, SIGNAL ( triggered ( QAction* ) ), this , SLOT ( histoActionTriggered ( QAction* ) ) );
131
+ action = new QAction ( tr ( " Visibility" ), group );
132
+ action->setSeparator ( true );
133
+ menu->addAction ( action );
106
134
group = new QActionGroup ( this );
107
135
group->setExclusive ( true ); // these options are exclusive
108
136
connect ( group, SIGNAL ( triggered ( QAction* ) ), this , SLOT ( histoActionTriggered ( QAction* ) ) );
@@ -122,6 +150,11 @@ QgsRasterHistogramWidget::QgsRasterHistogramWidget( QgsRasterLayer* lyr, QWidget
122
150
action->setChecked ( mHistoShowBands == ShowSelected );
123
151
menu->addAction ( action );
124
152
153
+ // actions
154
+ action = new QAction ( tr ( " Actions" ), group );
155
+ action->setSeparator ( true );
156
+ menu->addAction ( action );
157
+
125
158
// load actions
126
159
group = new QActionGroup ( this );
127
160
group->setExclusive ( false );
@@ -130,8 +163,9 @@ QgsRasterHistogramWidget::QgsRasterHistogramWidget( QgsRasterLayer* lyr, QWidget
130
163
action->setData ( QVariant ( " Load reset" ) );
131
164
menu->addAction ( action );
132
165
133
- // Load min/max needs 3 params (method, extent, accuracy), cannot put it in single item
166
+ // these actions have been disabled for api cleanup, restore them eventually
134
167
#if 0
168
+ // Load min/max needs 3 params (method, extent, accuracy), cannot put it in single item
135
169
action = new QAction( tr( "Load min/max" ), group );
136
170
action->setSeparator( true );
137
171
menu->addAction( action );
@@ -158,7 +192,6 @@ QgsRasterHistogramWidget::QgsRasterHistogramWidget( QgsRasterLayer* lyr, QWidget
158
192
#endif
159
193
160
194
// others
161
- menu->addSeparator ( );
162
195
action = new QAction ( tr ( " Recompute Histogram" ), group );
163
196
action->setData ( QVariant ( " Compute histogram" ) );
164
197
menu->addAction ( action );
@@ -611,19 +644,10 @@ void QgsRasterHistogramWidget::on_cboHistoBand_currentIndexChanged( int index )
611
644
btnHistoMin->setEnabled ( true );
612
645
btnHistoMax->setEnabled ( true );
613
646
614
- int theBandNo = index + 1 ;
615
- // TODO - there are 2 definitions of raster data type that should be unified
616
- // QgsRasterDataProvider::DataType and QGis::DataType
617
- // TODO - fix gdal provider: changes data type when nodata value is not found
618
- // this prevents us from getting proper min and max values here
619
- // minStr = QString::number( QgsContrastEnhancement::minimumValuePossible( ( QGis::DataType )
620
- // mRasterLayer->dataProvider()->dataType( theBandNo ) ) );
621
- // maxStr = QString::number( QgsContrastEnhancement::maximumValuePossible( ( QGis::DataType )
622
- // mRasterLayer->dataProvider()->dataType( theBandNo ) ) );
623
-
624
- QPair< QString, QString > myMinMax = rendererMinMax ( theBandNo );
647
+ QPair< QString, QString > myMinMax = rendererMinMax ( index + 1 );
625
648
leHistoMin->setText ( myMinMax.first );
626
649
leHistoMax->setText ( myMinMax.second );
650
+
627
651
applyHistoMin ();
628
652
applyHistoMax ();
629
653
}
@@ -647,41 +671,63 @@ void QgsRasterHistogramWidget::histoAction( const QString actionName, bool actio
647
671
if ( actionName == " Show markers" )
648
672
{
649
673
mHistoShowMarkers = actionFlag;
674
+ QSettings settings;
675
+ settings.setValue ( " /Raster/histogram/showMarkers" , mHistoShowMarkers );
650
676
updateHistoMarkers ();
651
677
return ;
652
678
}
679
+ else if ( actionName == " Zoom min_max" )
680
+ {
681
+ mHistoZoomToMinMax = actionFlag;
682
+ QSettings settings;
683
+ settings.setValue ( " /Raster/histogram/zoomToMinMax" , mHistoZoomToMinMax );
684
+ return ;
685
+ }
686
+ else if ( actionName == " Update min_max" )
687
+ {
688
+ mHistoUpdateStyleToMinMax = actionFlag;
689
+ QSettings settings;
690
+ settings.setValue ( " /Raster/histogram/updateStyleToMinMax" , mHistoUpdateStyleToMinMax );
691
+ return ;
692
+ }
653
693
else if ( actionName == " Show all" )
654
694
{
655
695
mHistoShowBands = ShowAll;
696
+ // settings.setValue( "/Raster/histogram/showBands", (int)mHistoShowBands );
656
697
refreshHistogram ();
657
698
return ;
658
699
}
659
700
else if ( actionName == " Show selected" )
660
701
{
661
702
mHistoShowBands = ShowSelected;
703
+ // settings.setValue( "/Raster/histogram/showBands", (int)mHistoShowBands );
662
704
refreshHistogram ();
663
705
return ;
664
706
}
665
707
else if ( actionName == " Show RGB" )
666
708
{
667
709
mHistoShowBands = ShowRGB;
710
+ // settings.setValue( "/Raster/histogram/showBands", (int)mHistoShowBands );
668
711
refreshHistogram ();
669
712
return ;
670
713
}
714
+ #if 0
671
715
else if ( actionName == "Load apply all" )
672
716
{
673
717
mHistoLoadApplyAll = actionFlag;
718
+ settings.setValue( "/Raster/histogram/loadApplyAll", mHistoLoadApplyAll );
674
719
return;
675
720
}
721
+ #endif
676
722
// Load actions
677
723
// TODO - separate calculations from rendererwidget so we can do them without
678
724
else if ( actionName.left ( 5 ) == " Load " && mRendererWidget )
679
725
{
680
726
QVector<int > myBands;
727
+ bool ok = false ;
728
+
681
729
#if 0
682
730
double minMaxValues[2];
683
- #endif
684
- bool ok = false ;
685
731
686
732
// find which band(s) need updating (all or current)
687
733
if ( mHistoLoadApplyAll )
@@ -693,6 +739,8 @@ void QgsRasterHistogramWidget::histoAction( const QString actionName, bool actio
693
739
myBands << i;
694
740
}
695
741
}
742
+ #endif
743
+
696
744
// add current band to the end
697
745
myBands << cboHistoBand->currentIndex () + 1 ;
698
746
@@ -782,13 +830,26 @@ void QgsRasterHistogramWidget::applyHistoMin( )
782
830
783
831
int theBandNo = cboHistoBand->currentIndex () + 1 ;
784
832
QList< int > mySelectedBands = rendererSelectedBands ();
833
+ QString min;
785
834
for ( int i = 0 ; i <= mySelectedBands.size (); i++ )
786
835
{
787
836
if ( theBandNo == mRendererWidget ->selectedBand ( i ) )
788
- mRendererWidget ->setMin ( leHistoMin->text (), i );
837
+ {
838
+ min = leHistoMin->text ();
839
+ if ( mHistoUpdateStyleToMinMax )
840
+ mRendererWidget ->setMin ( min, i );
841
+ }
789
842
}
790
843
791
844
updateHistoMarkers ();
845
+
846
+ if ( ! min.isEmpty () && mHistoZoomToMinMax && mHistoZoomer )
847
+ {
848
+ QRectF rect = mHistoZoomer ->zoomRect ();
849
+ rect.setLeft ( min.toDouble () );
850
+ mHistoZoomer ->zoom ( rect );
851
+ }
852
+
792
853
}
793
854
794
855
void QgsRasterHistogramWidget::applyHistoMax ( )
@@ -798,13 +859,25 @@ void QgsRasterHistogramWidget::applyHistoMax( )
798
859
799
860
int theBandNo = cboHistoBand->currentIndex () + 1 ;
800
861
QList< int > mySelectedBands = rendererSelectedBands ();
862
+ QString max;
801
863
for ( int i = 0 ; i <= mySelectedBands.size (); i++ )
802
864
{
803
865
if ( theBandNo == mRendererWidget ->selectedBand ( i ) )
804
- mRendererWidget ->setMax ( leHistoMax->text (), i );
866
+ {
867
+ max = leHistoMax->text ();
868
+ if ( mHistoUpdateStyleToMinMax )
869
+ mRendererWidget ->setMax ( max, i );
870
+ }
805
871
}
806
872
807
873
updateHistoMarkers ();
874
+
875
+ if ( ! max.isEmpty () && mHistoZoomToMinMax && mHistoZoomer )
876
+ {
877
+ QRectF rect = mHistoZoomer ->zoomRect ();
878
+ rect.setRight ( max.toDouble () );
879
+ mHistoZoomer ->zoom ( rect );
880
+ }
808
881
}
809
882
810
883
void QgsRasterHistogramWidget::on_btnHistoMin_toggled ()
@@ -822,6 +895,7 @@ void QgsRasterHistogramWidget::on_btnHistoMin_toggled()
822
895
mHistoZoomer ->setEnabled ( ! btnHistoMax->isChecked () );
823
896
mHistoPicker ->setEnabled ( btnHistoMin->isChecked () );
824
897
}
898
+ updateHistoMarkers ();
825
899
}
826
900
827
901
void QgsRasterHistogramWidget::on_btnHistoMax_toggled ()
@@ -839,6 +913,7 @@ void QgsRasterHistogramWidget::on_btnHistoMax_toggled()
839
913
mHistoZoomer ->setEnabled ( ! btnHistoMax->isChecked () );
840
914
mHistoPicker ->setEnabled ( btnHistoMax->isChecked () );
841
915
}
916
+ updateHistoMarkers ();
842
917
}
843
918
844
919
// local function used by histoPickerSelected(), to get a rounded picked value
@@ -891,7 +966,7 @@ void QgsRasterHistogramWidget::histoPickerSelected( const QPointF & pos )
891
966
applyHistoMin ();
892
967
btnHistoMin->setChecked ( false );
893
968
}
894
- else if ( btnHistoMax->isChecked () )
969
+ else // if ( btnHistoMax->isChecked() )
895
970
{
896
971
leHistoMax->setText ( findClosestTickVal ( pos.x (), scale ) );
897
972
applyHistoMax ();
@@ -919,8 +994,8 @@ void QgsRasterHistogramWidget::updateHistoMarkers( )
919
994
int theBandNo = cboHistoBand->currentIndex () + 1 ;
920
995
QList< int > mySelectedBands = histoSelectedBands ();
921
996
922
- if ( ! mHistoShowMarkers ||
923
- ( ! mySelectedBands.isEmpty () && ! mySelectedBands.contains ( theBandNo ) ) )
997
+ if (( ! mHistoShowMarkers && ! btnHistoMin-> isChecked () && ! btnHistoMax-> isChecked () ) ||
998
+ ( ! mySelectedBands.isEmpty () && ! mySelectedBands.contains ( theBandNo ) ) )
924
999
{
925
1000
mHistoMarkerMin ->hide ();
926
1001
mHistoMarkerMax ->hide ();
@@ -1024,5 +1099,22 @@ QPair< QString, QString > QgsRasterHistogramWidget::rendererMinMax( int theBandN
1024
1099
}
1025
1100
}
1026
1101
1102
+ // TODO - there are 2 definitions of raster data type that should be unified
1103
+ // QgsRasterDataProvider::DataType and QGis::DataType
1104
+ // TODO - fix gdal provider: changes data type when nodata value is not found
1105
+ // this prevents us from getting proper min and max values here
1106
+ // minStr = QString::number( QgsContrastEnhancement::minimumValuePossible( ( QGis::DataType )
1107
+ // mRasterLayer->dataProvider()->dataType( theBandNo ) ) );
1108
+ // maxStr = QString::number( QgsContrastEnhancement::maximumValuePossible( ( QGis::DataType )
1109
+ // mRasterLayer->dataProvider()->dataType( theBandNo ) ) );
1110
+
1111
+ // if we get an empty result, fill with default value (histo min/max)
1112
+ if ( myMinMax.first .isEmpty () )
1113
+ myMinMax.first = QString::number ( mHistoMin );
1114
+ if ( myMinMax.second .isEmpty () )
1115
+ myMinMax.second = QString::number ( mHistoMax );
1116
+
1117
+ QgsDebugMsg ( QString ( " bandNo %1 got min/max [%2] [%3]" ).arg ( theBandNo ).arg ( myMinMax.first ).arg ( myMinMax.second ) );
1118
+
1027
1119
return myMinMax;
1028
1120
}
0 commit comments