Skip to content

Commit 281b971

Browse files
author
timlinux
committed
Zen minimalism for raster graphing page
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@14296 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 6f51c4a commit 281b971

File tree

3 files changed

+276
-493
lines changed

3 files changed

+276
-493
lines changed

src/app/qgsrasterlayerproperties.cpp

+66-189
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#include "qgslogger.h"
5353

5454
// QWT Charting widget
55+
#include <qwt_plot_canvas.h>
5556
#include <qwt_array.h>
5657
#include <qwt_legend.h>
5758
#include <qwt_plot.h>
@@ -167,97 +168,23 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv
167168

168169
QgsDebugMsg( "Populating band combo boxes" );
169170

170-
//
171-
// Get a list of band names
172-
//
173-
QStringList myBandNameList;
174-
175171
int myBandCountInt = mRasterLayer->bandCount();
176-
177-
QgsDebugMsg( QString( "Looping though %1 image layers to get their names " ).arg( myBandCountInt ) );
178-
179-
for ( int myIteratorInt = 1;
180-
myIteratorInt <= myBandCountInt;
181-
++myIteratorInt )
182-
{
183-
//find out the name of this band
184-
QString myRasterBandNameQString = mRasterLayer->bandName( myIteratorInt ) ;
185-
186-
//add the band to the histogram tab
187-
//
188-
QPixmap myPixmap( 10, 10 );
189-
190-
if ( myBandCountInt == 1 ) //draw single band images with black
191-
{
192-
myPixmap.fill( Qt::black );
193-
}
194-
else if ( myIteratorInt == 1 )
195-
{
196-
myPixmap.fill( Qt::red );
197-
}
198-
else if ( myIteratorInt == 2 )
199-
{
200-
myPixmap.fill( Qt::green );
201-
}
202-
else if ( myIteratorInt == 3 )
203-
{
204-
myPixmap.fill( Qt::blue );
205-
}
206-
else if ( myIteratorInt == 4 )
207-
{
208-
myPixmap.fill( Qt::magenta );
209-
}
210-
else if ( myIteratorInt == 5 )
211-
{
212-
myPixmap.fill( Qt::darkRed );
213-
}
214-
else if ( myIteratorInt == 6 )
215-
{
216-
myPixmap.fill( Qt::darkGreen );
217-
}
218-
else if ( myIteratorInt == 7 )
219-
{
220-
myPixmap.fill( Qt::darkBlue );
221-
}
222-
else
223-
{
224-
myPixmap.fill( Qt::gray );
225-
}
226-
lstHistogramLabels->addItem( new QListWidgetItem( myPixmap, myRasterBandNameQString ) );
227-
//keep a list of band names for later use
228-
//! @note band names should not be translated!
229-
myBandNameList.append( myRasterBandNameQString );
230-
}
231-
232-
//select all histogram layers list items by default
233172
for ( int myIteratorInt = 1;
234173
myIteratorInt <= myBandCountInt;
235174
++myIteratorInt )
236175
{
237-
QListWidgetItem *myItem = lstHistogramLabels->item( myIteratorInt - 1 );
238-
myItem->setSelected( true );
239-
}
240-
241-
for ( QStringList::Iterator myIterator = myBandNameList.begin();
242-
myIterator != myBandNameList.end();
243-
++myIterator )
244-
{
245-
QString myQString = *myIterator;
246-
247-
QgsDebugMsg( QString( "Inserting : %1" ).arg( myQString ) );
248-
249-
cboGray->addItem( myQString );
250-
cboRed->addItem( myQString );
251-
cboGreen->addItem( myQString );
252-
cboBlue->addItem( myQString );
253-
cboxColorMapBand->addItem( myQString );
176+
QString myRasterBandName = mRasterLayer->bandName( myIteratorInt ) ;
177+
cboGray->addItem( myRasterBandName );
178+
cboRed->addItem( myRasterBandName );
179+
cboGreen->addItem( myRasterBandName );
180+
cboBlue->addItem( myRasterBandName );
181+
cboxColorMapBand->addItem( myRasterBandName );
254182
}
255183

256184
cboRed->addItem( TRSTRING_NOT_SET );
257185
cboGreen->addItem( TRSTRING_NOT_SET );
258186
cboBlue->addItem( TRSTRING_NOT_SET );
259187
cboGray->addItem( TRSTRING_NOT_SET );
260-
261188
cboxTransparencyBand->addItem( TRSTRING_NOT_SET );
262189

