Skip to content

Commit

Permalink
update histogram UI and options (#7619)
Browse files Browse the repository at this point in the history
  • Loading branch information
etiennesky committed May 6, 2013
1 parent ca43d8d commit cf9a1b5
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 27 deletions.
142 changes: 117 additions & 25 deletions src/gui/raster/qgsrasterhistogramwidget.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <QFileInfo> #include <QFileInfo>
#include <QDir> #include <QDir>
#include <QPainter> #include <QPainter>
#include <QSettings>


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


mHistoMin = 0;
mHistoMax = 0;

mHistoPicker = NULL; mHistoPicker = NULL;
mHistoZoomer = NULL; mHistoZoomer = NULL;
mHistoMarkerMin = NULL; mHistoMarkerMin = NULL;
mHistoMarkerMax = NULL; mHistoMarkerMax = NULL;
mHistoShowMarkers = false;
mHistoLoadApplyAll = false; QSettings settings;
mHistoShowMarkers = settings.value( "/Raster/histogram/showMarkers", false ).toBool();
// mHistoLoadApplyAll = settings.value( "/Raster/histogram/loadApplyAll", false ).toBool();
mHistoZoomToMinMax = settings.value( "/Raster/histogram/zoomToMinMax", false ).toBool();
mHistoUpdateStyleToMinMax = settings.value( "/Raster/histogram/updateStyleToMinMax", true ).toBool();
// mHistoShowBands = (HistoShowBands) settings.value( "/Raster/histogram/showBands", (int) ShowAll ).toInt();
mHistoShowBands = ShowAll; mHistoShowBands = ShowAll;

if ( true ) if ( true )
{ {
//band selector //band selector
Expand Down Expand Up @@ -91,18 +101,36 @@ QgsRasterHistogramWidget::QgsRasterHistogramWidget( QgsRasterLayer* lyr, QWidget
QActionGroup* group; QActionGroup* group;
QAction* action; QAction* action;


// various actions / prefs // min/max options
group = new QActionGroup( this ); group = new QActionGroup( this );
group->setExclusive( false ); group->setExclusive( false );
connect( group, SIGNAL( triggered( QAction* ) ), this, SLOT( histoActionTriggered( QAction* ) ) ); connect( group, SIGNAL( triggered( QAction* ) ), this, SLOT( histoActionTriggered( QAction* ) ) );
action = new QAction( tr( "Visibility" ), group ); action = new QAction( tr( "Min/Max options" ), group );
action->setSeparator( true ); action->setSeparator( true );
menu->addAction( action ); menu->addAction( action );
action = new QAction( tr( "Show min/max markers" ), group ); action = new QAction( tr( "Always show min/max markers" ), group );
action->setData( QVariant( "Show markers" ) ); action->setData( QVariant( "Show markers" ) );
action->setCheckable( true ); action->setCheckable( true );
action->setChecked( mHistoShowMarkers ); action->setChecked( mHistoShowMarkers );
menu->addAction( action ); menu->addAction( action );
action = new QAction( tr( "Zoom to min/max" ), group );
action->setData( QVariant( "Zoom min_max" ) );
action->setCheckable( true );
action->setChecked( mHistoZoomToMinMax );
menu->addAction( action );
action = new QAction( tr( "Update style to min/max" ), group );
action->setData( QVariant( "Update min_max" ) );
action->setCheckable( true );
action->setChecked( mHistoUpdateStyleToMinMax );
menu->addAction( action );

// visibility options
group = new QActionGroup( this );
group->setExclusive( false );
connect( group, SIGNAL( triggered( QAction* ) ), this, SLOT( histoActionTriggered( QAction* ) ) );
action = new QAction( tr( "Visibility" ), group );
action->setSeparator( true );
menu->addAction( action );
group = new QActionGroup( this ); group = new QActionGroup( this );
group->setExclusive( true ); // these options are exclusive group->setExclusive( true ); // these options are exclusive
connect( group, SIGNAL( triggered( QAction* ) ), this, SLOT( histoActionTriggered( QAction* ) ) ); connect( group, SIGNAL( triggered( QAction* ) ), this, SLOT( histoActionTriggered( QAction* ) ) );
Expand All @@ -122,6 +150,11 @@ QgsRasterHistogramWidget::QgsRasterHistogramWidget( QgsRasterLayer* lyr, QWidget
action->setChecked( mHistoShowBands == ShowSelected ); action->setChecked( mHistoShowBands == ShowSelected );
menu->addAction( action ); menu->addAction( action );


// actions
action = new QAction( tr( "Actions" ), group );
action->setSeparator( true );
menu->addAction( action );

// load actions // load actions
group = new QActionGroup( this ); group = new QActionGroup( this );
group->setExclusive( false ); group->setExclusive( false );
Expand All @@ -130,8 +163,9 @@ QgsRasterHistogramWidget::QgsRasterHistogramWidget( QgsRasterLayer* lyr, QWidget
action->setData( QVariant( "Load reset" ) ); action->setData( QVariant( "Load reset" ) );
menu->addAction( action ); menu->addAction( action );


// Load min/max needs 3 params (method, extent, accuracy), cannot put it in single item // these actions have been disabled for api cleanup, restore them eventually
#if 0 #if 0
// Load min/max needs 3 params (method, extent, accuracy), cannot put it in single item
action = new QAction( tr( "Load min/max" ), group ); action = new QAction( tr( "Load min/max" ), group );
action->setSeparator( true ); action->setSeparator( true );
menu->addAction( action ); menu->addAction( action );
Expand All @@ -158,7 +192,6 @@ QgsRasterHistogramWidget::QgsRasterHistogramWidget( QgsRasterLayer* lyr, QWidget
#endif #endif


//others //others
menu->addSeparator( );
action = new QAction( tr( "Recompute Histogram" ), group ); action = new QAction( tr( "Recompute Histogram" ), group );
action->setData( QVariant( "Compute histogram" ) ); action->setData( QVariant( "Compute histogram" ) );
menu->addAction( action ); menu->addAction( action );
Expand Down Expand Up @@ -611,19 +644,10 @@ void QgsRasterHistogramWidget::on_cboHistoBand_currentIndexChanged( int index )
btnHistoMin->setEnabled( true ); btnHistoMin->setEnabled( true );
btnHistoMax->setEnabled( true ); btnHistoMax->setEnabled( true );


int theBandNo = index + 1; QPair< QString, QString > myMinMax = rendererMinMax( index + 1 );
// TODO - there are 2 definitions of raster data type that should be unified
// QgsRasterDataProvider::DataType and QGis::DataType
// TODO - fix gdal provider: changes data type when nodata value is not found
// this prevents us from getting proper min and max values here
// minStr = QString::number( QgsContrastEnhancement::minimumValuePossible( ( QGis::DataType )
// mRasterLayer->dataProvider()->dataType( theBandNo ) ) );
// maxStr = QString::number( QgsContrastEnhancement::maximumValuePossible( ( QGis::DataType )
// mRasterLayer->dataProvider()->dataType( theBandNo ) ) );

QPair< QString, QString > myMinMax = rendererMinMax( theBandNo );
leHistoMin->setText( myMinMax.first ); leHistoMin->setText( myMinMax.first );
leHistoMax->setText( myMinMax.second ); leHistoMax->setText( myMinMax.second );

applyHistoMin(); applyHistoMin();
applyHistoMax(); applyHistoMax();
} }
Expand All @@ -647,41 +671,63 @@ void QgsRasterHistogramWidget::histoAction( const QString actionName, bool actio
if ( actionName == "Show markers" ) if ( actionName == "Show markers" )
{ {
mHistoShowMarkers = actionFlag; mHistoShowMarkers = actionFlag;
QSettings settings;
settings.setValue( "/Raster/histogram/showMarkers", mHistoShowMarkers );
updateHistoMarkers(); updateHistoMarkers();
return; return;
} }
else if ( actionName == "Zoom min_max" )
{
mHistoZoomToMinMax = actionFlag;
QSettings settings;
settings.setValue( "/Raster/histogram/zoomToMinMax", mHistoZoomToMinMax );
return;
}
else if ( actionName == "Update min_max" )
{
mHistoUpdateStyleToMinMax = actionFlag;
QSettings settings;
settings.setValue( "/Raster/histogram/updateStyleToMinMax", mHistoUpdateStyleToMinMax );
return;
}
else if ( actionName == "Show all" ) else if ( actionName == "Show all" )
{ {
mHistoShowBands = ShowAll; mHistoShowBands = ShowAll;
// settings.setValue( "/Raster/histogram/showBands", (int)mHistoShowBands );
refreshHistogram(); refreshHistogram();
return; return;
} }
else if ( actionName == "Show selected" ) else if ( actionName == "Show selected" )
{ {
mHistoShowBands = ShowSelected; mHistoShowBands = ShowSelected;
// settings.setValue( "/Raster/histogram/showBands", (int)mHistoShowBands );
refreshHistogram(); refreshHistogram();
return; return;
} }
else if ( actionName == "Show RGB" ) else if ( actionName == "Show RGB" )
{ {
mHistoShowBands = ShowRGB; mHistoShowBands = ShowRGB;
// settings.setValue( "/Raster/histogram/showBands", (int)mHistoShowBands );
refreshHistogram(); refreshHistogram();
return; return;
} }
#if 0
else if ( actionName == "Load apply all" ) else if ( actionName == "Load apply all" )
{ {
mHistoLoadApplyAll = actionFlag; mHistoLoadApplyAll = actionFlag;
settings.setValue( "/Raster/histogram/loadApplyAll", mHistoLoadApplyAll );
return; return;
} }
#endif
// Load actions // Load actions
// TODO - separate calculations from rendererwidget so we can do them without // TODO - separate calculations from rendererwidget so we can do them without
else if ( actionName.left( 5 ) == "Load " && mRendererWidget ) else if ( actionName.left( 5 ) == "Load " && mRendererWidget )
{ {
QVector<int> myBands; QVector<int> myBands;
bool ok = false;

#if 0 #if 0
double minMaxValues[2]; double minMaxValues[2];
#endif
bool ok = false;


// find which band(s) need updating (all or current) // find which band(s) need updating (all or current)
if ( mHistoLoadApplyAll ) if ( mHistoLoadApplyAll )
Expand All @@ -693,6 +739,8 @@ void QgsRasterHistogramWidget::histoAction( const QString actionName, bool actio
myBands << i; myBands << i;
} }
} }
#endif

// add current band to the end // add current band to the end
myBands << cboHistoBand->currentIndex() + 1; myBands << cboHistoBand->currentIndex() + 1;


Expand Down Expand Up @@ -782,13 +830,26 @@ void QgsRasterHistogramWidget::applyHistoMin( )


int theBandNo = cboHistoBand->currentIndex() + 1; int theBandNo = cboHistoBand->currentIndex() + 1;
QList< int > mySelectedBands = rendererSelectedBands(); QList< int > mySelectedBands = rendererSelectedBands();
QString min;
for ( int i = 0; i <= mySelectedBands.size(); i++ ) for ( int i = 0; i <= mySelectedBands.size(); i++ )
{ {
if ( theBandNo == mRendererWidget->selectedBand( i ) ) if ( theBandNo == mRendererWidget->selectedBand( i ) )
mRendererWidget->setMin( leHistoMin->text(), i ); {
min = leHistoMin->text();
if ( mHistoUpdateStyleToMinMax )
mRendererWidget->setMin( min, i );
}
} }


updateHistoMarkers(); updateHistoMarkers();

if ( ! min.isEmpty() && mHistoZoomToMinMax && mHistoZoomer )
{
QRectF rect = mHistoZoomer->zoomRect();
rect.setLeft( min.toDouble() );
mHistoZoomer->zoom( rect );
}

} }


void QgsRasterHistogramWidget::applyHistoMax( ) void QgsRasterHistogramWidget::applyHistoMax( )
Expand All @@ -798,13 +859,25 @@ void QgsRasterHistogramWidget::applyHistoMax( )


int theBandNo = cboHistoBand->currentIndex() + 1; int theBandNo = cboHistoBand->currentIndex() + 1;
QList< int > mySelectedBands = rendererSelectedBands(); QList< int > mySelectedBands = rendererSelectedBands();
QString max;
for ( int i = 0; i <= mySelectedBands.size(); i++ ) for ( int i = 0; i <= mySelectedBands.size(); i++ )
{ {
if ( theBandNo == mRendererWidget->selectedBand( i ) ) if ( theBandNo == mRendererWidget->selectedBand( i ) )
mRendererWidget->setMax( leHistoMax->text(), i ); {
max = leHistoMax->text();
if ( mHistoUpdateStyleToMinMax )
mRendererWidget->setMax( max, i );
}
} }


updateHistoMarkers(); updateHistoMarkers();

if ( ! max.isEmpty() && mHistoZoomToMinMax && mHistoZoomer )
{
QRectF rect = mHistoZoomer->zoomRect();
rect.setRight( max.toDouble() );
mHistoZoomer->zoom( rect );
}
} }


void QgsRasterHistogramWidget::on_btnHistoMin_toggled() void QgsRasterHistogramWidget::on_btnHistoMin_toggled()
Expand All @@ -822,6 +895,7 @@ void QgsRasterHistogramWidget::on_btnHistoMin_toggled()
mHistoZoomer->setEnabled( ! btnHistoMax->isChecked() ); mHistoZoomer->setEnabled( ! btnHistoMax->isChecked() );
mHistoPicker->setEnabled( btnHistoMin->isChecked() ); mHistoPicker->setEnabled( btnHistoMin->isChecked() );
} }
updateHistoMarkers();
} }


