Skip to content

Commit cf9a1b5

Browse files
committed
update histogram UI and options (#7619)
1 parent ca43d8d commit cf9a1b5

File tree

3 files changed

+121
-27
lines changed

3 files changed

+121
-27
lines changed

src/gui/raster/qgsrasterhistogramwidget.cpp

+117-25
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <QFileInfo>
2626
#include <QDir>
2727
#include <QPainter>
28+
#include <QSettings>
2829

2930
// QWT Charting widget
3031
#include <qwt_global.h>
@@ -55,13 +56,22 @@ QgsRasterHistogramWidget::QgsRasterHistogramWidget( QgsRasterLayer* lyr, QWidget
5556
mRendererWidget = 0;
5657
mRendererName = "singlebandgray";
5758

59+
mHistoMin = 0;
60+
mHistoMax = 0;
61+
5862
mHistoPicker = NULL;
5963
mHistoZoomer = NULL;
6064
mHistoMarkerMin = NULL;
6165
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();
6473
mHistoShowBands = ShowAll;
74+
6575
if ( true )
6676
{
6777
//band selector
@@ -91,18 +101,36 @@ QgsRasterHistogramWidget::QgsRasterHistogramWidget( QgsRasterLayer* lyr, QWidget
91101
QActionGroup* group;
92102
QAction* action;
93103

94-
// various actions / prefs
104+
// min/max options
95105
group = new QActionGroup( this );
96106
group->setExclusive( false );
97107
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 );
99109
action->setSeparator( true );
100110
menu->addAction( action );
101-
action = new QAction( tr( "Show min/max markers" ), group );
111+
action = new QAction( tr( "Always show min/max markers" ), group );
102112
action->setData( QVariant( "Show markers" ) );
103113
action->setCheckable( true );
104114
action->setChecked( mHistoShowMarkers );
105115
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 );
106134
group = new QActionGroup( this );
107135
group->setExclusive( true ); // these options are exclusive
108136
connect( group, SIGNAL( triggered( QAction* ) ), this, SLOT( histoActionTriggered( QAction* ) ) );
@@ -122,6 +150,11 @@ QgsRasterHistogramWidget::QgsRasterHistogramWidget( QgsRasterLayer* lyr, QWidget
122150
action->setChecked( mHistoShowBands == ShowSelected );
123151
menu->addAction( action );
124152

153+
// actions
154+
action = new QAction( tr( "Actions" ), group );
155+
action->setSeparator( true );
156+
menu->addAction( action );
157+
125158
// load actions
126159
group = new QActionGroup( this );
127160
group->setExclusive( false );
@@ -130,8 +163,9 @@ QgsRasterHistogramWidget::QgsRasterHistogramWidget( QgsRasterLayer* lyr, QWidget
130163
action->setData( QVariant( "Load reset" ) );
131164
menu->addAction( action );
132165

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
134167
#if 0
168+
// Load min/max needs 3 params (method, extent, accuracy), cannot put it in single item
135169
action = new QAction( tr( "Load min/max" ), group );
136170
action->setSeparator( true );
137171
menu->addAction( action );
@@ -158,7 +192,6 @@ QgsRasterHistogramWidget::QgsRasterHistogramWidget( QgsRasterLayer* lyr, QWidget
158192
#endif
159193

160194
//others
161-
menu->addSeparator( );
162195
action = new QAction( tr( "Recompute Histogram" ), group );
163196
action->setData( QVariant( "Compute histogram" ) );
164197
menu->addAction( action );
@@ -611,19 +644,10 @@ void QgsRasterHistogramWidget::on_cboHistoBand_currentIndexChanged( int index )
611644
btnHistoMin->setEnabled( true );
612645
btnHistoMax->setEnabled( true );
613646

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 );
625648
leHistoMin->setText( myMinMax.first );
626649
leHistoMax->setText( myMinMax.second );
650+
627651
applyHistoMin();
628652
applyHistoMax();
629653
}
@@ -647,41 +671,63 @@ void QgsRasterHistogramWidget::histoAction( const QString actionName, bool actio
647671
if ( actionName == "Show markers" )
648672
{
649673
mHistoShowMarkers = actionFlag;
674+
QSettings settings;
675+
settings.setValue( "/Raster/histogram/showMarkers", mHistoShowMarkers );
650676
updateHistoMarkers();
651677
return;
652678
}
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+
}
653693
else if ( actionName == "Show all" )
654694
{
655695
mHistoShowBands = ShowAll;
696+
// settings.setValue( "/Raster/histogram/showBands", (int)mHistoShowBands );
656697
refreshHistogram();
657698
return;
658699
}
659700
else if ( actionName == "Show selected" )
660701
{
661702
mHistoShowBands = ShowSelected;
703+
// settings.setValue( "/Raster/histogram/showBands", (int)mHistoShowBands );
662704
refreshHistogram();
663705
return;
664706
}
665707
else if ( actionName == "Show RGB" )
666708
{
667709
mHistoShowBands = ShowRGB;
710+
// settings.setValue( "/Raster/histogram/showBands", (int)mHistoShowBands );
668711
refreshHistogram();
669712
return;
670713
}
714+
#if 0
671715
else if ( actionName == "Load apply all" )
672716
{
673717
mHistoLoadApplyAll = actionFlag;
718+
settings.setValue( "/Raster/histogram/loadApplyAll", mHistoLoadApplyAll );
674719
return;
675720
}
721+
#endif
676722
// Load actions
677723
// TODO - separate calculations from rendererwidget so we can do them without
678724
else if ( actionName.left( 5 ) == "Load " && mRendererWidget )
679725
{
680726
QVector<int> myBands;
727+
bool ok = false;
728+
681729
#if 0
682730
double minMaxValues[2];
683-
#endif
684-
bool ok = false;
685731

686732
// find which band(s) need updating (all or current)
687733
if ( mHistoLoadApplyAll )
@@ -693,6 +739,8 @@ void QgsRasterHistogramWidget::histoAction( const QString actionName, bool actio
693739
myBands << i;
694740
}
695741
}
742+
#endif
743+
696744
// add current band to the end
697745
myBands << cboHistoBand->currentIndex() + 1;
698746

@@ -782,13 +830,26 @@ void QgsRasterHistogramWidget::applyHistoMin( )
782830

783831
int theBandNo = cboHistoBand->currentIndex() + 1;
784832
QList< int > mySelectedBands = rendererSelectedBands();
833+
QString min;
785834
for ( int i = 0; i <= mySelectedBands.size(); i++ )
786835
{
787836
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+
}
789842
}
790843

791844
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+
792853
}
793854

794855
void QgsRasterHistogramWidget::applyHistoMax( )
@@ -798,13 +859,25 @@ void QgsRasterHistogramWidget::applyHistoMax( )
798859

799860
int theBandNo = cboHistoBand->currentIndex() + 1;
800861
QList< int > mySelectedBands = rendererSelectedBands();
862+
QString max;
801863
for ( int i = 0; i <= mySelectedBands.size(); i++ )
802864
{
803865
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+
}
805871
}
806872