263190
QIcon myPyramidPixmap( QgisApp::getThemeIcon( "/mIconPyramid.png" ) );
@@ -1911,13 +1838,40 @@ void QgsRasterLayerProperties::on_pbnExportTransparentPixelValues_clicked()
19111838
}
19121839
}
19131840

1914-
void QgsRasterLayerProperties::on_pbnHistRefresh_clicked()
1841+
void QgsRasterLayerProperties::on_tabBar_currentChanged( int theTab )
1842+
{
1843+
int myHistogramTab = 6;
1844+
if ( theTab == myHistogramTab )
1845+
{
1846+
refreshHistogram();
1847+
}
1848+
}
1849+
1850+
void QgsRasterLayerProperties::refreshHistogram()
19151851
{
1852+
mHistogramProgress->show();
19161853
connect( mRasterLayer, SIGNAL( progressUpdate( int ) ), mHistogramProgress, SLOT( setValue( int ) ) );
19171854
QApplication::setOverrideCursor( Qt::WaitCursor );
19181855
QgsDebugMsg( "entered." );
1919-
int myBandCountInt = mRasterLayer->bandCount();
19201856

1857+
QwtPlot * mypPlot = new QwtPlot( mChartWidget );
1858+
mypPlot->canvas()->setCursor(Qt::ArrowCursor);
1859+
//ensure all children get removed
1860+
mypPlot->setAutoDelete( true );
1861+
QVBoxLayout *mpHistogramLayout = new QVBoxLayout( mChartWidget );
1862+
mpHistogramLayout->setContentsMargins( 0, 0, 0, 0 );
1863+
mpHistogramLayout->addWidget( mypPlot );
1864+
mChartWidget->setLayout( mpHistogramLayout );
1865+
mypPlot->setTitle( QObject::tr( "Raster Histogram") );
1866+
mypPlot->insertLegend( new QwtLegend(), QwtPlot::BottomLegend );
1867+
// Set axis titles
1868+
mypPlot->setAxisTitle( QwtPlot::xBottom, QObject::tr("Pixel Value") );
1869+
mypPlot->setAxisTitle( QwtPlot::yLeft, QObject::tr("Frequency") );
1870+
mypPlot->setAxisAutoScale( QwtPlot::xBottom );
1871+
mypPlot->setAxisAutoScale( QwtPlot::yLeft );
1872+
// add a grid
1873+
QwtPlotGrid * myGrid = new QwtPlotGrid();
1874+
myGrid->attach(mypPlot);
19211875
// Explanation:
19221876
// We use the gdal histogram creation routine is called for each selected
19231877
// layer. Currently the hist is hardcoded
@@ -1928,125 +1882,48 @@ void QgsRasterLayerProperties::on_pbnHistRefresh_clicked()
19281882
// bin in all selected layers, and the min. It then draws a scaled line between min
19291883
// and max - scaled to image height. 1 line drawn per selected band
19301884
//
1931-
const int BINCOUNT = spinHistBinCount->value();
1885+
const int BINCOUNT = 255;
19321886
enum GRAPH_TYPE { BAR_CHART, LINE_CHART } myGraphType;
1933-
if ( radHistTypeBar->isChecked() ) myGraphType = BAR_CHART; else myGraphType = LINE_CHART;
1934-
bool myIgnoreOutOfRangeFlag = chkHistIgnoreOutOfRange->isChecked();
1935-
bool myThoroughBandScanFlag = chkHistAllowApproximation->isChecked();
1936-
1937-
#ifdef QGISDEBUG
1938-
long myCellCount = mRasterLayer->width() * mRasterLayer->height();
1939-
#endif
1940-
1941-
QgsDebugMsg( "Computing histogram minima and maxima" );
1942-
//somtimes there are more bins than needed
1943-
//we find out the last on that actually has data in it
1944-
//so we can discard the rest adn the x-axis scales correctly
1887+
myGraphType = BAR_CHART;
1888+
bool myIgnoreOutOfRangeFlag = true;
1889+
bool myThoroughBandScanFlag = false;
19451890
int myLastBinWithData = 0;
1891+
int myBandCountInt = mRasterLayer->bandCount();
1892+
QList<QColor> myColors;
1893+
myColors << Qt::black << Qt::red << Qt::green << Qt::blue << Qt::magenta << Qt::darkRed << Qt::darkGreen << Qt::darkBlue;
19461894
//
1947-
// First scan through to get max and min cell counts from among selected layers' histograms
1895+
//now draw actual graphs
19481896
//
1949-
double myYAxisMax = 0;
1950-
double myYAxisMin = 0;
1951-
int myXAxisMin = 0;
1952-
int myXAxisMax = 0;
1953-
bool myFirstItemFlag = true;
1954-
for ( int myIteratorInt = 1;
1955-
myIteratorInt <= myBandCountInt;
1956-
++myIteratorInt )
1957-
{
1958-
QgsRasterBandStats myRasterBandStats = mRasterLayer->bandStatistics( myIteratorInt );
1959-
//calculate the x axis min max
1960-
if ( myRasterBandStats.minimumValue < myXAxisMin || myIteratorInt == 1 )
1961-
{
1962-
myXAxisMin = static_cast < unsigned int >( myRasterBandStats.minimumValue );
1963-
}
1964-
if ( myRasterBandStats.maximumValue < myXAxisMax || myIteratorInt == 1 )
1965-
{
1966-
myXAxisMax = static_cast < unsigned int >( myRasterBandStats.maximumValue );
1967-
}
1968-
QListWidgetItem *myItem = lstHistogramLabels->item( myIteratorInt - 1 );
1969-
if ( myItem->isSelected() )
1970-
{
1971-
QgsDebugMsg( "Ensuring hist is populated for this layer" );
1972-
mRasterLayer->populateHistogram( myIteratorInt, BINCOUNT, myIgnoreOutOfRangeFlag, myThoroughBandScanFlag );
1973-
1974-
QgsDebugMsg( QString( "...done...%1 bins filled" ).arg( myRasterBandStats.histogramVector->size() ) );
1975-
for ( int myBin = 0; myBin < BINCOUNT; myBin++ )
1976-
{
1977-
int myBinValue = myRasterBandStats.histogramVector->at( myBin );
1978-
if ( myBinValue > 0 && myBin > myLastBinWithData )
1979-
{
1980-
myLastBinWithData = myBin;
1981-
}
1982-
QgsDebugMsg( QString( "Testing if %1 is less than %2or greater then %3" ).arg( myBinValue ).arg( myYAxisMin ).arg( myYAxisMax ) );
1983-
if ( myBin == 0 && myFirstItemFlag )
1984-
{
1985-
myYAxisMin = myBinValue;
1986-
myYAxisMax = myBinValue;
1987-
}
1988-
1989-
if ( myBinValue > myYAxisMax )
1990-
{
1991-
myYAxisMax = myBinValue;
1992-
}
1993-
if ( myBinValue < myYAxisMin )
1994-
{
1995-
myYAxisMin = myBinValue;
1996-
}
1997-
}
1998-
myFirstItemFlag = false;
1999-
}
2000-
}
2001-
disconnect( mRasterLayer, SIGNAL( progressUpdate( int ) ), mHistogramProgress, SLOT( setValue( int ) ) );
2002-
QgsDebugMsg( QString( "max %1" ).arg( myYAxisMax ) );
2003-
QgsDebugMsg( QString( "min %1" ).arg( myYAxisMin ) );
20041897

2005-
QwtPlot * mypPlot = new QwtPlot( mChartWidget );
2006-
//ensure all children get removed
2007-
mypPlot->setAutoDelete( true );
2008-
QVBoxLayout *mpHistogramLayout = new QVBoxLayout( mChartWidget );
2009-
mpHistogramLayout->setContentsMargins( 0, 0, 0, 0 );
2010-
mpHistogramLayout->addWidget( mypPlot );
2011-
mChartWidget->setLayout( mpHistogramLayout );
2012-
mypPlot->setTitle(QObject::tr("Raster Histogram"));
2013-
mypPlot->insertLegend(new QwtLegend(), QwtPlot::BottomLegend);
2014-
// Set axis titles
2015-
mypPlot->setAxisTitle(QwtPlot::xBottom, QObject::tr("Pixel Value"));
2016-
mypPlot->setAxisTitle(QwtPlot::yLeft, QObject::tr("Frequency"));
2017-
//
2018-
// add a grid
2019-
//
2020-
QwtPlotGrid * myGrid = new QwtPlotGrid();
2021-
myGrid->attach(mypPlot);
1898+
//somtimes there are more bins than needed
1899+
//we find out the last one that actually has data in it
1900+
//so we can discard the rest and set the x-axis scales correctly
20221901
//
2023-
//now draw actual graphs
1902+
// scan through to get counts from layers' histograms
20241903
//
2025-
QList<QColor> myColors;
2026-
myColors << Qt::black << Qt::red << Qt::green << Qt::blue << Qt::magenta << Qt::darkRed << Qt::darkGreen << Qt::darkBlue;
20271904
for ( int myIteratorInt = 1;
20281905
myIteratorInt <= myBandCountInt;
20291906
++myIteratorInt )
20301907
{
20311908
QgsRasterBandStats myRasterBandStats = mRasterLayer->bandStatistics( myIteratorInt );
2032-
QListWidgetItem *myItem = lstHistogramLabels->item( myIteratorInt - 1 );
2033-
if ( myItem->isSelected() )
2034-
{
2035-
QwtPlotCurve * mypCurve = new QwtPlotCurve( tr( "Band %i" ).arg( myIteratorInt ) );
2036-
mypCurve->setRenderHint( QwtPlotItem::RenderAntialiased );
2037-
mypCurve->setPen(QPen( myColors.at( myIteratorInt ) ) );
2038-
QwtArray<double> myX2Data;//qwtarray is just a wrapped qvector
2039-
QwtArray<double> myY2Data;//qwtarray is just a wrapped qvector
2040-
for ( int myBin = 0; myBin < myLastBinWithData; myBin++ )
2041-
{
2042-
double myBinValue = myRasterBandStats.histogramVector->at( myBin );
2043-
myX2Data.append(myBin);
2044-
myY2Data.append(myBinValue);
2045-
}
2046-
mypCurve->setData(myX2Data,myY2Data);
2047-
mypCurve->attach(mypPlot);
2048-
}
2049-
}
1909+
mRasterLayer->populateHistogram( myIteratorInt, BINCOUNT, myIgnoreOutOfRangeFlag, myThoroughBandScanFlag );
1910+
QwtPlotCurve * mypCurve = new QwtPlotCurve( tr( "Band %1" ).arg( myIteratorInt ) );
1911+
mypCurve->setRenderHint( QwtPlotItem::RenderAntialiased );
1912+
mypCurve->setPen(QPen( myColors.at( myIteratorInt ) ) );
1913+
QwtArray<double> myX2Data;//qwtarray is just a wrapped qvector
1914+
QwtArray<double> myY2Data;//qwtarray is just a wrapped qvector
1915+
for ( int myBin = 0; myBin < BINCOUNT; myBin++ )
1916+
{
1917+
int myBinValue = myRasterBandStats.histogramVector->at( myBin );
1918+
myX2Data.append( double( myBin) );
1919+
myY2Data.append( double( myBinValue) );
1920+
}
1921+
mypCurve->setData(myX2Data,myY2Data);
1922+
mypCurve->attach(mypPlot);
1923+
}
1924+
mypPlot->replot();
1925+
disconnect( mRasterLayer, SIGNAL( progressUpdate( int ) ), mHistogramProgress, SLOT( setValue( int ) ) );
1926+
mHistogramProgress->hide();
20501927
QApplication::restoreOverrideCursor();
20511928
}
20521929

src/app/qgsrasterlayerproperties.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,10 @@ class QgsRasterLayerProperties : public QDialog, private Ui::QgsRasterLayerPrope
6868
void on_pbnDefaultValues_clicked();
6969
/** \brief slot executed when user wishes to export transparency values */
7070
void on_pbnExportTransparentPixelValues_clicked();
71+
/** \brief auto slot executed when the active page in the main widget stack is changed */
72+
void on_tabBar_currentChanged( int theTab );
7173
/** \brief slot executed when user wishes to refresh raster histogram */
72-
void on_pbnHistRefresh_clicked();
74+
void refreshHistogram();
7375
/** \brief slow executed when user wishes to import transparency values */
7476
void on_pbnImportTransparentPixelValues_clicked();
7577
/** \brief slot executed when user presses "Remove Selected Row" button on the transparency page */

0 commit comments

Comments
 (0)