Skip to content

Commit a975f30

Browse files
committedNov 19, 2011
In progress work to replace qwt with flot for raster histogram
1 parent e49bdbc commit a975f30

File tree

4 files changed

+34
-117
lines changed

4 files changed

+34
-117
lines changed
 

‎resources/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ INSTALL(FILES srs.db qgis.db qgis_help.db symbology-ng-style.xml spatialite.db c
22
DESTINATION ${QGIS_DATA_DIR}/resources)
33

44
ADD_SUBDIRECTORY(context_help)
5+
ADD_SUBDIRECTORY(js)

‎src/app/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ TARGET_LINK_LIBRARIES(${QGIS_APP_NAME}
415415
${QWT_LIBRARY}
416416
${QT_QTSQL_LIBRARY}
417417
${QT_QTUITOOLS_LIBRARY}
418+
${QT_QTWEBKIT_LIBRARY}
418419
#should only be needed for win
419420
${QT_QTMAIN_LIBRARY}
420421
${QWTPOLAR_LIBRARY}

‎src/app/qgsrasterlayerproperties.cpp

Lines changed: 7 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,8 @@
5151
#include <QSettings>
5252
#include <QMouseEvent>
5353
#include <QVector>
54+
#include <QWebView>
5455

55-
// QWT Charting widget
56-
#include <qwt_global.h>
57-
#include <qwt_plot_canvas.h>
58-
#include <qwt_legend.h>
59-
#include <qwt_plot.h>
60-
#include <qwt_plot_curve.h>
61-
#include <qwt_plot_grid.h>
6256

6357
QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanvas* theCanvas, QWidget *parent, Qt::WFlags fl )
6458
: QDialog( parent, fl ),
@@ -1858,25 +1852,10 @@ void QgsRasterLayerProperties::on_tabBar_currentChanged( int theTab )
18581852