807873
updateHistoMarkers();
874+
875+
if ( ! max.isEmpty() && mHistoZoomToMinMax && mHistoZoomer )
876+
{
877+
QRectF rect = mHistoZoomer->zoomRect();
878+
rect.setRight( max.toDouble() );
879+
mHistoZoomer->zoom( rect );
880+
}
808881
}
809882

810883
void QgsRasterHistogramWidget::on_btnHistoMin_toggled()
@@ -822,6 +895,7 @@ void QgsRasterHistogramWidget::on_btnHistoMin_toggled()
822895
mHistoZoomer->setEnabled( ! btnHistoMax->isChecked() );
823896
mHistoPicker->setEnabled( btnHistoMin->isChecked() );
824897
}
898+
updateHistoMarkers();
825899
}
826900

827901
void QgsRasterHistogramWidget::on_btnHistoMax_toggled()
@@ -839,6 +913,7 @@ void QgsRasterHistogramWidget::on_btnHistoMax_toggled()
839913
mHistoZoomer->setEnabled( ! btnHistoMax->isChecked() );
840914
mHistoPicker->setEnabled( btnHistoMax->isChecked() );
841915
}
916+
updateHistoMarkers();
842917
}
843918

844919
// local function used by histoPickerSelected(), to get a rounded picked value
@@ -891,7 +966,7 @@ void QgsRasterHistogramWidget::histoPickerSelected( const QPointF & pos )
891966
applyHistoMin();
892967
btnHistoMin->setChecked( false );
893968
}
894-
else if ( btnHistoMax->isChecked() )
969+
else // if ( btnHistoMax->isChecked() )
895970
{
896971
leHistoMax->setText( findClosestTickVal( pos.x(), scale ) );
897972
applyHistoMax();
@@ -919,8 +994,8 @@ void QgsRasterHistogramWidget::updateHistoMarkers( )
919994
int theBandNo = cboHistoBand->currentIndex() + 1;
920995
QList< int > mySelectedBands = histoSelectedBands();
921996

922-
if ( ! mHistoShowMarkers ||
923-
( ! mySelectedBands.isEmpty() && ! mySelectedBands.contains( theBandNo ) ) )
997+
if (( ! mHistoShowMarkers && ! btnHistoMin->isChecked() && ! btnHistoMax->isChecked() ) ||
998+
( ! mySelectedBands.isEmpty() && ! mySelectedBands.contains( theBandNo ) ) )
924999
{
9251000
mHistoMarkerMin->hide();
9261001
mHistoMarkerMax->hide();
@@ -1024,5 +1099,22 @@ QPair< QString, QString > QgsRasterHistogramWidget::rendererMinMax( int theBandN
10241099
}
10251100
}
10261101

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+
10271119
return myMinMax;
10281120
}

src/gui/raster/qgsrasterhistogramwidget.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ class GUI_EXPORT QgsRasterHistogramWidget : public QWidget, private Ui::QgsRaste
112112
double mHistoMax;
113113
QVector<QColor> mHistoColors;
114114
bool mHistoShowMarkers;
115-
bool mHistoLoadApplyAll;
115+
bool mHistoZoomToMinMax;
116+
bool mHistoUpdateStyleToMinMax;
117+
/* bool mHistoLoadApplyAll; */
116118
HistoShowBands mHistoShowBands;
117119
/** \brief Returns a list of selected bands in the histogram widget- or empty if there is no selection restriction. */
118120
QList< int > histoSelectedBands();

src/ui/qgsrasterhistogramwidgetbase.ui

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
</sizepolicy>
9999
</property>
100100
<property name="text">
101-
<string>Band</string>
101+
<string>Set min/max style for</string>
102102
</property>
103103
</widget>
104104
</item>

0 commit comments

Comments
 (0)