Skip to content

Commit 1012d3d

Browse files
etienneskyNathanW2
authored andcommitted
add identify results graph for rasters using qwt5 (qwt6 not supported yet)
1 parent 4620513 commit 1012d3d

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

src/app/qgsidentifyresultsdialog.cpp

+57
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@
5252
#include <QComboBox>
5353
#include <QWebFrame>
5454

55+
//graph
56+
#if defined(QWT_VERSION) && QWT_VERSION<0x060000
57+
#include <qwt_plot.h>
58+
#include <qwt_plot_curve.h>
59+
#include <qwt_symbol.h>
60+
#endif
61+
5562
QgsIdentifyResultsWebView::QgsIdentifyResultsWebView( QWidget *parent ) : QWebView( parent )
5663
{
5764
setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Minimum );
@@ -291,6 +298,30 @@ QgsIdentifyResultsDialog::QgsIdentifyResultsDialog( QgsMapCanvas *canvas, QWidge
291298
cmbIdentifyMode->setCurrentIndex( cmbIdentifyMode->findData( identifyMode ) );
292299
cbxAutoFeatureForm->setChecked( mySettings.value( "/Map/identifyAutoFeatureForm", false ).toBool() );
293300

301+
// graph
302+
mPlot->setVisible( false );
303+
#if defined(QWT_VERSION) && QWT_VERSION<0x060000
304+
mPlot->setAutoFillBackground( false );
305+
mPlot->setAutoDelete( true );
306+
QSizePolicy sizePolicy = QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
307+
sizePolicy.setHorizontalStretch( 0 );
308+
sizePolicy.setVerticalStretch( 0 );
309+
sizePolicy.setHeightForWidth( mPlot->sizePolicy().hasHeightForWidth() );
310+
mPlot->setSizePolicy( sizePolicy );
311+
mPlot->updateGeometry();
312+
313+
mPlotCurve = new QwtPlotCurve( "" );
314+
mPlotCurve->setSymbol( QwtSymbol( QwtSymbol::Ellipse, QBrush( Qt::white ),
315+
QPen( Qt::red, 2 ), QSize( 9, 9 ) ) );
316+
mPlotCurve->attach( mPlot );
317+
#else
318+
delete mPlot;
319+
mPlot = 0;
320+
tabWidget->removeTab( 2 );
321+
#endif
322+
323+
connect( buttonBox, SIGNAL( rejected() ), this, SLOT( close() ) );
324+
294325
connect( lstResults, SIGNAL( itemExpanded( QTreeWidgetItem* ) ),
295326
this, SLOT( itemExpanded( QTreeWidgetItem* ) ) );
296327

@@ -315,6 +346,9 @@ QgsIdentifyResultsDialog::~QgsIdentifyResultsDialog()
315346

316347
if ( mActionPopup )
317348
delete mActionPopup;
349+
#if defined(QWT_VERSION) && QWT_VERSION<0x060000
350+
delete mPlotCurve;
351+
#endif
318352
}
319353

320354
QTreeWidgetItem *QgsIdentifyResultsDialog::layerItem( QObject *object )
@@ -705,6 +739,23 @@ void QgsIdentifyResultsDialog::addFeature( QgsRasterLayer *layer,
705739
}
706740
tblResults->resizeColumnToContents( 1 );
707741

742+
// graph
743+
#if defined(QWT_VERSION) && QWT_VERSION<0x060000
744+
i = mPlotCurveXData.count();
745+
for ( QMap<QString, QString>::const_iterator it = attributes.begin(); it != attributes.end(); ++it )
746+
{
747+
mPlotCurveXData.append( double( ++i ) );
748+
mPlotCurveYData.append( double( it.value().toDouble() ) );
749+
}
750+
mPlotCurve->setData( mPlotCurveXData, mPlotCurveYData );
751+
752+
mPlot->setAxisMaxMinor( QwtPlot::xBottom, 0 );
753+
//mPlot->setAxisScale( QwtPlot::xBottom, 1, mPlotCurve->dataSize());
754+
//mPlot->setAxisScale( QwtPlot::yLeft, ymin, ymax );
755+
756+
mPlot->replot();
757+
mPlot->setVisible( mPlotCurveXData.count() > 0 );
758+
#endif
708759
}
709760

710761
void QgsIdentifyResultsDialog::editingToggled()
@@ -978,6 +1029,12 @@ void QgsIdentifyResultsDialog::clear()
9781029
tblResults->clearContents();
9791030
tblResults->setRowCount( 0 );
9801031

1032+
#if defined(QWT_VERSION) && QWT_VERSION<0x060000
1033+
mPlot->setVisible( false );
1034+
mPlotCurveXData.clear();
1035+
mPlotCurveYData.clear();
1036+
#endif
1037+
9811038
// keep it visible but disabled, it can switch from disabled/enabled
9821039
// after raster format change
9831040
mPrintToolButton->setDisabled( true );

src/app/qgsidentifyresultsdialog.h

+7
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ class QgsHighlight;
4343
class QgsMapCanvas;
4444
class QDockWidget;
4545

46+
class QwtPlotCurve;
47+
4648
/**
4749
*@author Gary E.Sherman
4850
*/
@@ -226,6 +228,11 @@ class APP_EXPORT QgsIdentifyResultsDialog: public QDialog, private Ui::QgsIdenti
226228
void doMapLayerAction( QTreeWidgetItem *item, QgsMapLayerAction* action );
227229

228230
QDockWidget *mDock;
231+
232+
#if defined(QWT_VERSION) && QWT_VERSION<0x060000
233+
QwtPlotCurve* mPlotCurve;
234+
QVector<double> mPlotCurveXData, mPlotCurveYData;
235+
#endif
229236
};
230237

231238
class QgsIdentifyResultsDialogMapLayerAction : public QAction

0 commit comments

Comments
 (0)