void QgsRasterHistogramWidget::on_btnHistoMax_toggled() void QgsRasterHistogramWidget::on_btnHistoMax_toggled()
Expand All @@ -839,6 +913,7 @@ void QgsRasterHistogramWidget::on_btnHistoMax_toggled()
mHistoZoomer->setEnabled( ! btnHistoMax->isChecked() ); mHistoZoomer->setEnabled( ! btnHistoMax->isChecked() );
mHistoPicker->setEnabled( btnHistoMax->isChecked() ); mHistoPicker->setEnabled( btnHistoMax->isChecked() );
} }
updateHistoMarkers();
} }


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


if ( ! mHistoShowMarkers || if (( ! mHistoShowMarkers && ! btnHistoMin->isChecked() && ! btnHistoMax->isChecked() ) ||
( ! mySelectedBands.isEmpty() && ! mySelectedBands.contains( theBandNo ) ) ) ( ! mySelectedBands.isEmpty() && ! mySelectedBands.contains( theBandNo ) ) )
{ {
mHistoMarkerMin->hide(); mHistoMarkerMin->hide();
mHistoMarkerMax->hide(); mHistoMarkerMax->hide();
Expand Down Expand Up @@ -1024,5 +1099,22 @@ QPair< QString, QString > QgsRasterHistogramWidget::rendererMinMax( int theBandN
} }
} }


