diff --git a/src/app/qgsrasterlayerproperties.cpp b/src/app/qgsrasterlayerproperties.cpp index 9b6f6b552c3..5906d925d31 100644 --- a/src/app/qgsrasterlayerproperties.cpp +++ b/src/app/qgsrasterlayerproperties.cpp @@ -52,6 +52,7 @@ #include "qgslogger.h" // QWT Charting widget +#include #include #include #include @@ -167,97 +168,23 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv QgsDebugMsg( "Populating band combo boxes" ); - // - // Get a list of band names - // - QStringList myBandNameList; - int myBandCountInt = mRasterLayer->bandCount(); - - QgsDebugMsg( QString( "Looping though %1 image layers to get their names " ).arg( myBandCountInt ) ); - for ( int myIteratorInt = 1; myIteratorInt <= myBandCountInt; ++myIteratorInt ) { - //find out the name of this band - QString myRasterBandNameQString = mRasterLayer->bandName( myIteratorInt ) ; - - //add the band to the histogram tab - // - QPixmap myPixmap( 10, 10 ); - - if ( myBandCountInt == 1 ) //draw single band images with black - { - myPixmap.fill( Qt::black ); - } - else if ( myIteratorInt == 1 ) - { - myPixmap.fill( Qt::red ); - } - else if ( myIteratorInt == 2 ) - { - myPixmap.fill( Qt::green ); - } - else if ( myIteratorInt == 3 ) - { - myPixmap.fill( Qt::blue ); - } - else if ( myIteratorInt == 4 ) - { - myPixmap.fill( Qt::magenta ); - } - else if ( myIteratorInt == 5 ) - { - myPixmap.fill( Qt::darkRed ); - } - else if ( myIteratorInt == 6 ) - { - myPixmap.fill( Qt::darkGreen ); - } - else if ( myIteratorInt == 7 ) - { - myPixmap.fill( Qt::darkBlue ); - } - else - { - myPixmap.fill( Qt::gray ); - } - lstHistogramLabels->addItem( new QListWidgetItem( myPixmap, myRasterBandNameQString ) ); - //keep a list of band names for later use - //! @note band names should not be translated! - myBandNameList.append( myRasterBandNameQString ); - } - - //select all histogram layers list items by default - for ( int myIteratorInt = 1; - myIteratorInt <= myBandCountInt; - ++myIteratorInt ) - { - QListWidgetItem *myItem = lstHistogramLabels->item( myIteratorInt - 1 ); - myItem->setSelected( true ); - } - - for ( QStringList::Iterator myIterator = myBandNameList.begin(); - myIterator != myBandNameList.end(); - ++myIterator ) - { - QString myQString = *myIterator; - - QgsDebugMsg( QString( "Inserting : %1" ).arg( myQString ) ); - - cboGray->addItem( myQString ); - cboRed->addItem( myQString ); - cboGreen->addItem( myQString ); - cboBlue->addItem( myQString ); - cboxColorMapBand->addItem( myQString ); + QString myRasterBandName = mRasterLayer->bandName( myIteratorInt ) ; + cboGray->addItem( myRasterBandName ); + cboRed->addItem( myRasterBandName ); + cboGreen->addItem( myRasterBandName ); + cboBlue->addItem( myRasterBandName ); + cboxColorMapBand->addItem( myRasterBandName ); } cboRed->addItem( TRSTRING_NOT_SET ); cboGreen->addItem( TRSTRING_NOT_SET ); cboBlue->addItem( TRSTRING_NOT_SET ); cboGray->addItem( TRSTRING_NOT_SET ); - cboxTransparencyBand->addItem( TRSTRING_NOT_SET ); QIcon myPyramidPixmap( QgisApp::getThemeIcon( "/mIconPyramid.png" ) ); @@ -1911,13 +1838,40 @@ void QgsRasterLayerProperties::on_pbnExportTransparentPixelValues_clicked() } } -void QgsRasterLayerProperties::on_pbnHistRefresh_clicked() +void QgsRasterLayerProperties::on_tabBar_currentChanged( int theTab ) { + int myHistogramTab = 6; + if ( theTab == myHistogramTab ) + { + refreshHistogram(); + } +} + +void QgsRasterLayerProperties::refreshHistogram() +{ + mHistogramProgress->show(); connect( mRasterLayer, SIGNAL( progressUpdate( int ) ), mHistogramProgress, SLOT( setValue( int ) ) ); QApplication::setOverrideCursor( Qt::WaitCursor ); QgsDebugMsg( "entered." ); - int myBandCountInt = mRasterLayer->bandCount(); + QwtPlot * mypPlot = new QwtPlot( mChartWidget ); + mypPlot->canvas()->setCursor(Qt::ArrowCursor); + //ensure all children get removed + mypPlot->setAutoDelete( true ); + QVBoxLayout *mpHistogramLayout = new QVBoxLayout( mChartWidget ); + mpHistogramLayout->setContentsMargins( 0, 0, 0, 0 ); + mpHistogramLayout->addWidget( mypPlot ); + mChartWidget->setLayout( mpHistogramLayout ); + mypPlot->setTitle( QObject::tr( "Raster Histogram") ); + mypPlot->insertLegend( new QwtLegend(), QwtPlot::BottomLegend ); + // Set axis titles + mypPlot->setAxisTitle( QwtPlot::xBottom, QObject::tr("Pixel Value") ); + mypPlot->setAxisTitle( QwtPlot::yLeft, QObject::tr("Frequency") ); + mypPlot->setAxisAutoScale( QwtPlot::xBottom ); + mypPlot->setAxisAutoScale( QwtPlot::yLeft ); + // add a grid + QwtPlotGrid * myGrid = new QwtPlotGrid(); + myGrid->attach(mypPlot); // Explanation: // We use the gdal histogram creation routine is called for each selected // layer. Currently the hist is hardcoded @@ -1928,125 +1882,48 @@ void QgsRasterLayerProperties::on_pbnHistRefresh_clicked() // bin in all selected layers, and the min. It then draws a scaled line between min // and max - scaled to image height. 1 line drawn per selected band // - const int BINCOUNT = spinHistBinCount->value(); + const int BINCOUNT = 255; enum GRAPH_TYPE { BAR_CHART, LINE_CHART } myGraphType; - if ( radHistTypeBar->isChecked() ) myGraphType = BAR_CHART; else myGraphType = LINE_CHART; - bool myIgnoreOutOfRangeFlag = chkHistIgnoreOutOfRange->isChecked(); - bool myThoroughBandScanFlag = chkHistAllowApproximation->isChecked(); - -#ifdef QGISDEBUG - long myCellCount = mRasterLayer->width() * mRasterLayer->height(); -#endif - - QgsDebugMsg( "Computing histogram minima and maxima" ); - //somtimes there are more bins than needed - //we find out the last on that actually has data in it - //so we can discard the rest adn the x-axis scales correctly + myGraphType = BAR_CHART; + bool myIgnoreOutOfRangeFlag = true; + bool myThoroughBandScanFlag = false; int myLastBinWithData = 0; - // - // First scan through to get max and min cell counts from among selected layers' histograms - // - double myYAxisMax = 0; - double myYAxisMin = 0; - int myXAxisMin = 0; - int myXAxisMax = 0; - bool myFirstItemFlag = true; - for ( int myIteratorInt = 1; - myIteratorInt <= myBandCountInt; - ++myIteratorInt ) - { - QgsRasterBandStats myRasterBandStats = mRasterLayer->bandStatistics( myIteratorInt ); - //calculate the x axis min max - if ( myRasterBandStats.minimumValue < myXAxisMin || myIteratorInt == 1 ) - { - myXAxisMin = static_cast < unsigned int >( myRasterBandStats.minimumValue ); - } - if ( myRasterBandStats.maximumValue < myXAxisMax || myIteratorInt == 1 ) - { - myXAxisMax = static_cast < unsigned int >( myRasterBandStats.maximumValue ); - } - QListWidgetItem *myItem = lstHistogramLabels->item( myIteratorInt - 1 ); - if ( myItem->isSelected() ) - { - QgsDebugMsg( "Ensuring hist is populated for this layer" ); - mRasterLayer->populateHistogram( myIteratorInt, BINCOUNT, myIgnoreOutOfRangeFlag, myThoroughBandScanFlag ); - - QgsDebugMsg( QString( "...done...%1 bins filled" ).arg( myRasterBandStats.histogramVector->size() ) ); - for ( int myBin = 0; myBin < BINCOUNT; myBin++ ) - { - int myBinValue = myRasterBandStats.histogramVector->at( myBin ); - if ( myBinValue > 0 && myBin > myLastBinWithData ) - { - myLastBinWithData = myBin; - } - QgsDebugMsg( QString( "Testing if %1 is less than %2or greater then %3" ).arg( myBinValue ).arg( myYAxisMin ).arg( myYAxisMax ) ); - if ( myBin == 0 && myFirstItemFlag ) - { - myYAxisMin = myBinValue; - myYAxisMax = myBinValue; - } - - if ( myBinValue > myYAxisMax ) - { - myYAxisMax = myBinValue; - } - if ( myBinValue < myYAxisMin ) - { - myYAxisMin = myBinValue; - } - } - myFirstItemFlag = false; - } - } - disconnect( mRasterLayer, SIGNAL( progressUpdate( int ) ), mHistogramProgress, SLOT( setValue( int ) ) ); - QgsDebugMsg( QString( "max %1" ).arg( myYAxisMax ) ); - QgsDebugMsg( QString( "min %1" ).arg( myYAxisMin ) ); - - QwtPlot * mypPlot = new QwtPlot( mChartWidget ); - //ensure all children get removed - mypPlot->setAutoDelete( true ); - QVBoxLayout *mpHistogramLayout = new QVBoxLayout( mChartWidget ); - mpHistogramLayout->setContentsMargins( 0, 0, 0, 0 ); - mpHistogramLayout->addWidget( mypPlot ); - mChartWidget->setLayout( mpHistogramLayout ); - mypPlot->setTitle(QObject::tr("Raster Histogram")); - mypPlot->insertLegend(new QwtLegend(), QwtPlot::BottomLegend); - // Set axis titles - mypPlot->setAxisTitle(QwtPlot::xBottom, QObject::tr("Pixel Value")); - mypPlot->setAxisTitle(QwtPlot::yLeft, QObject::tr("Frequency")); - // - // add a grid - // - QwtPlotGrid * myGrid = new QwtPlotGrid(); - myGrid->attach(mypPlot); + int myBandCountInt = mRasterLayer->bandCount(); + QList myColors; + myColors << Qt::black << Qt::red << Qt::green << Qt::blue << Qt::magenta << Qt::darkRed << Qt::darkGreen << Qt::darkBlue; // //now draw actual graphs // - QList myColors; - myColors << Qt::black << Qt::red << Qt::green << Qt::blue << Qt::magenta << Qt::darkRed << Qt::darkGreen << Qt::darkBlue; + + //somtimes there are more bins than needed + //we find out the last one that actually has data in it + //so we can discard the rest and set the x-axis scales correctly + // + // scan through to get counts from layers' histograms + // for ( int myIteratorInt = 1; myIteratorInt <= myBandCountInt; ++myIteratorInt ) { QgsRasterBandStats myRasterBandStats = mRasterLayer->bandStatistics( myIteratorInt ); - QListWidgetItem *myItem = lstHistogramLabels->item( myIteratorInt - 1 ); - if ( myItem->isSelected() ) + mRasterLayer->populateHistogram( myIteratorInt, BINCOUNT, myIgnoreOutOfRangeFlag, myThoroughBandScanFlag ); + QwtPlotCurve * mypCurve = new QwtPlotCurve( tr( "Band %1" ).arg( myIteratorInt ) ); + mypCurve->setRenderHint( QwtPlotItem::RenderAntialiased ); + mypCurve->setPen(QPen( myColors.at( myIteratorInt ) ) ); + QwtArray myX2Data;//qwtarray is just a wrapped qvector + QwtArray myY2Data;//qwtarray is just a wrapped qvector + for ( int myBin = 0; myBin < BINCOUNT; myBin++ ) { - QwtPlotCurve * mypCurve = new QwtPlotCurve( tr( "Band %i" ).arg( myIteratorInt ) ); - mypCurve->setRenderHint( QwtPlotItem::RenderAntialiased ); - mypCurve->setPen(QPen( myColors.at( myIteratorInt ) ) ); - QwtArray myX2Data;//qwtarray is just a wrapped qvector - QwtArray myY2Data;//qwtarray is just a wrapped qvector - for ( int myBin = 0; myBin < myLastBinWithData; myBin++ ) - { - double myBinValue = myRasterBandStats.histogramVector->at( myBin ); - myX2Data.append(myBin); - myY2Data.append(myBinValue); - } - mypCurve->setData(myX2Data,myY2Data); - mypCurve->attach(mypPlot); + int myBinValue = myRasterBandStats.histogramVector->at( myBin ); + myX2Data.append( double( myBin) ); + myY2Data.append( double( myBinValue) ); } + mypCurve->setData(myX2Data,myY2Data); + mypCurve->attach(mypPlot); } + mypPlot->replot(); + disconnect( mRasterLayer, SIGNAL( progressUpdate( int ) ), mHistogramProgress, SLOT( setValue( int ) ) ); + mHistogramProgress->hide(); QApplication::restoreOverrideCursor(); } diff --git a/src/app/qgsrasterlayerproperties.h b/src/app/qgsrasterlayerproperties.h index c74253513fb..ca0c0c38cb4 100644 --- a/src/app/qgsrasterlayerproperties.h +++ b/src/app/qgsrasterlayerproperties.h @@ -68,8 +68,10 @@ class QgsRasterLayerProperties : public QDialog, private Ui::QgsRasterLayerPrope void on_pbnDefaultValues_clicked(); /** \brief slot executed when user wishes to export transparency values */ void on_pbnExportTransparentPixelValues_clicked(); + /** \brief auto slot executed when the active page in the main widget stack is changed */ + void on_tabBar_currentChanged( int theTab ); /** \brief slot executed when user wishes to refresh raster histogram */ - void on_pbnHistRefresh_clicked(); + void refreshHistogram(); /** \brief slow executed when user wishes to import transparency values */ void on_pbnImportTransparentPixelValues_clicked(); /** \brief slot executed when user presses "Remove Selected Row" button on the transparency page */ diff --git a/src/ui/qgsrasterlayerpropertiesbase.ui b/src/ui/qgsrasterlayerpropertiesbase.ui index fcc3f7a1d22..6e29e52cb94 100644 --- a/src/ui/qgsrasterlayerpropertiesbase.ui +++ b/src/ui/qgsrasterlayerpropertiesbase.ui @@ -6,8 +6,8 @@ 0 0 - 757 - 638 + 755 + 618 @@ -25,175 +25,42 @@ true - - - - - 110 - 0 - + + + + Restore Default Style - - - 110 - 16777215 - + + + + + + Save As Default - - QFrame::NoFrame + + + + + + Load Style ... - - QFrame::Plain + + + + + + Save Style ... - - Qt::ScrollBarAlwaysOff + + + + + + Qt::Horizontal - - QAbstractItemView::NoEditTriggers + + QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok - - false - - - - 64 - 64 - - - - Qt::ElideNone - - - QListView::TopToBottom - - - false - - - QListView::Adjust - - - 9 - - - QListView::IconMode - - - true - - - - Symbology - - - AlignHCenter|AlignVCenter|AlignCenter - - - - :/images/themes/default/propertyicons/symbology.png:/images/themes/default/propertyicons/symbology.png - - - ItemIsSelectable|ItemIsUserCheckable|ItemIsEnabled - - - - - Transparency - - - AlignHCenter|AlignVCenter|AlignCenter - - - - :/images/themes/default/propertyicons/transparency.png:/images/themes/default/propertyicons/transparency.png - - - ItemIsSelectable|ItemIsUserCheckable|ItemIsEnabled - - - - - Colormap - - - AlignHCenter|AlignVCenter|AlignCenter - - - - :/images/themes/default/propertyicons/colormap.png:/images/themes/default/propertyicons/colormap.png - - - ItemIsSelectable|ItemIsUserCheckable|ItemIsEnabled - - - - - General - - - AlignHCenter|AlignVCenter|AlignCenter - - - - :/images/themes/default/propertyicons/general.png:/images/themes/default/propertyicons/general.png - - - ItemIsSelectable|ItemIsUserCheckable|ItemIsEnabled - - - - - Metadata - - - AlignHCenter|AlignVCenter|AlignCenter - - - - :/images/themes/default/propertyicons/metadata.png:/images/themes/default/propertyicons/metadata.png - - - ItemIsSelectable|ItemIsUserCheckable|ItemIsEnabled - - - - - Pyramids - - - AlignHCenter|AlignVCenter|AlignCenter - - - - :/images/themes/default/propertyicons/pyramids.png:/images/themes/default/propertyicons/pyramids.png - - - ItemIsSelectable|ItemIsUserCheckable|ItemIsEnabled - - - - - Histogram - - - AlignHCenter|AlignVCenter|AlignCenter - - - - :/images/themes/default/propertyicons/histogram.png:/images/themes/default/propertyicons/histogram.png - - - ItemIsSelectable|ItemIsUserCheckable|ItemIsEnabled - - - - - - - - NoItemFlags - - @@ -1893,6 +1760,8 @@ p, li { white-space: pre-wrap; } <td style="border: none;"> <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"></p> <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"></p> <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans Serif'; font-size:9pt;"></p></td></tr></table></body></html> @@ -1963,159 +1832,201 @@ p, li { white-space: pre-wrap; } - - - - - - - 99999 - 32767 - - - - QAbstractItemView::MultiSelection - - - - - + - + 0 0 - - Chart Type + + + 16777215 + 16777215 + - - - 11 - - - - - Line graph - - - true - - - - - - - Bar chart - - - - - - - - Options - - - - - - Column count - - - - - - - 8 - - - 1024 - - - 8 - - - 64 - - - - - - - Out of range OK? - - - - - - - Allow approximation - - - true - - - - - - - + 0 - - - - Refresh - - - - - - - Restore Default Style + + + + + 110 + 0 + - - - - - - Save As Default + + + 110 + 16777215 + - - - - - - Load Style ... + + QFrame::NoFrame - - - - - - Save Style ... + + QFrame::Plain - - - - - - Qt::Horizontal + + Qt::ScrollBarAlwaysOff - - QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok + + QAbstractItemView::NoEditTriggers + + false + + + + 64 + 64 + + + + Qt::ElideNone + + + QListView::TopToBottom + + + false + + + QListView::Adjust + + + 9 + + + QListView::IconMode + + + true + + + + Symbology + + + AlignHCenter|AlignVCenter|AlignCenter + + + + :/images/themes/default/propertyicons/symbology.png:/images/themes/default/propertyicons/symbology.png + + + ItemIsSelectable|ItemIsUserCheckable|ItemIsEnabled + + + + + Transparency + + + AlignHCenter|AlignVCenter|AlignCenter + + + + :/images/themes/default/propertyicons/transparency.png:/images/themes/default/propertyicons/transparency.png + + + ItemIsSelectable|ItemIsUserCheckable|ItemIsEnabled + + + + + Colormap + + + AlignHCenter|AlignVCenter|AlignCenter + + + + :/images/themes/default/propertyicons/colormap.png:/images/themes/default/propertyicons/colormap.png + + + ItemIsSelectable|ItemIsUserCheckable|ItemIsEnabled + + + + + General + + + AlignHCenter|AlignVCenter|AlignCenter + + + + :/images/themes/default/propertyicons/general.png:/images/themes/default/propertyicons/general.png + + + ItemIsSelectable|ItemIsUserCheckable|ItemIsEnabled + + + + + Metadata + + + AlignHCenter|AlignVCenter|AlignCenter + + + + :/images/themes/default/propertyicons/metadata.png:/images/themes/default/propertyicons/metadata.png + + + ItemIsSelectable|ItemIsUserCheckable|ItemIsEnabled + + + + + Pyramids + + + AlignHCenter|AlignVCenter|AlignCenter + + + + :/images/themes/default/propertyicons/pyramids.png:/images/themes/default/propertyicons/pyramids.png + + + ItemIsSelectable|ItemIsUserCheckable|ItemIsEnabled + + + + + Histogram + + + AlignHCenter|AlignVCenter|AlignCenter + + + + :/images/themes/default/propertyicons/histogram.png:/images/themes/default/propertyicons/histogram.png + + + ItemIsSelectable|ItemIsUserCheckable|ItemIsEnabled + + + + + + + + NoItemFlags + + @@ -2145,18 +2056,11 @@ p, li { white-space: pre-wrap; } tePyramidDescription cboResamplingMethod buttonBuildPyramids - radHistTypeBar - radHistTypeLine - spinHistBinCount - chkHistIgnoreOutOfRange - chkHistAllowApproximation - pbnHistRefresh leGrayMin cboGray lbxPyramidResolutions leGrayMax cboxColorMap - lstHistogramLabels sboxSingleBandStdDev @@ -2170,8 +2074,8 @@ p, li { white-space: pre-wrap; } reject() - 476 - 620 + 485 + 608 3