18591853
void QgsRasterLayerProperties::refreshHistogram()
18601854
{
1861-
#if !defined(QWT_VERSION) || QWT_VERSION<0x060000
1862-
mpPlot->clear();
1863-
#endif
18641855
mHistogramProgress->show();
18651856
connect( mRasterLayer, SIGNAL( progressUpdate( int ) ), mHistogramProgress, SLOT( setValue( int ) ) );
18661857
QApplication::setOverrideCursor( Qt::WaitCursor );
1867-
QgsDebugMsg( "entered." );
1868-
//ensure all children get removed
1869-
mpPlot->setAutoDelete( true );
1870-
mpPlot->setTitle( QObject::tr( "Raster Histogram" ) );
1871-
mpPlot->insertLegend( new QwtLegend(), QwtPlot::BottomLegend );
1872-
// Set axis titles
1873-
mpPlot->setAxisTitle( QwtPlot::xBottom, QObject::tr( "Pixel Value" ) );
1874-
mpPlot->setAxisTitle( QwtPlot::yLeft, QObject::tr( "Frequency" ) );
1875-
mpPlot->setAxisAutoScale( QwtPlot::yLeft );
1876-
// x axis scale only set after computing global min/max across bands (see below)
1877-
// add a grid
1878-
QwtPlotGrid * myGrid = new QwtPlotGrid();
1879-
myGrid->attach( mpPlot );
1858+
mWebPlot->setHtml("<h1>Hellow World</h1>");
18801859
// Explanation:
18811860
// We use the gdal histogram creation routine is called for each selected
18821861
// layer. Currently the hist is hardcoded
@@ -1891,115 +1870,44 @@ void QgsRasterLayerProperties::refreshHistogram()
18911870
bool myIgnoreOutOfRangeFlag = true;
18921871
bool myThoroughBandScanFlag = false;
18931872
int myBandCountInt = mRasterLayer->bandCount();
1894-
QList<QColor> myColors;
1895-
myColors << Qt::black << Qt::red << Qt::green << Qt::blue << Qt::magenta << Qt::darkRed << Qt::darkGreen << Qt::darkBlue;
1896-
1897-
while ( myColors.size() <= myBandCountInt )
1898-
{
1899-
myColors <<
1900-
QColor( 1 + ( int )( 255.0 * rand() / ( RAND_MAX + 1.0 ) ),
1901-
1 + ( int )( 255.0 * rand() / ( RAND_MAX + 1.0 ) ),
1902-
1 + ( int )( 255.0 * rand() / ( RAND_MAX + 1.0 ) ) );
1903-
}
1904-
19051873
//
19061874
//now draw actual graphs
19071875
//
19081876

1909-
//somtimes there are more bins than needed
1910-
//we find out the last one that actually has data in it
1911-
//so we can discard the rest and set the x-axis scales correctly
1912-
//
1913-
// scan through to get counts from layers' histograms
1914-
//
1915-
float myGlobalMin = 0;
1916-
float myGlobalMax = 0;
19171877
bool myFirstIteration = true;
19181878
for ( int myIteratorInt = 1;
1919-
myIteratorInt <= myBandCountInt;
1920-
++myIteratorInt )
1879+
myIteratorInt <= myBandCountInt;
1880+
++myIteratorInt )
19211881
{
19221882
QgsRasterBandStats myRasterBandStats = mRasterLayer->bandStatistics( myIteratorInt );
19231883
mRasterLayer->populateHistogram( myIteratorInt, BINCOUNT, myIgnoreOutOfRangeFlag, myThoroughBandScanFlag );
1924-
QwtPlotCurve * mypCurve = new QwtPlotCurve( tr( "Band %1" ).arg( myIteratorInt ) );
1925-
mypCurve->setCurveAttribute( QwtPlotCurve::Fitted );
1926-
mypCurve->setRenderHint( QwtPlotItem::RenderAntialiased );
1927-
mypCurve->setPen( QPen( myColors.at( myIteratorInt ) ) );
1928-
#if defined(QWT_VERSION) && QWT_VERSION>=0x060000
1929-
QVector<QPointF> data;
1930-
#else
1931-
QVector<double> myX2Data;
1932-
QVector<double> myY2Data;
1933-
#endif
19341884
for ( int myBin = 0; myBin < BINCOUNT; myBin++ )
19351885
{
19361886
int myBinValue = myRasterBandStats.histogramVector->at( myBin );
1937-
#if defined(QWT_VERSION) && QWT_VERSION>=0x060000
1938-
data << QPointF( myBin, myBinValue );
1939-
#else
1940-
myX2Data.append( double( myBin ) );
1941-
myY2Data.append( double( myBinValue ) );
1942-
#endif
1943-
}
1944-
#if defined(QWT_VERSION) && QWT_VERSION>=0x060000
1945-
mypCurve->setSamples( data );
1946-
#else
1947-
mypCurve->setData( myX2Data, myY2Data );
1948-
#endif
1949-
mypCurve->attach( mpPlot );
1950-
if ( myFirstIteration || myGlobalMin < myRasterBandStats.minimumValue )
1951-
{
1952-
myGlobalMin = myRasterBandStats.minimumValue;
1953-
}
1954-
if ( myFirstIteration || myGlobalMax < myRasterBandStats.maximumValue )
1955-
{
1956-
myGlobalMax = myRasterBandStats.maximumValue;
19571887
}
1958-
myFirstIteration = false;
19591888
}
1960-
// for x axis use band pixel values rather than gdal hist. bin values
1961-
// subtract -0.5 to prevent rounding errors
1962-
// see http://www.gdal.org/classGDALRasterBand.html#3f8889607d3b2294f7e0f11181c201c8
1963-
mpPlot->setAxisScale( QwtPlot::xBottom,
1964-
myGlobalMin - 0.5,
1965-
myGlobalMax + 0.5 );
1966-
mpPlot->replot();
19671889
disconnect( mRasterLayer, SIGNAL( progressUpdate( int ) ), mHistogramProgress, SLOT( setValue( int ) ) );
19681890
mHistogramProgress->hide();
1969-
mpPlot->canvas()->setCursor( Qt::ArrowCursor );
19701891
QApplication::restoreOverrideCursor();
19711892
}
19721893

19731894
void QgsRasterLayerProperties::on_mSaveAsImageButton_clicked()
19741895
{
1975-
if ( mpPlot == 0 )
1976-
{
1977-
return;
1978-
}
19791896

19801897
QPixmap myPixmap( 600, 600 );
19811898
myPixmap.fill( Qt::white ); // Qt::transparent ?
19821899

1983-
#if (QWT_VERSION<0x060000)
1984-
QwtPlotPrintFilter myFilter;
1985-
int myOptions = QwtPlotPrintFilter::PrintAll;
1986-
myOptions &= ~QwtPlotPrintFilter::PrintBackground;
1987-
myOptions |= QwtPlotPrintFilter::PrintFrameWithScales;
1988-
myFilter.setOptions( myOptions );
1989-
1990-
mpPlot->print( myPixmap, myFilter );
1991-
#else
19921900
QPainter painter;
19931901
painter.begin( &myPixmap );
1994-
mpPlot->drawCanvas( &painter );
1902+
//mWebPlot->drawCanvas( &painter );
19951903
painter.end();
1996-
#endif
19971904
QPair< QString, QString> myFileNameAndFilter = QgisGui::getSaveAsImageName( this, tr( "Choose a file name to save the map image as" ) );
19981905
if ( myFileNameAndFilter.first != "" )
19991906
{
20001907
myPixmap.save( myFileNameAndFilter.first );
20011908
}
20021909
}
1910+
20031911
void QgsRasterLayerProperties::on_pbnImportTransparentPixelValues_clicked()
20041912
{
20051913
int myLineCounter = 0;
@@ -2864,6 +2772,7 @@ QLinearGradient QgsRasterLayerProperties::grayGradient()
28642772
myGradient.setColorAt( 1.0, QColor( 220, 220, 220, 190 ) );
28652773
return myGradient;
28662774
}
2775+
28672776
QLinearGradient QgsRasterLayerProperties::highlightGradient()
28682777
{
28692778
//define another gradient for the highlight
@@ -3074,4 +2983,3 @@ void QgsRasterLayerProperties::toggleBuildPyramidsButton()
30742983
buttonBuildPyramids->setEnabled( true );
30752984
}
30762985
}
3077-