// TODO - there are 2 definitions of raster data type that should be unified
// QgsRasterDataProvider::DataType and QGis::DataType
// TODO - fix gdal provider: changes data type when nodata value is not found
// this prevents us from getting proper min and max values here
// minStr = QString::number( QgsContrastEnhancement::minimumValuePossible( ( QGis::DataType )
// mRasterLayer->dataProvider()->dataType( theBandNo ) ) );
// maxStr = QString::number( QgsContrastEnhancement::maximumValuePossible( ( QGis::DataType )
// mRasterLayer->dataProvider()->dataType( theBandNo ) ) );

// if we get an empty result, fill with default value (histo min/max)
if ( myMinMax.first.isEmpty() )
myMinMax.first = QString::number( mHistoMin );
if ( myMinMax.second.isEmpty() )
myMinMax.second = QString::number( mHistoMax );

QgsDebugMsg( QString( "bandNo %1 got min/max [%2] [%3]" ).arg( theBandNo ).arg( myMinMax.first ).arg( myMinMax.second ) );

return myMinMax; return myMinMax;
} }
4 changes: 3 additions & 1 deletion src/gui/raster/qgsrasterhistogramwidget.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ class GUI_EXPORT QgsRasterHistogramWidget : public QWidget, private Ui::QgsRaste
double mHistoMax; double mHistoMax;
QVector<QColor> mHistoColors; QVector<QColor> mHistoColors;
bool mHistoShowMarkers; bool mHistoShowMarkers;
bool mHistoLoadApplyAll; bool mHistoZoomToMinMax;
bool mHistoUpdateStyleToMinMax;
/* bool mHistoLoadApplyAll; */
HistoShowBands mHistoShowBands; HistoShowBands mHistoShowBands;
/** \brief Returns a list of selected bands in the histogram widget- or empty if there is no selection restriction. */ /** \brief Returns a list of selected bands in the histogram widget- or empty if there is no selection restriction. */
QList< int > histoSelectedBands(); QList< int > histoSelectedBands();
Expand Down
2 changes: 1 addition & 1 deletion src/ui/qgsrasterhistogramwidgetbase.ui
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
</sizepolicy> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>Band</string> <string>Set min/max style for</string>
</property> </property>
</widget> </widget>
</item> </item>
Expand Down

0 comments on commit cf9a1b5

Please sign in to comment.