|
57 | 57 | #include <qwt_plot.h>
|
58 | 58 | #include <qwt_plot_curve.h>
|
59 | 59 | #include <qwt_symbol.h>
|
| 60 | +#include <qwt_legend.h> |
| 61 | +#include "qgsvectorcolorrampv2.h" // for random colors |
60 | 62 | #endif
|
61 | 63 |
|
62 | 64 | QgsIdentifyResultsWebView::QgsIdentifyResultsWebView( QWidget *parent ) : QWebView( parent )
|
@@ -303,17 +305,13 @@ QgsIdentifyResultsDialog::QgsIdentifyResultsDialog( QgsMapCanvas *canvas, QWidge
|
303 | 305 | #if defined(QWT_VERSION) && QWT_VERSION<0x060000
|
304 | 306 | mPlot->setAutoFillBackground( false );
|
305 | 307 | mPlot->setAutoDelete( true );
|
| 308 | + mPlot->insertLegend( new QwtLegend(), QwtPlot::RightLegend ); |
306 | 309 | QSizePolicy sizePolicy = QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
|
307 | 310 | sizePolicy.setHorizontalStretch( 0 );
|
308 | 311 | sizePolicy.setVerticalStretch( 0 );
|
309 | 312 | sizePolicy.setHeightForWidth( mPlot->sizePolicy().hasHeightForWidth() );
|
310 | 313 | mPlot->setSizePolicy( sizePolicy );
|
311 | 314 | 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 | 315 | #else
|
318 | 316 | delete mPlot;
|
319 | 317 | mPlot = 0;
|
@@ -347,7 +345,9 @@ QgsIdentifyResultsDialog::~QgsIdentifyResultsDialog()
|
347 | 345 | if ( mActionPopup )
|
348 | 346 | delete mActionPopup;
|
349 | 347 | #if defined(QWT_VERSION) && QWT_VERSION<0x060000
|
350 |
| - delete mPlotCurve; |
| 348 | + foreach ( QgsIdentifyPlotCurve *curve, mPlotCurves ) |
| 349 | + delete curve; |
| 350 | + mPlotCurves.clear(); |
351 | 351 | #endif
|
352 | 352 | }
|
353 | 353 |
|
@@ -600,6 +600,48 @@ void QgsIdentifyResultsDialog::mapLayerActionDestroyed()
|
600 | 600 | }
|
601 | 601 | }
|
602 | 602 |
|
| 603 | +#if defined(QWT_VERSION) && QWT_VERSION<0x060000 |
| 604 | +QgsIdentifyPlotCurve::QgsIdentifyPlotCurve( const QMap<QString, QString> &attributes, |
| 605 | + QwtPlot* plot, const QString &title, QColor color ) |
| 606 | +{ |
| 607 | + mPlotCurve = new QwtPlotCurve( title ); |
| 608 | + |
| 609 | + if ( color == QColor() ) |
| 610 | + { |
| 611 | + color = QgsVectorRandomColorRampV2::randomColors( 1 )[0]; |
| 612 | + } |
| 613 | + mPlotCurve->setSymbol( QwtSymbol( QwtSymbol::Ellipse, QBrush( Qt::white ), |
| 614 | + QPen( color, 2 ), QSize( 9, 9 ) ) ); |
| 615 | + |
| 616 | + int i = 1; |
| 617 | + for ( QMap<QString, QString>::const_iterator it = attributes.begin(); |
| 618 | + it != attributes.end(); ++it ) |
| 619 | + { |
| 620 | + mPlotCurveXData.append( double( i++ ) ); |
| 621 | + mPlotCurveYData.append( double( it.value().toDouble() ) ); |
| 622 | + } |
| 623 | + mPlotCurve->setData( mPlotCurveXData, mPlotCurveYData ); |
| 624 | + |
| 625 | + mPlotCurve->attach( plot ); |
| 626 | + |
| 627 | + plot->setAxisMaxMinor( QwtPlot::xBottom, 0 ); |
| 628 | + //mPlot->setAxisScale( QwtPlot::xBottom, 1, mPlotCurve->dataSize()); |
| 629 | + //mPlot->setAxisScale( QwtPlot::yLeft, ymin, ymax ); |
| 630 | + |
| 631 | + plot->replot(); |
| 632 | + plot->setVisible( true ); |
| 633 | +} |
| 634 | + |
| 635 | +QgsIdentifyPlotCurve::~QgsIdentifyPlotCurve() |
| 636 | +{ |
| 637 | + if ( mPlotCurve ) |
| 638 | + { |
| 639 | + mPlotCurve->detach(); |
| 640 | + delete mPlotCurve; |
| 641 | + } |
| 642 | +} |
| 643 | +#endif |
| 644 | + |
603 | 645 | void QgsIdentifyResultsDialog::addFeature( QgsRasterLayer *layer,
|
604 | 646 | QString label,
|
605 | 647 | const QMap<QString, QString> &attributes,
|
@@ -741,20 +783,10 @@ void QgsIdentifyResultsDialog::addFeature( QgsRasterLayer *layer,
|
741 | 783 |
|
742 | 784 | // graph
|
743 | 785 | #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 ) |
| 786 | + if ( attributes.count() > 0 ) |
746 | 787 | {
|
747 |
| - mPlotCurveXData.append( double( ++i ) ); |
748 |
| - mPlotCurveYData.append( double( it.value().toDouble() ) ); |
| 788 | + mPlotCurves.append( new QgsIdentifyPlotCurve( attributes, mPlot, layer->name() ) ); |
749 | 789 | }
|
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 | 790 | #endif
|
759 | 791 | }
|
760 | 792 |
|
@@ -1031,8 +1063,9 @@ void QgsIdentifyResultsDialog::clear()
|
1031 | 1063 |
|
1032 | 1064 | #if defined(QWT_VERSION) && QWT_VERSION<0x060000
|
1033 | 1065 | mPlot->setVisible( false );
|
1034 |
| - mPlotCurveXData.clear(); |
1035 |
| - mPlotCurveYData.clear(); |
| 1066 | + foreach ( QgsIdentifyPlotCurve *curve, mPlotCurves ) |
| 1067 | + delete curve; |
| 1068 | + mPlotCurves.clear(); |
1036 | 1069 | #endif
|
1037 | 1070 |
|
1038 | 1071 | // keep it visible but disabled, it can switch from disabled/enabled
|
|
0 commit comments