Skip to content

Commit

Permalink
add support for qwt6 for identify results graph
Browse files Browse the repository at this point in the history
  • Loading branch information
etiennesky authored and NathanW2 committed May 19, 2014
1 parent 3fc1585 commit fe2435c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
44 changes: 26 additions & 18 deletions src/app/qgsidentifyresultsdialog.cpp
Expand Up @@ -53,13 +53,12 @@
#include <QWebFrame>

//graph
#if defined(QWT_VERSION) && QWT_VERSION<0x060000
#include <qwt_plot.h>
#include <qwt_plot_curve.h>
#include <qwt_symbol.h>
#include <qwt_legend.h>
#include "qgsvectorcolorrampv2.h" // for random colors
#endif


QgsIdentifyResultsWebView::QgsIdentifyResultsWebView( QWidget *parent ) : QWebView( parent )
{
Expand Down Expand Up @@ -302,7 +301,6 @@ QgsIdentifyResultsDialog::QgsIdentifyResultsDialog( QgsMapCanvas *canvas, QWidge

// graph
mPlot->setVisible( false );
#if defined(QWT_VERSION) && QWT_VERSION<0x060000
mPlot->setAutoFillBackground( false );
mPlot->setAutoDelete( true );
mPlot->insertLegend( new QwtLegend(), QwtPlot::TopLegend );
Expand All @@ -312,11 +310,6 @@ QgsIdentifyResultsDialog::QgsIdentifyResultsDialog( QgsMapCanvas *canvas, QWidge
sizePolicy.setHeightForWidth( mPlot->sizePolicy().hasHeightForWidth() );
mPlot->setSizePolicy( sizePolicy );
mPlot->updateGeometry();
#else
delete mPlot;
mPlot = 0;
tabWidget->removeTab( 2 );
#endif

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

Expand Down Expand Up @@ -344,11 +337,9 @@ QgsIdentifyResultsDialog::~QgsIdentifyResultsDialog()

if ( mActionPopup )
delete mActionPopup;
#if defined(QWT_VERSION) && QWT_VERSION<0x060000
foreach ( QgsIdentifyPlotCurve *curve, mPlotCurves )
delete curve;
mPlotCurves.clear();
#endif
}

QTreeWidgetItem *QgsIdentifyResultsDialog::layerItem( QObject *object )
Expand Down Expand Up @@ -610,17 +601,39 @@ QgsIdentifyPlotCurve::QgsIdentifyPlotCurve( const QMap<QString, QString> &attrib
{
color = QgsVectorRandomColorRampV2::randomColors( 1 )[0];
}
#if defined(QWT_VERSION) && QWT_VERSION>=0x060000
mPlotCurve->setSymbol( new QwtSymbol( QwtSymbol::Ellipse, QBrush( Qt::white ),
QPen( color, 2 ), QSize( 9, 9 ) ) );
mPlotCurve->setPen( QPen( color, 2 ) ); // needed for legend
#else
mPlotCurve->setSymbol( QwtSymbol( QwtSymbol::Ellipse, QBrush( Qt::white ),
QPen( color, 2 ), QSize( 9, 9 ) ) );
mPlotCurve->setPen( QPen( color, 2 ) );
#endif

#if defined(QWT_VERSION) && QWT_VERSION>=0x060000
QVector<QPointF> myData;
#else
QVector<double> myX2Data;
QVector<double> myY2Data;
#endif
int i = 1;

for ( QMap<QString, QString>::const_iterator it = attributes.begin();
it != attributes.end(); ++it )
{
mPlotCurveXData.append( double( i++ ) );
mPlotCurveYData.append( double( it.value().toDouble() ) );
#if defined(QWT_VERSION) && QWT_VERSION>=0x060000
myData << QPointF( double( i++ ), it.value().toDouble() );
#else
myX2Data.append( double( i++ ) );
myY2Data.append( it.value().toDouble() );
#endif
}
mPlotCurve->setData( mPlotCurveXData, mPlotCurveYData );
#if defined(QWT_VERSION) && QWT_VERSION>=0x060000
mPlotCurve->setSamples( myData );
#else
mPlotCurve->setData( myX2Data, myY2Data );
#endif

mPlotCurve->attach( plot );

Expand All @@ -640,7 +653,6 @@ QgsIdentifyPlotCurve::~QgsIdentifyPlotCurve()
delete mPlotCurve;
}
}
#endif

void QgsIdentifyResultsDialog::addFeature( QgsRasterLayer *layer,
QString label,
Expand Down Expand Up @@ -782,12 +794,10 @@ void QgsIdentifyResultsDialog::addFeature( QgsRasterLayer *layer,
tblResults->resizeColumnToContents( 1 );

// graph
#if defined(QWT_VERSION) && QWT_VERSION<0x060000
if ( attributes.count() > 0 )
{
mPlotCurves.append( new QgsIdentifyPlotCurve( attributes, mPlot, layer->name() ) );
}
#endif
}

void QgsIdentifyResultsDialog::editingToggled()
Expand Down Expand Up @@ -1061,12 +1071,10 @@ void QgsIdentifyResultsDialog::clear()
tblResults->clearContents();
tblResults->setRowCount( 0 );

#if defined(QWT_VERSION) && QWT_VERSION<0x060000
mPlot->setVisible( false );
foreach ( QgsIdentifyPlotCurve *curve, mPlotCurves )
delete curve;
mPlotCurves.clear();
#endif

// keep it visible but disabled, it can switch from disabled/enabled
// after raster format change
Expand Down
7 changes: 0 additions & 7 deletions src/app/qgsidentifyresultsdialog.h
Expand Up @@ -94,7 +94,6 @@ class APP_EXPORT QgsIdentifyResultsWebViewItem: public QObject, public QTreeWidg
QgsIdentifyResultsWebView *mWebView;
};

#if defined(QWT_VERSION) && QWT_VERSION<0x060000
class APP_EXPORT QgsIdentifyPlotCurve
{
public:
Expand All @@ -106,9 +105,7 @@ class APP_EXPORT QgsIdentifyPlotCurve

private:
QwtPlotCurve* mPlotCurve;
QVector<double> mPlotCurveXData, mPlotCurveYData;
};
#endif

class APP_EXPORT QgsIdentifyResultsDialog: public QDialog, private Ui::QgsIdentifyResultsBase
{
Expand Down Expand Up @@ -245,11 +242,7 @@ class APP_EXPORT QgsIdentifyResultsDialog: public QDialog, private Ui::QgsIdenti

QDockWidget *mDock;

#if defined(QWT_VERSION) && QWT_VERSION<0x060000
/* QwtPlotCurve* mPlotCurve; */
/* QVector<double> mPlotCurveXData, mPlotCurveYData; */
QVector<QgsIdentifyPlotCurve *> mPlotCurves;
#endif
};

class QgsIdentifyResultsDialogMapLayerAction : public QAction
Expand Down

0 comments on commit fe2435c

Please sign in to comment.