mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-08 00:05:09 -04:00
In progress work to replace qwt with flot for raster histogram
This commit is contained in:
parent
e49bdbc4b8
commit
a975f30257
@ -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)
|
DESTINATION ${QGIS_DATA_DIR}/resources)
|
||||||
|
|
||||||
ADD_SUBDIRECTORY(context_help)
|
ADD_SUBDIRECTORY(context_help)
|
||||||
|
ADD_SUBDIRECTORY(js)
|
||||||
|
@ -415,6 +415,7 @@ TARGET_LINK_LIBRARIES(${QGIS_APP_NAME}
|
|||||||
${QWT_LIBRARY}
|
${QWT_LIBRARY}
|
||||||
${QT_QTSQL_LIBRARY}
|
${QT_QTSQL_LIBRARY}
|
||||||
${QT_QTUITOOLS_LIBRARY}
|
${QT_QTUITOOLS_LIBRARY}
|
||||||
|
${QT_QTWEBKIT_LIBRARY}
|
||||||
#should only be needed for win
|
#should only be needed for win
|
||||||
${QT_QTMAIN_LIBRARY}
|
${QT_QTMAIN_LIBRARY}
|
||||||
${QWTPOLAR_LIBRARY}
|
${QWTPOLAR_LIBRARY}
|
||||||
|
@ -51,14 +51,8 @@
|
|||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
#include <QWebView>
|
||||||
|
|
||||||
// QWT Charting widget
|
|
||||||
#include <qwt_global.h>
|
|
||||||
#include <qwt_plot_canvas.h>
|
|
||||||
#include <qwt_legend.h>
|
|
||||||
#include <qwt_plot.h>
|
|
||||||
#include <qwt_plot_curve.h>
|
|
||||||
#include <qwt_plot_grid.h>
|
|
||||||
|
|
||||||
QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanvas* theCanvas, QWidget *parent, Qt::WFlags fl )
|
QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanvas* theCanvas, QWidget *parent, Qt::WFlags fl )
|
||||||
: QDialog( parent, fl ),
|
: QDialog( parent, fl ),
|
||||||
@ -1858,25 +1852,10 @@ void QgsRasterLayerProperties::on_tabBar_currentChanged( int theTab )
|
|||||||
|
|
||||||
void QgsRasterLayerProperties::refreshHistogram()
|
void QgsRasterLayerProperties::refreshHistogram()
|
||||||
{
|
{
|
||||||
#if !defined(QWT_VERSION) || QWT_VERSION<0x060000
|
|
||||||
mpPlot->clear();
|
|
||||||
#endif
|
|
||||||
mHistogramProgress->show();
|
mHistogramProgress->show();
|
||||||
connect( mRasterLayer, SIGNAL( progressUpdate( int ) ), mHistogramProgress, SLOT( setValue( int ) ) );
|
connect( mRasterLayer, SIGNAL( progressUpdate( int ) ), mHistogramProgress, SLOT( setValue( int ) ) );
|
||||||
QApplication::setOverrideCursor( Qt::WaitCursor );
|
QApplication::setOverrideCursor( Qt::WaitCursor );
|
||||||
QgsDebugMsg( "entered." );
|
mWebPlot->setHtml("<h1>Hellow World</h1>");
|
||||||
//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 );
|
|
||||||
// Explanation:
|
// Explanation:
|
||||||
// We use the gdal histogram creation routine is called for each selected
|
// We use the gdal histogram creation routine is called for each selected
|
||||||
// layer. Currently the hist is hardcoded
|
// layer. Currently the hist is hardcoded
|
||||||
@ -1891,115 +1870,44 @@ void QgsRasterLayerProperties::refreshHistogram()
|
|||||||
bool myIgnoreOutOfRangeFlag = true;
|
bool myIgnoreOutOfRangeFlag = true;
|
||||||
bool myThoroughBandScanFlag = false;
|
bool myThoroughBandScanFlag = false;
|
||||||
int myBandCountInt = mRasterLayer->bandCount();
|
int myBandCountInt = mRasterLayer->bandCount();
|
||||||
QList<QColor> 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
|
//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;
|
bool myFirstIteration = true;
|
||||||
for ( int myIteratorInt = 1;
|
for ( int myIteratorInt = 1;
|
||||||
myIteratorInt <= myBandCountInt;
|
myIteratorInt <= myBandCountInt;
|
||||||
++myIteratorInt )
|
++myIteratorInt )
|
||||||
{
|
{
|
||||||
QgsRasterBandStats myRasterBandStats = mRasterLayer->bandStatistics( myIteratorInt );
|
QgsRasterBandStats myRasterBandStats = mRasterLayer->bandStatistics( myIteratorInt );
|
||||||
mRasterLayer->populateHistogram( myIteratorInt, BINCOUNT, myIgnoreOutOfRangeFlag, myThoroughBandScanFlag );
|
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<QPointF> data;
|
|
||||||
#else
|
|
||||||
QVector<double> myX2Data;
|
|
||||||
QVector<double> myY2Data;
|
|
||||||
#endif
|
|
||||||
for ( int myBin = 0; myBin < BINCOUNT; myBin++ )
|
for ( int myBin = 0; myBin < BINCOUNT; myBin++ )
|
||||||
{
|
{
|
||||||
int myBinValue = myRasterBandStats.histogramVector->at( 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 ) ) );
|
disconnect( mRasterLayer, SIGNAL( progressUpdate( int ) ), mHistogramProgress, SLOT( setValue( int ) ) );
|
||||||
mHistogramProgress->hide();
|
mHistogramProgress->hide();
|
||||||
mpPlot->canvas()->setCursor( Qt::ArrowCursor );
|
|
||||||
QApplication::restoreOverrideCursor();
|
QApplication::restoreOverrideCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsRasterLayerProperties::on_mSaveAsImageButton_clicked()
|
void QgsRasterLayerProperties::on_mSaveAsImageButton_clicked()
|
||||||
{
|
{
|
||||||
if ( mpPlot == 0 )
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QPixmap myPixmap( 600, 600 );
|
QPixmap myPixmap( 600, 600 );
|
||||||
myPixmap.fill( Qt::white ); // Qt::transparent ?
|
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;
|
QPainter painter;
|
||||||
painter.begin( &myPixmap );
|
painter.begin( &myPixmap );
|
||||||
mpPlot->drawCanvas( &painter );
|
//mWebPlot->drawCanvas( &painter );
|
||||||
painter.end();
|
painter.end();
|
||||||
#endif
|
|
||||||
QPair< QString, QString> myFileNameAndFilter = QgisGui::getSaveAsImageName( this, tr( "Choose a file name to save the map image as" ) );
|
QPair< QString, QString> myFileNameAndFilter = QgisGui::getSaveAsImageName( this, tr( "Choose a file name to save the map image as" ) );
|
||||||
if ( myFileNameAndFilter.first != "" )
|
if ( myFileNameAndFilter.first != "" )
|
||||||
{
|
{
|
||||||
myPixmap.save( myFileNameAndFilter.first );
|
myPixmap.save( myFileNameAndFilter.first );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsRasterLayerProperties::on_pbnImportTransparentPixelValues_clicked()
|
void QgsRasterLayerProperties::on_pbnImportTransparentPixelValues_clicked()
|
||||||
{
|
{
|
||||||
int myLineCounter = 0;
|
int myLineCounter = 0;
|
||||||
@ -2864,6 +2772,7 @@ QLinearGradient QgsRasterLayerProperties::grayGradient()
|
|||||||
myGradient.setColorAt( 1.0, QColor( 220, 220, 220, 190 ) );
|
myGradient.setColorAt( 1.0, QColor( 220, 220, 220, 190 ) );
|
||||||
return myGradient;
|
return myGradient;
|
||||||
}
|
}
|
||||||
|
|
||||||
QLinearGradient QgsRasterLayerProperties::highlightGradient()
|
QLinearGradient QgsRasterLayerProperties::highlightGradient()
|
||||||
{
|
{
|
||||||
//define another gradient for the highlight
|
//define another gradient for the highlight
|
||||||
@ -3074,4 +2983,3 @@ void QgsRasterLayerProperties::toggleBuildPyramidsButton()
|
|||||||
buttonBuildPyramids->setEnabled( true );
|
buttonBuildPyramids->setEnabled( true );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1771,21 +1771,22 @@
|
|||||||
<string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
|
<string><!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">
|
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
|
||||||
p, li { white-space: pre-wrap; }
|
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;">
|
<table border="0" style="-qt-table-type: root; margin-top:4px; margin-bottom:4px; margin-left:4px; margin-right:4px;">
|
||||||
<tr>
|
<tr>
|
||||||
<td style="border: none;">
|
<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: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-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'; 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';"></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';"></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';"></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';"></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';"></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';"></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';"></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';"></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';"></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></string>
|
<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></string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
@ -1865,9 +1866,6 @@ p, li { white-space: pre-wrap; }
|
|||||||
<string>Histogram</string>
|
<string>Histogram</string>
|
||||||
</attribute>
|
</attribute>
|
||||||
<layout class="QGridLayout" name="gridLayout_4">
|
<layout class="QGridLayout" name="gridLayout_4">
|
||||||
<item row="0" column="0" colspan="2">
|
|
||||||
<widget class="QwtPlot" name="mpPlot"/>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="0">
|
<item row="1" column="0">
|
||||||
<widget class="QProgressBar" name="mHistogramProgress">
|
<widget class="QProgressBar" name="mHistogramProgress">
|
||||||
<property name="value">
|
<property name="value">
|
||||||
@ -1886,6 +1884,15 @@ p, li { white-space: pre-wrap; }
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QWebView" name="mWebPlot">
|
||||||
|
<property name="url">
|
||||||
|
<url>
|
||||||
|
<string>about:blank</string>
|
||||||
|
</url>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
@ -1933,9 +1940,9 @@ p, li { white-space: pre-wrap; }
|
|||||||
<layoutdefault spacing="6" margin="11"/>
|
<layoutdefault spacing="6" margin="11"/>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
<class>QwtPlot</class>
|
<class>QWebView</class>
|
||||||
<extends>QFrame</extends>
|
<extends>QWidget</extends>
|
||||||
<header>qwt_plot.h</header>
|
<header>QtWebKit/QWebView</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
<tabstops>
|
<tabstops>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user