‎src/ui/qgsrasterlayerpropertiesbase.ui

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1771,21 +1771,22 @@
17711771
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
17721772
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
17731773
p, li { white-space: pre-wrap; }
1774-
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Ubuntu'; font-size:10pt; font-weight:400; font-style:normal;&quot;&gt;
1774+
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;&quot;&gt;
17751775
&lt;table border=&quot;0&quot; style=&quot;-qt-table-type: root; margin-top:4px; margin-bottom:4px; margin-left:4px; margin-right:4px;&quot;&gt;
17761776
&lt;tr&gt;
17771777
&lt;td style=&quot;border: none;&quot;&gt;
1778-
&lt;p style=&quot;-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';&quot;&gt;&lt;/p&gt;
1779-
&lt;p style=&quot;-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;&quot;&gt;&lt;/p&gt;
1780-
&lt;p style=&quot;-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';&quot;&gt;&lt;/p&gt;
1781-
&lt;p style=&quot;-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';&quot;&gt;&lt;/p&gt;
1782-
&lt;p style=&quot;-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';&quot;&gt;&lt;/p&gt;
1783-
&lt;p style=&quot;-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';&quot;&gt;&lt;/p&gt;
1784-
&lt;p style=&quot;-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';&quot;&gt;&lt;/p&gt;
1785-
&lt;p style=&quot;-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';&quot;&gt;&lt;/p&gt;
1786-
&lt;p style=&quot;-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';&quot;&gt;&lt;/p&gt;
1787-
&lt;p style=&quot;-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';&quot;&gt;&lt;/p&gt;
1788-
&lt;p style=&quot;-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';&quot;&gt;&lt;/p&gt;
1778+
&lt;p style=&quot;-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;&quot;&gt;&lt;/p&gt;
1779+
&lt;p style=&quot;-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;&quot;&gt;&lt;/p&gt;
1780+
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;/p&gt;
1781+
&lt;p style=&quot;-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;&quot;&gt;&lt;/p&gt;
1782+
&lt;p style=&quot;-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;&quot;&gt;&lt;/p&gt;
1783+
&lt;p style=&quot;-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;&quot;&gt;&lt;/p&gt;
1784+
&lt;p style=&quot;-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;&quot;&gt;&lt;/p&gt;
1785+
&lt;p style=&quot;-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;&quot;&gt;&lt;/p&gt;
1786+
&lt;p style=&quot;-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;&quot;&gt;&lt;/p&gt;
1787+
&lt;p style=&quot;-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;&quot;&gt;&lt;/p&gt;
1788+
&lt;p style=&quot;-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;&quot;&gt;&lt;/p&gt;
1789+
&lt;p style=&quot;-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;&quot;&gt;&lt;/p&gt;
17891790
&lt;p style=&quot;-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;&quot;&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/body&gt;&lt;/html&gt;</string>
17901791
</property>
17911792
</widget>
@@ -1865,9 +1866,6 @@ p, li { white-space: pre-wrap; }
18651866
<string>Histogram</string>
18661867
</attribute>
18671868
<layout class="QGridLayout" name="gridLayout_4">
1868-
<item row="0" column="0" colspan="2">
1869-
<widget class="QwtPlot" name="mpPlot"/>
1870-
</item>
18711869
<item row="1" column="0">
18721870
<widget class="QProgressBar" name="mHistogramProgress">
18731871
<property name="value">
@@ -1886,6 +1884,15 @@ p, li { white-space: pre-wrap; }
18861884
</property>
18871885
</widget>
18881886
</item>
1887+
<item row="0" column="0">
1888+
<widget class="QWebView" name="mWebPlot">
1889+
<property name="url">
1890+
<url>
1891+
<string>about:blank</string>
1892+
</url>
1893+
</property>
1894+
</widget>
1895+
</item>
18891896
</layout>
18901897
</widget>
18911898
</widget>
@@ -1933,9 +1940,9 @@ p, li { white-space: pre-wrap; }
19331940
<layoutdefault spacing="6" margin="11"/>
19341941
<customwidgets>
19351942
<customwidget>
1936-
<class>QwtPlot</class>
1937-
<extends>QFrame</extends>
1938-
<header>qwt_plot.h</header>
1943+
<class>QWebView</class>
1944+
<extends>QWidget</extends>
1945+
<header>QtWebKit/QWebView</header>
19391946
</customwidget>
19401947
</customwidgets>
19411948
<tabstops>

0 commit comments

Comments
 (0)
Please sign in to comment.