From a975f302571e43ee35a906074a2721ebd35bcd2e Mon Sep 17 00:00:00 2001 From: Tim Sutton Date: Sun, 20 Nov 2011 00:21:50 +0200 Subject: [PATCH] In progress work to replace qwt with flot for raster histogram --- resources/CMakeLists.txt | 1 + src/app/CMakeLists.txt | 1 + src/app/qgsrasterlayerproperties.cpp | 106 ++----------------------- src/ui/qgsrasterlayerpropertiesbase.ui | 43 +++++----- 4 files changed, 34 insertions(+), 117 deletions(-) diff --git a/resources/CMakeLists.txt b/resources/CMakeLists.txt index 9d903592190..693d20eb838 100644 --- a/resources/CMakeLists.txt +++ b/resources/CMakeLists.txt @@ -2,3 +2,4 @@ INSTALL(FILES srs.db qgis.db qgis_help.db symbology-ng-style.xml spatialite.db c DESTINATION ${QGIS_DATA_DIR}/resources) ADD_SUBDIRECTORY(context_help) +ADD_SUBDIRECTORY(js) diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index f9546b9825b..ef70a5025e9 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -415,6 +415,7 @@ TARGET_LINK_LIBRARIES(${QGIS_APP_NAME} ${QWT_LIBRARY} ${QT_QTSQL_LIBRARY} ${QT_QTUITOOLS_LIBRARY} + ${QT_QTWEBKIT_LIBRARY} #should only be needed for win ${QT_QTMAIN_LIBRARY} ${QWTPOLAR_LIBRARY} diff --git a/src/app/qgsrasterlayerproperties.cpp b/src/app/qgsrasterlayerproperties.cpp index 4ce3f49c978..cda6da1f934 100644 --- a/src/app/qgsrasterlayerproperties.cpp +++ b/src/app/qgsrasterlayerproperties.cpp @@ -51,14 +51,8 @@ #include #include #include +#include -// QWT Charting widget -#include -#include -#include -#include -#include -#include QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanvas* theCanvas, QWidget *parent, Qt::WFlags fl ) : QDialog( parent, fl ), @@ -1858,25 +1852,10 @@ void QgsRasterLayerProperties::on_tabBar_currentChanged( int theTab ) void QgsRasterLayerProperties::refreshHistogram() { -#if !defined(QWT_VERSION) || QWT_VERSION<0x060000 - mpPlot->clear(); -#endif mHistogramProgress->show(); connect( mRasterLayer, SIGNAL( progressUpdate( int ) ), mHistogramProgress, SLOT( setValue( int ) ) ); QApplication::setOverrideCursor( Qt::WaitCursor ); - QgsDebugMsg( "entered." ); - //ensure all children get removed - mpPlot->setAutoDelete( true ); - mpPlot->setTitle( QObject::tr( "Raster Histogram" ) ); - mpPlot->insertLegend( new QwtLegend(), QwtPlot::BottomLegend ); - // Set axis titles - mpPlot->setAxisTitle( QwtPlot::xBottom, QObject::tr( "Pixel Value" ) ); - mpPlot->setAxisTitle( QwtPlot::yLeft, QObject::tr( "Frequency" ) ); - mpPlot->setAxisAutoScale( QwtPlot::yLeft ); - // x axis scale only set after computing global min/max across bands (see below) - // add a grid - QwtPlotGrid * myGrid = new QwtPlotGrid(); - myGrid->attach( mpPlot ); + mWebPlot->setHtml("

Hellow World

"); // Explanation: // We use the gdal histogram creation routine is called for each selected // layer. Currently the hist is hardcoded @@ -1891,115 +1870,44 @@ void QgsRasterLayerProperties::refreshHistogram() bool myIgnoreOutOfRangeFlag = true; bool myThoroughBandScanFlag = false; int myBandCountInt = mRasterLayer->bandCount(); - QList myColors; - myColors << Qt::black << Qt::red << Qt::green << Qt::blue << Qt::magenta << Qt::darkRed << Qt::darkGreen << Qt::darkBlue; - - while ( myColors.size() <= myBandCountInt ) - { - myColors << - QColor( 1 + ( int )( 255.0 * rand() / ( RAND_MAX + 1.0 ) ), - 1 + ( int )( 255.0 * rand() / ( RAND_MAX + 1.0 ) ), - 1 + ( int )( 255.0 * rand() / ( RAND_MAX + 1.0 ) ) ); - } - // //now draw actual graphs // - //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 - // - float myGlobalMin = 0; - float myGlobalMax = 0; bool myFirstIteration = true; for ( int myIteratorInt = 1; - myIteratorInt <= myBandCountInt; - ++myIteratorInt ) + myIteratorInt <= myBandCountInt; + ++myIteratorInt ) { QgsRasterBandStats myRasterBandStats = mRasterLayer->bandStatistics( myIteratorInt ); mRasterLayer->populateHistogram( myIteratorInt, BINCOUNT, myIgnoreOutOfRangeFlag, myThoroughBandScanFlag ); - QwtPlotCurve * mypCurve = new QwtPlotCurve( tr( "Band %1" ).arg( myIteratorInt ) ); - mypCurve->setCurveAttribute( QwtPlotCurve::Fitted ); - mypCurve->setRenderHint( QwtPlotItem::RenderAntialiased ); - mypCurve->setPen( QPen( myColors.at( myIteratorInt ) ) ); -#if defined(QWT_VERSION) && QWT_VERSION>=0x060000 - QVector data; -#else - QVector myX2Data; - QVector myY2Data; -#endif for ( int myBin = 0; myBin < BINCOUNT; myBin++ ) { int myBinValue = myRasterBandStats.histogramVector->at( myBin ); -#if defined(QWT_VERSION) && QWT_VERSION>=0x060000 - data << QPointF( myBin, myBinValue ); -#else - myX2Data.append( double( myBin ) ); - myY2Data.append( double( myBinValue ) ); -#endif } -#if defined(QWT_VERSION) && QWT_VERSION>=0x060000 - mypCurve->setSamples( data ); -#else - mypCurve->setData( myX2Data, myY2Data ); -#endif - mypCurve->attach( mpPlot ); - if ( myFirstIteration || myGlobalMin < myRasterBandStats.minimumValue ) - { - myGlobalMin = myRasterBandStats.minimumValue; - } - if ( myFirstIteration || myGlobalMax < myRasterBandStats.maximumValue ) - { - myGlobalMax = myRasterBandStats.maximumValue; - } - myFirstIteration = false; } - // for x axis use band pixel values rather than gdal hist. bin values - // subtract -0.5 to prevent rounding errors - // see http://www.gdal.org/classGDALRasterBand.html#3f8889607d3b2294f7e0f11181c201c8 - mpPlot->setAxisScale( QwtPlot::xBottom, - myGlobalMin - 0.5, - myGlobalMax + 0.5 ); - mpPlot->replot(); disconnect( mRasterLayer, SIGNAL( progressUpdate( int ) ), mHistogramProgress, SLOT( setValue( int ) ) ); mHistogramProgress->hide(); - mpPlot->canvas()->setCursor( Qt::ArrowCursor ); QApplication::restoreOverrideCursor(); } void QgsRasterLayerProperties::on_mSaveAsImageButton_clicked() { - if ( mpPlot == 0 ) - { - return; - } QPixmap myPixmap( 600, 600 ); myPixmap.fill( Qt::white ); // Qt::transparent ? -#if (QWT_VERSION<0x060000) - QwtPlotPrintFilter myFilter; - int myOptions = QwtPlotPrintFilter::PrintAll; - myOptions &= ~QwtPlotPrintFilter::PrintBackground; - myOptions |= QwtPlotPrintFilter::PrintFrameWithScales; - myFilter.setOptions( myOptions ); - - mpPlot->print( myPixmap, myFilter ); -#else QPainter painter; painter.begin( &myPixmap ); - mpPlot->drawCanvas( &painter ); + //mWebPlot->drawCanvas( &painter ); painter.end(); -#endif QPair< QString, QString> myFileNameAndFilter = QgisGui::getSaveAsImageName( this, tr( "Choose a file name to save the map image as" ) ); if ( myFileNameAndFilter.first != "" ) { myPixmap.save( myFileNameAndFilter.first ); } } + void QgsRasterLayerProperties::on_pbnImportTransparentPixelValues_clicked() { int myLineCounter = 0; @@ -2864,6 +2772,7 @@ QLinearGradient QgsRasterLayerProperties::grayGradient() myGradient.setColorAt( 1.0, QColor( 220, 220, 220, 190 ) ); return myGradient; } + QLinearGradient QgsRasterLayerProperties::highlightGradient() { //define another gradient for the highlight @@ -3074,4 +2983,3 @@ void QgsRasterLayerProperties::toggleBuildPyramidsButton() buttonBuildPyramids->setEnabled( true ); } } - diff --git a/src/ui/qgsrasterlayerpropertiesbase.ui b/src/ui/qgsrasterlayerpropertiesbase.ui index 7fb6087b085..3107260c1d6 100644 --- a/src/ui/qgsrasterlayerpropertiesbase.ui +++ b/src/ui/qgsrasterlayerpropertiesbase.ui @@ -1771,21 +1771,22 @@ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Ubuntu'; font-size:10pt; font-weight:400; font-style:normal;"> +</style></head><body style=" font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;"> <table border="0" style="-qt-table-type: root; margin-top:4px; margin-bottom:4px; margin-left:4px; margin-right:4px;"> <tr> <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; font-family:'Sans';"></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-size:11pt;"></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';"></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';"></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';"></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';"></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';"></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';"></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';"></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';"></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';"></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-size:10pt;"></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'; font-size:10pt;"></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'; font-size:10pt;"></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'; font-size:10pt;"></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'; font-size:10pt;"></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'; font-size:10pt;"></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'; font-size:10pt;"></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'; font-size:10pt;"></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'; font-size:10pt;"></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'; font-size:10pt;"></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'; font-size:10pt;"></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> @@ -1865,9 +1866,6 @@ p, li { white-space: pre-wrap; } Histogram - - - @@ -1886,6 +1884,15 @@ p, li { white-space: pre-wrap; } + + + + + about:blank + + + + @@ -1933,9 +1940,9 @@ p, li { white-space: pre-wrap; } - QwtPlot - QFrame -
qwt_plot.h
+ QWebView + QWidget +
QtWebKit/QWebView