Skip to content

Commit

Permalink
add identify results graph for rasters using qwt5 (qwt6 not supported…
Browse files Browse the repository at this point in the history
… yet)
  • Loading branch information
etiennesky authored and NathanW2 committed May 19, 2014
1 parent 4620513 commit 1012d3d
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
57 changes: 57 additions & 0 deletions src/app/qgsidentifyresultsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@
#include <QComboBox>
#include <QWebFrame>

//graph
#if defined(QWT_VERSION) && QWT_VERSION<0x060000
#include <qwt_plot.h>
#include <qwt_plot_curve.h>
#include <qwt_symbol.h>
#endif

QgsIdentifyResultsWebView::QgsIdentifyResultsWebView( QWidget *parent ) : QWebView( parent )
{
setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Minimum );
Expand Down Expand Up @@ -291,6 +298,30 @@ QgsIdentifyResultsDialog::QgsIdentifyResultsDialog( QgsMapCanvas *canvas, QWidge
cmbIdentifyMode->setCurrentIndex( cmbIdentifyMode->findData( identifyMode ) );
cbxAutoFeatureForm->setChecked( mySettings.value( "/Map/identifyAutoFeatureForm", false ).toBool() );

// graph
mPlot->setVisible( false );
#if defined(QWT_VERSION) && QWT_VERSION<0x060000
mPlot->setAutoFillBackground( false );
mPlot->setAutoDelete( true );
QSizePolicy sizePolicy = QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
sizePolicy.setHorizontalStretch( 0 );
sizePolicy.setVerticalStretch( 0 );
sizePolicy.setHeightForWidth( mPlot->sizePolicy().hasHeightForWidth() );
mPlot->setSizePolicy( sizePolicy );
mPlot->updateGeometry();

mPlotCurve = new QwtPlotCurve( "" );
mPlotCurve->setSymbol( QwtSymbol( QwtSymbol::Ellipse, QBrush( Qt::white ),
QPen( Qt::red, 2 ), QSize( 9, 9 ) ) );
mPlotCurve->attach( mPlot );
#else
delete mPlot;
mPlot = 0;
tabWidget->removeTab( 2 );
#endif

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

connect( lstResults, SIGNAL( itemExpanded( QTreeWidgetItem* ) ),
this, SLOT( itemExpanded( QTreeWidgetItem* ) ) );

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

if ( mActionPopup )
delete mActionPopup;
#if defined(QWT_VERSION) && QWT_VERSION<0x060000
delete mPlotCurve;
#endif
}

QTreeWidgetItem *QgsIdentifyResultsDialog::layerItem( QObject *object )
Expand Down Expand Up @@ -705,6 +739,23 @@ void QgsIdentifyResultsDialog::addFeature( QgsRasterLayer *layer,
}
tblResults->resizeColumnToContents( 1 );

// graph
#if defined(QWT_VERSION) && QWT_VERSION<0x060000
i = mPlotCurveXData.count();
for ( QMap<QString, QString>::const_iterator it = attributes.begin(); it != attributes.end(); ++it )
{
mPlotCurveXData.append( double( ++i ) );
mPlotCurveYData.append( double( it.value().toDouble() ) );
}
mPlotCurve->setData( mPlotCurveXData, mPlotCurveYData );

mPlot->setAxisMaxMinor( QwtPlot::xBottom, 0 );
//mPlot->setAxisScale( QwtPlot::xBottom, 1, mPlotCurve->dataSize());
//mPlot->setAxisScale( QwtPlot::yLeft, ymin, ymax );

mPlot->replot();
mPlot->setVisible( mPlotCurveXData.count() > 0 );
#endif
}

void QgsIdentifyResultsDialog::editingToggled()
Expand Down Expand Up @@ -978,6 +1029,12 @@ void QgsIdentifyResultsDialog::clear()
tblResults->clearContents();
tblResults->setRowCount( 0 );

#if defined(QWT_VERSION) && QWT_VERSION<0x060000
mPlot->setVisible( false );
mPlotCurveXData.clear();
mPlotCurveYData.clear();
#endif

// keep it visible but disabled, it can switch from disabled/enabled
// after raster format change
mPrintToolButton->setDisabled( true );
Expand Down
7 changes: 7 additions & 0 deletions src/app/qgsidentifyresultsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class QgsHighlight;
class QgsMapCanvas;
class QDockWidget;

class QwtPlotCurve;

/**
*@author Gary E.Sherman
*/
Expand Down Expand Up @@ -226,6 +228,11 @@ class APP_EXPORT QgsIdentifyResultsDialog: public QDialog, private Ui::QgsIdenti
void doMapLayerAction( QTreeWidgetItem *item, QgsMapLayerAction* action );

QDockWidget *mDock;

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

class QgsIdentifyResultsDialogMapLayerAction : public QAction
Expand Down

0 comments on commit 1012d3d

Please sign in to comment.