Skip to content

Commit fe2435c

Browse files
etienneskyNathanW2
authored andcommitted
add support for qwt6 for identify results graph
1 parent 3fc1585 commit fe2435c

File tree

2 files changed

+26
-25
lines changed

2 files changed

+26
-25
lines changed

src/app/qgsidentifyresultsdialog.cpp

+26-18
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,12 @@
5353
#include <QWebFrame>
5454

5555
//graph
56-
#if defined(QWT_VERSION) && QWT_VERSION<0x060000
5756
#include <qwt_plot.h>
5857
#include <qwt_plot_curve.h>
5958
#include <qwt_symbol.h>
6059
#include <qwt_legend.h>
6160
#include "qgsvectorcolorrampv2.h" // for random colors
62-
#endif
61+
6362

6463
QgsIdentifyResultsWebView::QgsIdentifyResultsWebView( QWidget *parent ) : QWebView( parent )
6564
{
@@ -302,7 +301,6 @@ QgsIdentifyResultsDialog::QgsIdentifyResultsDialog( QgsMapCanvas *canvas, QWidge
302301

303302
// graph
304303
mPlot->setVisible( false );
305-
#if defined(QWT_VERSION) && QWT_VERSION<0x060000
306304
mPlot->setAutoFillBackground( false );
307305
mPlot->setAutoDelete( true );
308306
mPlot->insertLegend( new QwtLegend(), QwtPlot::TopLegend );
@@ -312,11 +310,6 @@ QgsIdentifyResultsDialog::QgsIdentifyResultsDialog( QgsMapCanvas *canvas, QWidge
312310
sizePolicy.setHeightForWidth( mPlot->sizePolicy().hasHeightForWidth() );
313311
mPlot->setSizePolicy( sizePolicy );
314312
mPlot->updateGeometry();
315-
#else
316-
delete mPlot;
317-
mPlot = 0;
318-
tabWidget->removeTab( 2 );
319-
#endif
320313

321314
connect( buttonBox, SIGNAL( rejected() ), this, SLOT( close() ) );
322315

@@ -344,11 +337,9 @@ QgsIdentifyResultsDialog::~QgsIdentifyResultsDialog()
344337

345338
if ( mActionPopup )
346339
delete mActionPopup;
347-
#if defined(QWT_VERSION) && QWT_VERSION<0x060000
348340
foreach ( QgsIdentifyPlotCurve *curve, mPlotCurves )
349341
delete curve;
350342
mPlotCurves.clear();
351-
#endif
352343
}
353344

354345
QTreeWidgetItem *QgsIdentifyResultsDialog::layerItem( QObject *object )
@@ -610,17 +601,39 @@ QgsIdentifyPlotCurve::QgsIdentifyPlotCurve( const QMap<QString, QString> &attrib
610601
{
611602
color = QgsVectorRandomColorRampV2::randomColors( 1 )[0];
612603
}
604+
#if defined(QWT_VERSION) && QWT_VERSION>=0x060000
605+
mPlotCurve->setSymbol( new QwtSymbol( QwtSymbol::Ellipse, QBrush( Qt::white ),
606+
QPen( color, 2 ), QSize( 9, 9 ) ) );
607+
mPlotCurve->setPen( QPen( color, 2 ) ); // needed for legend
608+
#else
613609
mPlotCurve->setSymbol( QwtSymbol( QwtSymbol::Ellipse, QBrush( Qt::white ),
614610
QPen( color, 2 ), QSize( 9, 9 ) ) );
611+
mPlotCurve->setPen( QPen( color, 2 ) );
612+
#endif
615613

614+
#if defined(QWT_VERSION) && QWT_VERSION>=0x060000
615+
QVector<QPointF> myData;
616+
#else
617+
QVector<double> myX2Data;
618+
QVector<double> myY2Data;
619+
#endif
616620
int i = 1;
621+
617622
for ( QMap<QString, QString>::const_iterator it = attributes.begin();
618623
it != attributes.end(); ++it )
619624
{
620-
mPlotCurveXData.append( double( i++ ) );
621-
mPlotCurveYData.append( double( it.value().toDouble() ) );
625+
#if defined(QWT_VERSION) && QWT_VERSION>=0x060000
626+
myData << QPointF( double( i++ ), it.value().toDouble() );
627+
#else
628+
myX2Data.append( double( i++ ) );
629+
myY2Data.append( it.value().toDouble() );
630+
#endif
622631
}
623-
mPlotCurve->setData( mPlotCurveXData, mPlotCurveYData );
632+
#if defined(QWT_VERSION) && QWT_VERSION>=0x060000
633+
mPlotCurve->setSamples( myData );
634+
#else
635+
mPlotCurve->setData( myX2Data, myY2Data );
636+
#endif
624637

625638
mPlotCurve->attach( plot );
626639

@@ -640,7 +653,6 @@ QgsIdentifyPlotCurve::~QgsIdentifyPlotCurve()
640653
delete mPlotCurve;
641654
}
642655
}
643-
#endif
644656

645657
void QgsIdentifyResultsDialog::addFeature( QgsRasterLayer *layer,
646658
QString label,
@@ -782,12 +794,10 @@ void QgsIdentifyResultsDialog::addFeature( QgsRasterLayer *layer,
782794
tblResults->resizeColumnToContents( 1 );
783795

784796
// graph
785-
#if defined(QWT_VERSION) && QWT_VERSION<0x060000
786797
if ( attributes.count() > 0 )
787798
{
788799
mPlotCurves.append( new QgsIdentifyPlotCurve( attributes, mPlot, layer->name() ) );
789800
}
790-
#endif
791801
}
792802

793803
void QgsIdentifyResultsDialog::editingToggled()
@@ -1061,12 +1071,10 @@ void QgsIdentifyResultsDialog::clear()
10611071
tblResults->clearContents();
10621072
tblResults->setRowCount( 0 );
10631073

1064-
#if defined(QWT_VERSION) && QWT_VERSION<0x060000
10651074
mPlot->setVisible( false );
10661075
foreach ( QgsIdentifyPlotCurve *curve, mPlotCurves )
10671076
delete curve;
10681077
mPlotCurves.clear();
1069-
#endif
10701078

10711079
// keep it visible but disabled, it can switch from disabled/enabled
10721080
// after raster format change

src/app/qgsidentifyresultsdialog.h

-7
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ class APP_EXPORT QgsIdentifyResultsWebViewItem: public QObject, public QTreeWidg
9494
QgsIdentifyResultsWebView *mWebView;
9595
};
9696

97-
#if defined(QWT_VERSION) && QWT_VERSION<0x060000
9897
class APP_EXPORT QgsIdentifyPlotCurve
9998
{
10099
public:
@@ -106,9 +105,7 @@ class APP_EXPORT QgsIdentifyPlotCurve
106105

107106
private:
108107
QwtPlotCurve* mPlotCurve;
109-
QVector<double> mPlotCurveXData, mPlotCurveYData;
110108
};
111-
#endif
112109

113110
class APP_EXPORT QgsIdentifyResultsDialog: public QDialog, private Ui::QgsIdentifyResultsBase
114111
{
@@ -245,11 +242,7 @@ class APP_EXPORT QgsIdentifyResultsDialog: public QDialog, private Ui::QgsIdenti
245242

246243
QDockWidget *mDock;
247244

248-
#if defined(QWT_VERSION) && QWT_VERSION<0x060000
249-
/* QwtPlotCurve* mPlotCurve; */
250-
/* QVector<double> mPlotCurveXData, mPlotCurveYData; */
251245
QVector<QgsIdentifyPlotCurve *> mPlotCurves;
252-
#endif
253246
};
254247

255248
class QgsIdentifyResultsDialogMapLayerAction : public QAction

0 commit comments

Comments
 (0)